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

Commit742fd06

Browse files
committed
Fix up ruleutils.c for CTE features. The main problem was that
get_name_for_var_field didn't have enough context to interpret a reference toa CTE query's output. Fixing this requires separate hacks for the regulardeparse case (pg_get_ruledef) and for the EXPLAIN case, since the availablecontext information is quite different. It's pretty nearly parallel to theexisting code for SUBQUERY RTEs, though. Also, add code to make sure wequalify a relation name that matches a CTE name; else the CTE will mistakenlycapture the reference when reloading the rule.In passing, fix a pre-existing problem with get_name_for_var_field not workingon variables in targetlists of SubqueryScan plan nodes. Although latent allalong, this wasn't a problem until we made EXPLAIN VERBOSE try to printtargetlists. To do this, refactor the deparse_context_for_plan API so thatthe special case for SubqueryScan is all on ruleutils.c's side.
1 parentbf46153 commit742fd06

File tree

3 files changed

+249
-72
lines changed

3 files changed

+249
-72
lines changed

‎src/backend/commands/explain.c

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994-5, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.179 2008/10/04 21:56:52 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.180 2008/10/06 20:29:38 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -63,7 +63,7 @@ static void explain_outNode(StringInfo str,
6363
staticvoidshow_plan_tlist(Plan*plan,
6464
StringInfostr,intindent,ExplainState*es);
6565
staticvoidshow_scan_qual(List*qual,constchar*qlabel,
66-
intscanrelid,Plan*outer_plan,Plan*inner_plan,
66+
intscanrelid,Plan*scan_plan,Plan*outer_plan,
6767
StringInfostr,intindent,ExplainState*es);
6868
staticvoidshow_upper_qual(List*qual,constchar*qlabel,Plan*plan,
6969
StringInfostr,intindent,ExplainState*es);
@@ -804,27 +804,27 @@ explain_outNode(StringInfo str,
804804
show_scan_qual(((IndexScan*)plan)->indexqualorig,
805805
"Index Cond",
806806
((Scan*)plan)->scanrelid,
807-
outer_plan,NULL,
807+
plan,outer_plan,
808808
str,indent,es);
809809
show_scan_qual(plan->qual,
810810
"Filter",
811811
((Scan*)plan)->scanrelid,
812-
outer_plan,NULL,
812+
plan,outer_plan,
813813
str,indent,es);
814814
break;
815815
caseT_BitmapIndexScan:
816816
show_scan_qual(((BitmapIndexScan*)plan)->indexqualorig,
817817
"Index Cond",
818818
((Scan*)plan)->scanrelid,
819-
outer_plan,NULL,
819+
plan,outer_plan,
820820
str,indent,es);
821821
break;
822822
caseT_BitmapHeapScan:
823823
/* XXX do we want to show this in production? */
824824
show_scan_qual(((BitmapHeapScan*)plan)->bitmapqualorig,
825825
"Recheck Cond",
826826
((Scan*)plan)->scanrelid,
827-
outer_plan,NULL,
827+
plan,outer_plan,
828828
str,indent,es);
829829
/* FALL THRU */
830830
caseT_SeqScan:
@@ -835,15 +835,14 @@ explain_outNode(StringInfo str,
835835
show_scan_qual(plan->qual,
836836
"Filter",
837837
((Scan*)plan)->scanrelid,
838-
outer_plan,NULL,
838+
plan,outer_plan,
839839
str,indent,es);
840840
break;
841841
caseT_SubqueryScan:
842842
show_scan_qual(plan->qual,
843843
"Filter",
844844
((Scan*)plan)->scanrelid,
845-
outer_plan,
846-
((SubqueryScan*)plan)->subplan,
845+
plan,outer_plan,
847846
str,indent,es);
848847
break;
849848
caseT_TidScan:
@@ -859,12 +858,12 @@ explain_outNode(StringInfo str,
859858
show_scan_qual(tidquals,
860859
"TID Cond",
861860
((Scan*)plan)->scanrelid,
862-
outer_plan,NULL,
861+
plan,outer_plan,
863862
str,indent,es);
864863
show_scan_qual(plan->qual,
865864
"Filter",
866865
((Scan*)plan)->scanrelid,
867-
outer_plan,NULL,
866+
plan,outer_plan,
868867
str,indent,es);
869868
}
870869
break;
@@ -1121,9 +1120,10 @@ show_plan_tlist(Plan *plan,
11211120
return;
11221121

11231122
/* Set up deparsing context */
1124-
context=deparse_context_for_plan((Node*)outerPlan(plan),
1125-
(Node*)innerPlan(plan),
1126-
es->rtable);
1123+
context=deparse_context_for_plan((Node*)plan,
1124+
NULL,
1125+
es->rtable,
1126+
es->pstmt->subplans);
11271127
useprefix=list_length(es->rtable)>1;
11281128

11291129
/* Emit line prefix */
@@ -1153,12 +1153,11 @@ show_plan_tlist(Plan *plan,
11531153
* Show a qualifier expression for a scan plan node
11541154
*
11551155
* Note: outer_plan is the referent for any OUTER vars in the scan qual;
1156-
* this would be the outer side of a nestloop plan. inner_plan should be
1157-
* NULL except for a SubqueryScan plan node, where it should be the subplan.
1156+
* this would be the outer side of a nestloop plan. Pass NULL if none.
11581157
*/
11591158
staticvoid
11601159
show_scan_qual(List*qual,constchar*qlabel,
1161-
intscanrelid,Plan*outer_plan,Plan*inner_plan,
1160+
intscanrelid,Plan*scan_plan,Plan*outer_plan,
11621161
StringInfostr,intindent,ExplainState*es)
11631162
{
11641163
List*context;
@@ -1175,10 +1174,11 @@ show_scan_qual(List *qual, const char *qlabel,
11751174
node= (Node*)make_ands_explicit(qual);
11761175

11771176
/* Set up deparsing context */
1178-
context=deparse_context_for_plan((Node*)outer_plan,
1179-
(Node*)inner_plan,
1180-
es->rtable);
1181-
useprefix= (outer_plan!=NULL||inner_plan!=NULL);
1177+
context=deparse_context_for_plan((Node*)scan_plan,
1178+
(Node*)outer_plan,
1179+
es->rtable,
1180+
es->pstmt->subplans);
1181+
useprefix= (outer_plan!=NULL||IsA(scan_plan,SubqueryScan));
11821182

11831183
/* Deparse the expression */
11841184
exprstr=deparse_expression(node,context,useprefix, false);
@@ -1207,9 +1207,10 @@ show_upper_qual(List *qual, const char *qlabel, Plan *plan,
12071207
return;
12081208

12091209
/* Set up deparsing context */
1210-
context=deparse_context_for_plan((Node*)outerPlan(plan),
1211-
(Node*)innerPlan(plan),
1212-
es->rtable);
1210+
context=deparse_context_for_plan((Node*)plan,
1211+
NULL,
1212+
es->rtable,
1213+
es->pstmt->subplans);
12131214
useprefix=list_length(es->rtable)>1;
12141215

12151216
/* Deparse the expression */
@@ -1244,9 +1245,10 @@ show_sort_keys(Plan *sortplan, int nkeys, AttrNumber *keycols,
12441245
appendStringInfo(str," %s: ",qlabel);
12451246

12461247
/* Set up deparsing context */
1247-
context=deparse_context_for_plan((Node*)outerPlan(sortplan),
1248-
NULL,/* Sort has no innerPlan */
1249-
es->rtable);
1248+
context=deparse_context_for_plan((Node*)sortplan,
1249+
NULL,
1250+
es->rtable,
1251+
es->pstmt->subplans);
12501252
useprefix=list_length(es->rtable)>1;
12511253

12521254
for (keyno=0;keyno<nkeys;keyno++)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp