Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd7c0fa

Browse files
committed
Fix crashes on plans with multiple Gather (Merge) nodes.
es_query_dsa turns out to be broken by design, because it supposesthat there is only one DSA for the whole query, whereas there isactually one per Gather (Merge) node. For now, work around thatproblem by setting and clearing the pointer around the sections ofcode that might need it. It's probably a better idea to get rid ofes_query_dsa altogether in favor of having each node keep trackindividually of which DSA is relevant, but that seems like more thanwe would want to back-patch.Thomas Munro, reviewed and tested by Andreas Seltenreich, AmitKapila, and by me.Discussion:http://postgr.es/m/CAEepm=1U6as=brnVvMNixEV2tpi8NuyQoTmO8Qef0-VV+=7MDA@mail.gmail.com
1 parent7731c32 commitfd7c0fa

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

‎src/backend/executor/execParallel.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ EstimateParamExecSpace(EState *estate, Bitmapset *params)
330330
* parameter array) and then the datum as serialized by datumSerialize().
331331
*/
332332
staticdsa_pointer
333-
SerializeParamExecParams(EState*estate,Bitmapset*params)
333+
SerializeParamExecParams(EState*estate,Bitmapset*params,dsa_area*area)
334334
{
335335
Sizesize;
336336
intnparams;
@@ -341,8 +341,8 @@ SerializeParamExecParams(EState *estate, Bitmapset *params)
341341

342342
/* Allocate enough space for the current parameter values. */
343343
size=EstimateParamExecSpace(estate,params);
344-
handle=dsa_allocate(estate->es_query_dsa,size);
345-
start_address=dsa_get_address(estate->es_query_dsa,handle);
344+
handle=dsa_allocate(area,size);
345+
start_address=dsa_get_address(area,handle);
346346

347347
/* First write the number of parameters as a 4-byte integer. */
348348
nparams=bms_num_members(params);
@@ -736,12 +736,6 @@ ExecInitParallelPlan(PlanState *planstate, EState *estate,
736736
LWTRANCHE_PARALLEL_QUERY_DSA,
737737
pcxt->seg);
738738

739-
/*
740-
* Make the area available to executor nodes running in the leader.
741-
* See also ParallelQueryMain which makes it available to workers.
742-
*/
743-
estate->es_query_dsa=pei->area;
744-
745739
/*
746740
* Serialize parameters, if any, using DSA storage. We don't dare use
747741
* the main parallel query DSM for this because we might relaunch
@@ -750,7 +744,8 @@ ExecInitParallelPlan(PlanState *planstate, EState *estate,
750744
*/
751745
if (!bms_is_empty(sendParams))
752746
{
753-
pei->param_exec=SerializeParamExecParams(estate,sendParams);
747+
pei->param_exec=SerializeParamExecParams(estate,sendParams,
748+
pei->area);
754749
fpes->param_exec=pei->param_exec;
755750
}
756751
}
@@ -763,7 +758,11 @@ ExecInitParallelPlan(PlanState *planstate, EState *estate,
763758
d.pcxt=pcxt;
764759
d.instrumentation=instrumentation;
765760
d.nnodes=0;
761+
762+
/* Install our DSA area while initializing the plan. */
763+
estate->es_query_dsa=pei->area;
766764
ExecParallelInitializeDSM(planstate,&d);
765+
estate->es_query_dsa=NULL;
767766

768767
/*
769768
* Make sure that the world hasn't shifted under our feet. This could
@@ -832,19 +831,22 @@ ExecParallelReinitialize(PlanState *planstate,
832831
/* Free any serialized parameters from the last round. */
833832
if (DsaPointerIsValid(fpes->param_exec))
834833
{
835-
dsa_free(estate->es_query_dsa,fpes->param_exec);
834+
dsa_free(pei->area,fpes->param_exec);
836835
fpes->param_exec=InvalidDsaPointer;
837836
}
838837

839838
/* Serialize current parameter values if required. */
840839
if (!bms_is_empty(sendParams))
841840
{
842-
pei->param_exec=SerializeParamExecParams(estate,sendParams);
841+
pei->param_exec=SerializeParamExecParams(estate,sendParams,
842+
pei->area);
843843
fpes->param_exec=pei->param_exec;
844844
}
845845

846846
/* Traverse plan tree and let each child node reset associated state. */
847+
estate->es_query_dsa=pei->area;
847848
ExecParallelReInitializeDSM(planstate,pei->pcxt);
849+
estate->es_query_dsa=NULL;
848850
}
849851

850852
/*

‎src/backend/executor/nodeGather.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,13 @@ gather_getnext(GatherState *gatherstate)
277277

278278
if (gatherstate->need_to_scan_locally)
279279
{
280+
EState*estate=gatherstate->ps.state;
281+
282+
/* Install our DSA area while executing the plan. */
283+
estate->es_query_dsa=
284+
gatherstate->pei ?gatherstate->pei->area :NULL;
280285
outerTupleSlot=ExecProcNode(outerPlan);
286+
estate->es_query_dsa=NULL;
281287

282288
if (!TupIsNull(outerTupleSlot))
283289
returnouterTupleSlot;

‎src/backend/executor/nodeGatherMerge.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,12 @@ gather_merge_readnext(GatherMergeState *gm_state, int reader, bool nowait)
637637
{
638638
PlanState*outerPlan=outerPlanState(gm_state);
639639
TupleTableSlot*outerTupleSlot;
640+
EState*estate=gm_state->ps.state;
640641

642+
/* Install our DSA area while executing the plan. */
643+
estate->es_query_dsa=gm_state->pei ?gm_state->pei->area :NULL;
641644
outerTupleSlot=ExecProcNode(outerPlan);
645+
estate->es_query_dsa=NULL;
642646

643647
if (!TupIsNull(outerTupleSlot))
644648
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp