On Thu, Apr 2, 2015 at 2:36 AM, Amit Kapila <amit.kapil...@gmail.com> wrote:
>> 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.

OK, I failed to realize that the initPlan doesn't get evaluated until
first use.  Maybe in the case of a funnel node we should force all of
the initplans to be run before starting parallelism, so that we can
pass down the resulting value to each worker.  If we try to push the
whole plan tree down from the worker then, aside from the issue of
needing to copy the plan tree, it'll get evaluated N times instead of
once.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to