On Wed, Apr 1, 2015 at 8:18 PM, Robert Haas <robertmh...@gmail.com> wrote: > > >> I don't think you need to do anything that complicated. I'm not > >> proposing to *run* the initPlan in the workers, just to pass the > >> parameter values down. > > > > Sorry, but I am not able to understand how it will help if just parameters > > (If I understand correctly you want to say about Bitmapset *extParam; > > Bitmapset *allParam; in Plan structure) are passed to workers and I > > think they are already getting passed only initPlan and related Subplan > > in planned statement is not passed and the reason is that ss_finalize_plan() > > attaches initPlan to top node (which in this case is Funnel node and not > > PartialSeqScan) > > > > By any chance, do you mean that we run the part of the statement in > > workers and then run initPlan in master backend? > > If I'm not confused, it would be the other way around. We would run > the initPlan in the master backend *first* and then the rest in the > workers. >
Either one of us is confused, let me try to describe my understanding in somewhat more detail. Let me try to explain w.r.t the tab completion query [1]. In this, the initPlan is generated for Qualification expression [2], so it will be executed during qualification and the callstack will look like: postgres.exe!ExecSeqScan(ScanState * node=0x000000000c33bce8) Line 113 C postgres.exe!ExecProcNode(PlanState * node=0x000000000c33bce8) Line 418 + 0xa bytes C postgres.exe!ExecSetParamPlan(SubPlanState * node=0x000000000c343930, ExprContext * econtext=0x000000000c33de50) Line 1001 + 0xa bytes C > postgres.exe!ExecEvalParamExec(ExprState * exprstate=0x000000000c33f980, ExprContext * econtext=0x000000000c33de50, char * isNull=0x000000000c33f481, ExprDoneCond * isDone=0x0000000000000000) Line 1111 C postgres.exe!ExecMakeFunctionResultNoSets(FuncExprState * fcache=0x000000000c33f0d0, ExprContext * econtext=0x000000000c33de50, char * isNull=0x000000000042f1c8, ExprDoneCond * isDone=0x0000000000000000) Line 1992 + 0x2d bytes C postgres.exe!ExecEvalOper(FuncExprState * fcache=0x000000000c33f0d0, ExprContext * econtext=0x000000000c33de50, char * isNull=0x000000000042f1c8, ExprDoneCond * isDone=0x0000000000000000) Line 2443 C postgres.exe!ExecQual(List * qual=0x000000000c33fa08, ExprContext * econtext=0x000000000c33de50, char resultForNull=0) Line 5206 + 0x1a bytes C postgres.exe!ExecScan(ScanState * node=0x000000000c33dd38, TupleTableSlot * (ScanState *)* accessMtd=0x0000000140232940, char (ScanState *, TupleTableSlot *)* recheckMtd=0x00000001402329e0) Line 195 + 0x1a bytes C postgres.exe!ExecSeqScan(ScanState * node=0x000000000c33dd38) Line 114 C Basically here initPlan is getting executed during Qualification. So now the point I am not able to understand from your explanation is that how the worker will perform qualification without the knowledge of initPlan? [1] SELECT pg_catalog.quote_ident(c.relname) FROM pg_catalog.pg_class c WHERE c.relkind IN ('r', 'S', 'v', 'm', 'f') AND substring(pg_catalog.quote_ident(c.relname),1,3)='pgb' AND pg_catalog.pg_table_is_visible(c.oid) AND c.relnamespace <> (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = 'pg_catalog') UNION SELECT pg_catalog.quote_ident(n.nspname) || '.' FROM pg_catalog.pg_namespace n WHERE substring (pg_catalog.quote_ident(n.nspname) || '.',1,3)='pgb' AND (SELECT pg_catalog.count(*) FROM pg_catalog.pg_namespace WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,3) = substring ('pgb',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) > 1 UNION SELECT pg_catalog.quote_ident (n.nspname) || '.' || pg_catalog.quote_ident(c.relname) FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n WHERE c.relnamespace = n.oid AND c.relkind IN ('r', 'S', 'v', 'm', 'f') AND substring(pg_catalog.quote_ident (n.nspname) || '.' || pg_catalog.quote_ident(c.relname),1,3)='pgb' AND substring(pg_catalog.quote_ident (n.nspname) || '.',1,3) = substring('pgb',1,pg_catalog.length(pg_catalog.quote_ident(n.nspname))+1) AND (SELECT pg_catalog.count(*) FROM pg_catalog.pg_namespace WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,3) = substring('pgb',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) = 1 LIMIT 1000; [2] (SELECT pg_catalog.count(*) FROM pg_catalog.pg_namespace WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,3) = substring('pgb',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1) With Regards, Amit Kapila. EnterpriseDB: http://www.enterprisedb.com