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

Commite89a71f

Browse files
committed
Pass InitPlan values to workers via Gather (Merge).
If a PARAM_EXEC parameter is used below a Gather (Merge) but the InitPlanthat computes it is attached to or above the Gather (Merge), force thevalue to be computed before starting parallelism and pass it down to allworkers. This allows us to use parallelism in cases where it previouslywould have had to be rejected as unsafe. We do - in this case - lose theoptimization that the value is only computed if it's actually used. Analternative strategy would be to have the first worker that needs the valuecompute it, but one downside of that approach is that we'd then need toselect a parallel-safe path to compute the parameter value; it couldn't forexample contain a Gather (Merge) node. At some point in the future, wemight want to consider both approaches.Independent of that consideration, there is a great deal more work thatcould be done to make more kinds of PARAM_EXEC parameters parallel-safe.This infrastructure could be used to allow a Gather (Merge) on the innerside of a nested loop (although that's not a very appealing plan) andcases where the InitPlan is attached below the Gather (Merge) could beaddressed as well using various techniques. But this is a good start.Amit Kapila, reviewed and revised by me. Reviewing and testing fromKuntal Ghosh, Haribabu Kommi, and Tushar Ahuja.Discussion:http://postgr.es/m/CAA4eK1LV0Y1AUV4cUCdC+sYOx0Z0-8NAJ2Pd9=UKsbQ5Sr7+JQ@mail.gmail.com
1 parentff2d435 commite89a71f

File tree

17 files changed

+419
-23
lines changed

17 files changed

+419
-23
lines changed

‎src/backend/commands/explain.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static void show_tidbitmap_info(BitmapHeapScanState *planstate,
107107
staticvoidshow_instrumentation_count(constchar*qlabel,intwhich,
108108
PlanState*planstate,ExplainState*es);
109109
staticvoidshow_foreignscan_info(ForeignScanState*fsstate,ExplainState*es);
110+
staticvoidshow_eval_params(Bitmapset*bms_params,ExplainState*es);
110111
staticconstchar*explain_get_index_name(OidindexId);
111112
staticvoidshow_buffer_usage(ExplainState*es,constBufferUsage*usage);
112113
staticvoidExplainIndexScanDetails(Oidindexid,ScanDirectionindexorderdir,
@@ -1441,6 +1442,11 @@ ExplainNode(PlanState *planstate, List *ancestors,
14411442
planstate,es);
14421443
ExplainPropertyInteger("Workers Planned",
14431444
gather->num_workers,es);
1445+
1446+
/* Show params evaluated at gather node */
1447+
if (gather->initParam)
1448+
show_eval_params(gather->initParam,es);
1449+
14441450
if (es->analyze)
14451451
{
14461452
intnworkers;
@@ -1463,6 +1469,11 @@ ExplainNode(PlanState *planstate, List *ancestors,
14631469
planstate,es);
14641470
ExplainPropertyInteger("Workers Planned",
14651471
gm->num_workers,es);
1472+
1473+
/* Show params evaluated at gather-merge node */
1474+
if (gm->initParam)
1475+
show_eval_params(gm->initParam,es);
1476+
14661477
if (es->analyze)
14671478
{
14681479
intnworkers;
@@ -2487,6 +2498,29 @@ show_foreignscan_info(ForeignScanState *fsstate, ExplainState *es)
24872498
}
24882499
}
24892500

2501+
/*
2502+
* Show initplan params evaluated at Gather or Gather Merge node.
2503+
*/
2504+
staticvoid
2505+
show_eval_params(Bitmapset*bms_params,ExplainState*es)
2506+
{
2507+
intparamid=-1;
2508+
List*params=NIL;
2509+
2510+
Assert(bms_params);
2511+
2512+
while ((paramid=bms_next_member(bms_params,paramid)) >=0)
2513+
{
2514+
charparam[32];
2515+
2516+
snprintf(param,sizeof(param),"$%d",paramid);
2517+
params=lappend(params,pstrdup(param));
2518+
}
2519+
2520+
if (params)
2521+
ExplainPropertyList("Params Evaluated",params,es);
2522+
}
2523+
24902524
/*
24912525
* Fetch the name of an index in an EXPLAIN
24922526
*

‎src/backend/executor/execExprInterp.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,33 @@ ExecEvalParamExec(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
19261926
*op->resnull=prm->isnull;
19271927
}
19281928

1929+
/*
1930+
* ExecEvalParamExecParams
1931+
*
1932+
* Execute the subplan stored in PARAM_EXEC initplans params, if not executed
1933+
* till now.
1934+
*/
1935+
void
1936+
ExecEvalParamExecParams(Bitmapset*params,EState*estate)
1937+
{
1938+
ParamExecData*prm;
1939+
intparamid;
1940+
1941+
paramid=-1;
1942+
while ((paramid=bms_next_member(params,paramid)) >=0)
1943+
{
1944+
prm=&(estate->es_param_exec_vals[paramid]);
1945+
1946+
if (prm->execPlan!=NULL)
1947+
{
1948+
/* Parameter not evaluated yet, so go do it */
1949+
ExecSetParamPlan(prm->execPlan,GetPerTupleExprContext(estate));
1950+
/* ExecSetParamPlan should have processed this param... */
1951+
Assert(prm->execPlan==NULL);
1952+
}
1953+
}
1954+
}
1955+
19291956
/*
19301957
* Evaluate a PARAM_EXTERN parameter.
19311958
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp