接前面,繼續分析 chooseportalstrategy:
/*先展開第一段的判斷:if (list_length(stmts) == 1)* chooseportalstrategy
* select portal execution strategy given the intended statement list.
* * the list elements can be querys, plannedstmts, or utility statements.
* that's more general than portals need, but plancache.c uses this too.
* * see the comments in portal.h. */
portalstrategy
chooseportalstrategy(list *stmts)
if (query->commandtype == cmd_utility &&query->utilitystmt !=null)}}
else
if(isa(stmt, plannedstmt))}}
else
}/** portal_one_returning has to allow auxiliary queries added by rewrite.
* choose portal_one_returning if there is exactly one cansettag query and
* it has a returning list.
*/nsettag = 0
;
foreach
(lc, stmts)
}else
if(isa(stmt, plannedstmt))
}/*otherwise, utility command, assumed not cansettag */}
if (nsettag == 1
)
return
portal_one_returning;
/*else, it's the general case...
*/return
portal_multi_query;
}
其實是:
static inline int這裡我作乙個查詢驗證一下,list_length(
const list *l)
select * from tst01 where id in (select sid from tst02) or id in (select sid from tst03);
list_length(stmts) == 1 的條件滿足。
再看:
#define lfirst(lc) ((lc)->data.ptr_value)#define linitial(l) lfirst(list_head(l))
static inline listcell *list_head(所以呢,這句 :node *stmt = (node *) lfirst(lc); 就是拿到了 計畫樹的頭,並且轉換為 node 指標。const list *l)
PostgreSQL在何處處理 sql查詢之三十
接前面,繼續分析 portalstrategy chooseportalstrategy list stmts else if isa stmt,plannedstmt else portal one returning has to allow auxiliary queries added by...
PostgreSQL在何處處理 sql查詢之三十一
回到上乙個層面,繼續看 portalstart的處理 void portalstart portal portal,paramlistinfo params int eflags,bool use active snapshot pg catch pg end try 由之前的分析可以知道,滿足 c...
PostgreSQL在何處處理 sql查詢
如果我開乙個psql視窗,來輸入sql文,它在資料庫的何處被解析?在何處被 真正 處理?postgres.c 的 int postgresmain int argc,char ar const char username 函式中,在 postgresmain 的 for 迴圈中,呼叫 static ...