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

Commit842a23e

Browse files
committed
Fix handling of "Subplans Removed" field in EXPLAIN output.
Commit499be01 added this field in a rather poorly-thought-throughmanner, with the result being that rather than being a field of theAppend or MergeAppend plan node as intended (and as it seems to be,in text format), it was actually an element of the "Plans" subgroup.At least in JSON format, that's flat out invalid syntax, because"Plans" is an array not an object.While it's not hard to move the generation of the field so that itappears where it's supposed to, this does result in a visible changein field order in text format, in cases where a Append or MergeAppendplan node has any InitPlans attached. That's slightly annoying todo in stable branches; but the alternative of continuing to emitbroken non-text formats seems worse.Also, since the set of fields emitted is not supposed to bedata-dependent in non-text formats, make sure that "Subplans Removed"appears in Append and MergeAppend nodes even when it's zero, in thoseformats. (The previous coding made it look like it could appear insome other node types such as BitmapAnd, but we don't actually supportruntime pruning there, so don't emit it in those cases.)Per bug #16171 from Mahadevan Ramachandran. Fix by Daniel Gustafssonand Tom Lane, reviewed by Hamid Akhtar. Back-patch to v11 where thiscode came in.Discussion:https://postgr.es/m/16171-b72259ab75505fa2@postgresql.org
1 parentbeefab6 commit842a23e

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

‎src/backend/commands/explain.c

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ static void ExplainModifyTarget(ModifyTable *plan, ExplainState *es);
118118
staticvoidExplainTargetRel(Plan*plan,Indexrti,ExplainState*es);
119119
staticvoidshow_modifytable_info(ModifyTableState*mtstate,List*ancestors,
120120
ExplainState*es);
121-
staticvoidExplainMemberNodes(PlanState**planstates,intnsubnodes,
122-
intnplans,List*ancestors,ExplainState*es);
121+
staticvoidExplainMemberNodes(PlanState**planstates,intnplans,
122+
List*ancestors,ExplainState*es);
123+
staticvoidExplainMissingMembers(intnplans,intnchildren,ExplainState*es);
123124
staticvoidExplainSubPlans(List*plans,List*ancestors,
124125
constchar*relationship,ExplainState*es);
125126
staticvoidExplainCustomChildren(CustomScanState*css,
@@ -1862,6 +1863,30 @@ ExplainNode(PlanState *planstate, List *ancestors,
18621863
ExplainCloseGroup("Workers","Workers", false,es);
18631864
}
18641865

1866+
/*
1867+
* If partition pruning was done during executor initialization, the
1868+
* number of child plans we'll display below will be less than the number
1869+
* of subplans that was specified in the plan. To make this a bit less
1870+
* mysterious, emit an indication that this happened. Note that this
1871+
* field is emitted now because we want it to be a property of the parent
1872+
* node; it *cannot* be emitted within the Plans sub-node we'll open next.
1873+
*/
1874+
switch (nodeTag(plan))
1875+
{
1876+
caseT_Append:
1877+
ExplainMissingMembers(((AppendState*)planstate)->as_nplans,
1878+
list_length(((Append*)plan)->appendplans),
1879+
es);
1880+
break;
1881+
caseT_MergeAppend:
1882+
ExplainMissingMembers(((MergeAppendState*)planstate)->ms_nplans,
1883+
list_length(((MergeAppend*)plan)->mergeplans),
1884+
es);
1885+
break;
1886+
default:
1887+
break;
1888+
}
1889+
18651890
/* Get ready to display the child plans */
18661891
haschildren=planstate->initPlan||
18671892
outerPlanState(planstate)||
@@ -1902,31 +1927,26 @@ ExplainNode(PlanState *planstate, List *ancestors,
19021927
caseT_ModifyTable:
19031928
ExplainMemberNodes(((ModifyTableState*)planstate)->mt_plans,
19041929
((ModifyTableState*)planstate)->mt_nplans,
1905-
list_length(((ModifyTable*)plan)->plans),
19061930
ancestors,es);
19071931
break;
19081932
caseT_Append:
19091933
ExplainMemberNodes(((AppendState*)planstate)->appendplans,
19101934
((AppendState*)planstate)->as_nplans,
1911-
list_length(((Append*)plan)->appendplans),
19121935
ancestors,es);
19131936
break;
19141937
caseT_MergeAppend:
19151938
ExplainMemberNodes(((MergeAppendState*)planstate)->mergeplans,
19161939
((MergeAppendState*)planstate)->ms_nplans,
1917-
list_length(((MergeAppend*)plan)->mergeplans),
19181940
ancestors,es);
19191941
break;
19201942
caseT_BitmapAnd:
19211943
ExplainMemberNodes(((BitmapAndState*)planstate)->bitmapplans,
19221944
((BitmapAndState*)planstate)->nplans,
1923-
list_length(((BitmapAnd*)plan)->bitmapplans),
19241945
ancestors,es);
19251946
break;
19261947
caseT_BitmapOr:
19271948
ExplainMemberNodes(((BitmapOrState*)planstate)->bitmapplans,
19281949
((BitmapOrState*)planstate)->nplans,
1929-
list_length(((BitmapOr*)plan)->bitmapplans),
19301950
ancestors,es);
19311951
break;
19321952
caseT_SubqueryScan:
@@ -3237,32 +3257,33 @@ show_modifytable_info(ModifyTableState *mtstate, List *ancestors,
32373257
*
32383258
* The ancestors list should already contain the immediate parent of these
32393259
* plans.
3240-
*
3241-
* nsubnodes indicates the number of items in the planstates array.
3242-
* nplans indicates the original number of subnodes in the Plan, some of these
3243-
* may have been pruned by the run-time pruning code.
32443260
*/
32453261
staticvoid
3246-
ExplainMemberNodes(PlanState**planstates,intnsubnodes,intnplans,
3262+
ExplainMemberNodes(PlanState**planstates,intnplans,
32473263
List*ancestors,ExplainState*es)
32483264
{
32493265
intj;
32503266

3251-
/*
3252-
* The number of subnodes being lower than the number of subplans that was
3253-
* specified in the plan means that some subnodes have been ignored per
3254-
* instruction for the partition pruning code during the executor
3255-
* initialization. To make this a bit less mysterious, we'll indicate
3256-
* here that this has happened.
3257-
*/
3258-
if (nsubnodes<nplans)
3259-
ExplainPropertyInteger("Subplans Removed",NULL,nplans-nsubnodes,es);
3260-
3261-
for (j=0;j<nsubnodes;j++)
3267+
for (j=0;j<nplans;j++)
32623268
ExplainNode(planstates[j],ancestors,
32633269
"Member",NULL,es);
32643270
}
32653271

3272+
/*
3273+
* Report about any pruned subnodes of an Append or MergeAppend node.
3274+
*
3275+
* nplans indicates the number of live subplans.
3276+
* nchildren indicates the original number of subnodes in the Plan;
3277+
* some of these may have been pruned by the run-time pruning code.
3278+
*/
3279+
staticvoid
3280+
ExplainMissingMembers(intnplans,intnchildren,ExplainState*es)
3281+
{
3282+
if (nplans<nchildren||es->format!=EXPLAIN_FORMAT_TEXT)
3283+
ExplainPropertyInteger("Subplans Removed",NULL,
3284+
nchildren-nplans,es);
3285+
}
3286+
32663287
/*
32673288
* Explain a list of SubPlans (or initPlans, which also use SubPlan nodes).
32683289
*

‎src/test/regress/expected/partition_prune.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,9 +1887,9 @@ explain (analyze, costs off, summary off, timing off) execute ab_q2 (2, 2);
18871887
QUERY PLAN
18881888
--------------------------------------------------------
18891889
Append (actual rows=0 loops=1)
1890+
Subplans Removed: 6
18901891
InitPlan 1 (returns $0)
18911892
-> Result (actual rows=1 loops=1)
1892-
Subplans Removed: 6
18931893
-> Seq Scan on ab_a2_b1 (actual rows=0 loops=1)
18941894
Filter: ((a >= $1) AND (a <= $2) AND (b < $0))
18951895
-> Seq Scan on ab_a2_b2 (actual rows=0 loops=1)
@@ -1930,9 +1930,9 @@ explain (analyze, costs off, summary off, timing off) execute ab_q3 (2, 2);
19301930
QUERY PLAN
19311931
--------------------------------------------------------
19321932
Append (actual rows=0 loops=1)
1933+
Subplans Removed: 6
19331934
InitPlan 1 (returns $0)
19341935
-> Result (actual rows=1 loops=1)
1935-
Subplans Removed: 6
19361936
-> Seq Scan on ab_a1_b2 (actual rows=0 loops=1)
19371937
Filter: ((b >= $1) AND (b <= $2) AND (a < $0))
19381938
-> Seq Scan on ab_a2_b2 (actual rows=0 loops=1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp