Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc77005

Browse files
committed
Change Agg and Group nodes so that Vars contained in their targetlists
and quals have varno OUTER, rather than zero, to indicate a reference to an output of their lefttree subplan. This is consistent with the way that every other upper-level node type does it, and allows some simplifications in setrefs.c and EXPLAIN.
1 parent 3c5985b commit cc77005

File tree

6 files changed

+72
-64
lines changed

6 files changed

+72
-64
lines changed

src/backend/commands/explain.c

Lines changed: 41 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.157 2007/02/22 22:00:22 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.158 2007/02/22 23:44:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -52,8 +52,8 @@ static void show_scan_qual(List *qual, const char *qlabel,
5252
int scanrelid, Plan *outer_plan,
5353
StringInfo str, int indent, ExplainState *es);
5454
static void show_upper_qual(List *qual, const char *qlabel,
55-
const char *outer_name, int outer_varno, Plan *outer_plan,
56-
const char *inner_name, int inner_varno, Plan *inner_plan,
55+
const char *outer_name, Plan *outer_plan,
56+
const char *inner_name, Plan *inner_plan,
5757
StringInfo str, int indent, ExplainState *es);
5858
static void show_sort_keys(Plan *sortplan, int nkeys, AttrNumber *keycols,
5959
const char *qlabel,
@@ -783,55 +783,55 @@ explain_outNode(StringInfo str,
783783
case T_NestLoop:
784784
show_upper_qual(((NestLoop *) plan)->join.joinqual,
785785
"Join Filter",
786-
"outer", OUTER, outerPlan(plan),
787-
"inner", INNER, innerPlan(plan),
786+
"outer", outerPlan(plan),
787+
"inner", innerPlan(plan),
788788
str, indent, es);
789789
show_upper_qual(plan->qual,
790790
"Filter",
791-
"outer", OUTER, outerPlan(plan),
792-
"inner", INNER, innerPlan(plan),
791+
"outer", outerPlan(plan),
792+
"inner", innerPlan(plan),
793793
str, indent, es);
794794
break;
795795
case T_MergeJoin:
796796
show_upper_qual(((MergeJoin *) plan)->mergeclauses,
797797
"Merge Cond",
798-
"outer", OUTER, outerPlan(plan),
799-
"inner", INNER, innerPlan(plan),
798+
"outer", outerPlan(plan),
799+
"inner", innerPlan(plan),
800800
str, indent, es);
801801
show_upper_qual(((MergeJoin *) plan)->join.joinqual,
802802
"Join Filter",
803-
"outer", OUTER, outerPlan(plan),
804-
"inner", INNER, innerPlan(plan),
803+
"outer", outerPlan(plan),
804+
"inner", innerPlan(plan),
805805
str, indent, es);
806806
show_upper_qual(plan->qual,
807807
"Filter",
808-
"outer", OUTER, outerPlan(plan),
809-
"inner", INNER, innerPlan(plan),
808+
"outer", outerPlan(plan),
809+
"inner", innerPlan(plan),
810810
str, indent, es);
811811
break;
812812
case T_HashJoin:
813813
show_upper_qual(((HashJoin *) plan)->hashclauses,
814814
"Hash Cond",
815-
"outer", OUTER, outerPlan(plan),
816-
"inner", INNER, innerPlan(plan),
815+
"outer", outerPlan(plan),
816+
"inner", innerPlan(plan),
817817
str, indent, es);
818818
show_upper_qual(((HashJoin *) plan)->join.joinqual,
819819
"Join Filter",
820-
"outer", OUTER, outerPlan(plan),
821-
"inner", INNER, innerPlan(plan),
820+
"outer", outerPlan(plan),
821+
"inner", innerPlan(plan),
822822
str, indent, es);
823823
show_upper_qual(plan->qual,
824824
"Filter",
825-
"outer", OUTER, outerPlan(plan),
826-
"inner", INNER, innerPlan(plan),
825+
"outer", outerPlan(plan),
826+
"inner", innerPlan(plan),
827827
str, indent, es);
828828
break;
829829
case T_Agg:
830830
case T_Group:
831831
show_upper_qual(plan->qual,
832832
"Filter",
833-
"subplan", 0, outerPlan(plan),
834-
"", 0, NULL,
833+
"subplan", outerPlan(plan),
834+
"", NULL,
835835
str, indent, es);
836836
break;
837837
case T_Sort:
@@ -844,13 +844,13 @@ explain_outNode(StringInfo str,
844844
case T_Result:
845845
show_upper_qual((List *) ((Result *) plan)->resconstantqual,
846846
"One-Time Filter",
847-
"subplan", OUTER, outerPlan(plan),
848-
"", 0, NULL,
847+
"subplan", outerPlan(plan),
848+
"", NULL,
849849
str, indent, es);
850850
show_upper_qual(plan->qual,
851851
"Filter",
852-
"subplan", OUTER, outerPlan(plan),
853-
"", 0, NULL,
852+
"subplan", outerPlan(plan),
853+
"", NULL,
854854
str, indent, es);
855855
break;
856856
default:
@@ -1088,13 +1088,15 @@ show_scan_qual(List *qual, const char *qlabel,
10881088
*/
10891089
static void
10901090
show_upper_qual(List *qual, const char *qlabel,
1091-
const char *outer_name, int outer_varno, Plan *outer_plan,
1092-
const char *inner_name, int inner_varno, Plan *inner_plan,
1091+
const char *outer_name, Plan *outer_plan,
1092+
const char *inner_name, Plan *inner_plan,
10931093
StringInfo str, int indent, ExplainState *es)
10941094
{
10951095
List *context;
10961096
Node *outercontext;
10971097
Node *innercontext;
1098+
int outer_varno;
1099+
int inner_varno;
10981100
Node *node;
10991101
char *exprstr;
11001102
int i;
@@ -1105,15 +1107,27 @@ show_upper_qual(List *qual, const char *qlabel,
11051107

11061108
/* Generate deparse context */
11071109
if (outer_plan)
1110+
{
11081111
outercontext = deparse_context_for_subplan(outer_name,
11091112
(Node *) outer_plan);
1113+
outer_varno = OUTER;
1114+
}
11101115
else
1116+
{
11111117
outercontext = NULL;
1118+
outer_varno = 0;
1119+
}
11121120
if (inner_plan)
1121+
{
11131122
innercontext = deparse_context_for_subplan(inner_name,
11141123
(Node *) inner_plan);
1124+
inner_varno = INNER;
1125+
}
11151126
else
1127+
{
11161128
innercontext = NULL;
1129+
inner_varno = 0;
1130+
}
11171131
context = deparse_context_for_plan(outer_varno, outercontext,
11181132
inner_varno, innercontext,
11191133
es->rtable);

src/backend/executor/nodeAgg.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
* Portions Copyright (c) 1994, Regents of the University of California
6262
*
6363
* IDENTIFICATION
64-
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.150 2007/02/02 00:07:03 tgl Exp $
64+
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.151 2007/02/22 23:44:24 tgl Exp $
6565
*
6666
*-------------------------------------------------------------------------
6767
*/
@@ -420,7 +420,7 @@ advance_transition_function(AggState *aggstate,
420420

421421
/*
422422
* Advance all the aggregates for one input tuple. The input tuple
423-
* has been stored in tmpcontext->ecxt_scantuple, so that it is accessible
423+
* has been stored in tmpcontext->ecxt_outertuple, so that it is accessible
424424
* to ExecEvalExpr. pergroup is the array of per-group structs to use
425425
* (this might be in a hashtable entry).
426426
*
@@ -643,8 +643,8 @@ find_unaggregated_cols_walker(Node *node, Bitmapset **colnos)
643643
{
644644
Var *var = (Var *) node;
645645

646-
/* setrefs.c should have set the varno to 0 */
647-
Assert(var->varno == 0);
646+
/* setrefs.c should have set the varno to OUTER */
647+
Assert(var->varno == OUTER);
648648
Assert(var->varlevelsup == 0);
649649
*colnos = bms_add_member(*colnos, var->varattno);
650650
return false;
@@ -905,7 +905,7 @@ agg_retrieve_direct(AggState *aggstate)
905905
aggstate->grp_firstTuple = NULL; /* don't keep two pointers */
906906

907907
/* set up for first advance_aggregates call */
908-
tmpcontext->ecxt_scantuple = firstSlot;
908+
tmpcontext->ecxt_outertuple = firstSlot;
909909

910910
/*
911911
* Process each outer-plan tuple, and then fetch the next one,
@@ -926,7 +926,7 @@ agg_retrieve_direct(AggState *aggstate)
926926
break;
927927
}
928928
/* set up for next advance_aggregates call */
929-
tmpcontext->ecxt_scantuple = outerslot;
929+
tmpcontext->ecxt_outertuple = outerslot;
930930

931931
/*
932932
* If we are grouping, check whether we've crossed a group
@@ -973,7 +973,7 @@ agg_retrieve_direct(AggState *aggstate)
973973
* with an empty firstSlot ... but if not grouping, there can't be any
974974
* references to non-aggregated input columns, so no problem.)
975975
*/
976-
econtext->ecxt_scantuple = firstSlot;
976+
econtext->ecxt_outertuple = firstSlot;
977977

978978
/*
979979
* Check the qual (HAVING clause); if the group does not match, ignore
@@ -1022,7 +1022,7 @@ agg_fill_hash_table(AggState *aggstate)
10221022
if (TupIsNull(outerslot))
10231023
break;
10241024
/* set up for advance_aggregates call */
1025-
tmpcontext->ecxt_scantuple = outerslot;
1025+
tmpcontext->ecxt_outertuple = outerslot;
10261026

10271027
/* Find or build hashtable entry for this tuple's group */
10281028
entry = lookup_hash_entry(aggstate, outerslot);
@@ -1116,7 +1116,7 @@ agg_retrieve_hash_table(AggState *aggstate)
11161116
* Use the representative input tuple for any references to
11171117
* non-aggregated input columns in the qual and tlist.
11181118
*/
1119-
econtext->ecxt_scantuple = firstSlot;
1119+
econtext->ecxt_outertuple = firstSlot;
11201120

11211121
/*
11221122
* Check the qual (HAVING clause); if the group does not match, ignore

src/backend/executor/nodeGroup.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* locate group boundaries.
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/executor/nodeGroup.c,v 1.68 2007/02/02 00:07:03 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/executor/nodeGroup.c,v 1.69 2007/02/22 23:44:24 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -72,9 +72,14 @@ ExecGroup(GroupState *node)
7272
node->grp_done = TRUE;
7373
return NULL;
7474
}
75-
/* Copy tuple, set up as input for qual test and projection */
75+
/* Copy tuple into firsttupleslot */
7676
ExecCopySlot(firsttupleslot, outerslot);
77-
econtext->ecxt_scantuple = firsttupleslot;
77+
78+
/*
79+
* Set it up as input for qual test and projection. The expressions
80+
* will access the input tuple as varno OUTER.
81+
*/
82+
econtext->ecxt_outertuple = firsttupleslot;
7883

7984
/*
8085
* Check the qual (HAVING clause); if the group does not match, ignore
@@ -126,7 +131,7 @@ ExecGroup(GroupState *node)
126131
*/
127132
/* Copy tuple, set up as input for qual test and projection */
128133
ExecCopySlot(firsttupleslot, outerslot);
129-
econtext->ecxt_scantuple = firsttupleslot;
134+
econtext->ecxt_outertuple = firsttupleslot;
130135

131136
/*
132137
* Check the qual (HAVING clause); if the group does not match, ignore

src/backend/executor/nodeResult.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
4040
* IDENTIFICATION
41-
* $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.39 2007/02/16 03:49:04 tgl Exp $
41+
* $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.40 2007/02/22 23:44:25 tgl Exp $
4242
*
4343
*-------------------------------------------------------------------------
4444
*/
@@ -132,13 +132,11 @@ ExecResult(ResultState *node)
132132
if (TupIsNull(outerTupleSlot))
133133
return NULL;
134134

135-
node->ps.ps_OuterTupleSlot = outerTupleSlot;
136-
137135
/*
138-
* XXX gross hack. use outer tuple as scan tuple for projection
136+
* prepare to compute projection expressions, which will expect
137+
* to access the input tuples as varno OUTER.
139138
*/
140139
econtext->ecxt_outertuple = outerTupleSlot;
141-
econtext->ecxt_scantuple = outerTupleSlot;
142140
}
143141
else
144142
{

0 commit comments

Comments
 (0)