Re: Parallel Seq Scan

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Thom Brown <thom(at)linux(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Andres Freund <andres(at)2ndquadrant(dot)com>, Kouhei Kaigai <kaigai(at)ak(dot)jp(dot)nec(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>, Fabrízio Mello <fabriziomello(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Parallel Seq Scan
Date: 2015-04-02 13:16:03
Message-ID: CA+TgmoacjmBzj=o0z0SyAuXQ6LqRcDxPKntnm79ZRMZVUBAEeQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Apr 2, 2015 at 2:36 AM, Amit Kapila <amit(dot)kapila16(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2015-04-02 13:17:44 Re: Parallel Seq Scan
Previous Message Robert Haas 2015-04-02 13:07:00 Re: Additional role attributes && superuser review