Fix crashes on plans with multiple Gather (Merge) nodes.
es_query_dsa turns out to be broken by design, because it supposes that there is only one DSA for the whole query, whereas there is actually one per Gather (Merge) node. For now, work around that problem by setting and clearing the pointer around the sections of code that might need it. It's probably a better idea to get rid of es_query_dsa altogether in favor of having each node keep track individually of which DSA is relevant, but that seems like more than we would want to back-patch. Thomas Munro, reviewed and tested by Andreas Seltenreich, Amit Kapila, and by me. Discussion: http://postgr.es/m/CAEepm=1U6as=brnVvMNixEV2tpi8NuyQoTmO8Qef0-VV+=7MDA@mail.gmail.com
This commit is contained in:
parent
ac93acbc05
commit
b70ea4c75e
@ -543,12 +543,6 @@ ExecInitParallelPlan(PlanState *planstate, EState *estate, int nworkers)
|
|||||||
pcxt->seg);
|
pcxt->seg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Make the area available to executor nodes running in the leader. See
|
|
||||||
* also ParallelQueryMain which makes it available to workers.
|
|
||||||
*/
|
|
||||||
estate->es_query_dsa = pei->area;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Give parallel-aware nodes a chance to initialize their shared data.
|
* Give parallel-aware nodes a chance to initialize their shared data.
|
||||||
* This also initializes the elements of instrumentation->ps_instrument,
|
* This also initializes the elements of instrumentation->ps_instrument,
|
||||||
@ -557,7 +551,11 @@ ExecInitParallelPlan(PlanState *planstate, EState *estate, int nworkers)
|
|||||||
d.pcxt = pcxt;
|
d.pcxt = pcxt;
|
||||||
d.instrumentation = instrumentation;
|
d.instrumentation = instrumentation;
|
||||||
d.nnodes = 0;
|
d.nnodes = 0;
|
||||||
|
|
||||||
|
/* Install our DSA area while initializing the plan. */
|
||||||
|
estate->es_query_dsa = pei->area;
|
||||||
ExecParallelInitializeDSM(planstate, &d);
|
ExecParallelInitializeDSM(planstate, &d);
|
||||||
|
estate->es_query_dsa = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure that the world hasn't shifted under our feet. This could
|
* Make sure that the world hasn't shifted under our feet. This could
|
||||||
@ -609,6 +607,8 @@ void
|
|||||||
ExecParallelReinitialize(PlanState *planstate,
|
ExecParallelReinitialize(PlanState *planstate,
|
||||||
ParallelExecutorInfo *pei)
|
ParallelExecutorInfo *pei)
|
||||||
{
|
{
|
||||||
|
EState *estate = planstate->state;
|
||||||
|
|
||||||
/* Old workers must already be shut down */
|
/* Old workers must already be shut down */
|
||||||
Assert(pei->finished);
|
Assert(pei->finished);
|
||||||
|
|
||||||
@ -618,7 +618,9 @@ ExecParallelReinitialize(PlanState *planstate,
|
|||||||
pei->finished = false;
|
pei->finished = false;
|
||||||
|
|
||||||
/* Traverse plan tree and let each child node reset associated state. */
|
/* Traverse plan tree and let each child node reset associated state. */
|
||||||
|
estate->es_query_dsa = pei->area;
|
||||||
ExecParallelReInitializeDSM(planstate, pei->pcxt);
|
ExecParallelReInitializeDSM(planstate, pei->pcxt);
|
||||||
|
estate->es_query_dsa = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -278,7 +278,13 @@ gather_getnext(GatherState *gatherstate)
|
|||||||
|
|
||||||
if (gatherstate->need_to_scan_locally)
|
if (gatherstate->need_to_scan_locally)
|
||||||
{
|
{
|
||||||
|
EState *estate = gatherstate->ps.state;
|
||||||
|
|
||||||
|
/* Install our DSA area while executing the plan. */
|
||||||
|
estate->es_query_dsa =
|
||||||
|
gatherstate->pei ? gatherstate->pei->area : NULL;
|
||||||
outerTupleSlot = ExecProcNode(outerPlan);
|
outerTupleSlot = ExecProcNode(outerPlan);
|
||||||
|
estate->es_query_dsa = NULL;
|
||||||
|
|
||||||
if (!TupIsNull(outerTupleSlot))
|
if (!TupIsNull(outerTupleSlot))
|
||||||
return outerTupleSlot;
|
return outerTupleSlot;
|
||||||
|
@ -627,8 +627,12 @@ gather_merge_readnext(GatherMergeState *gm_state, int reader, bool nowait)
|
|||||||
{
|
{
|
||||||
PlanState *outerPlan = outerPlanState(gm_state);
|
PlanState *outerPlan = outerPlanState(gm_state);
|
||||||
TupleTableSlot *outerTupleSlot;
|
TupleTableSlot *outerTupleSlot;
|
||||||
|
EState *estate = gm_state->ps.state;
|
||||||
|
|
||||||
|
/* Install our DSA area while executing the plan. */
|
||||||
|
estate->es_query_dsa = gm_state->pei ? gm_state->pei->area : NULL;
|
||||||
outerTupleSlot = ExecProcNode(outerPlan);
|
outerTupleSlot = ExecProcNode(outerPlan);
|
||||||
|
estate->es_query_dsa = NULL;
|
||||||
|
|
||||||
if (!TupIsNull(outerTupleSlot))
|
if (!TupIsNull(outerTupleSlot))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user