@@ -95,7 +95,6 @@ create_upper_paths_hook_type create_upper_paths_hook = NULL;
9595/* Passthrough data for standard_qp_callback */
9696typedef struct
9797{
98- List * tlist ; /* preprocessed query targetlist */
9998 List * activeWindows ; /* active windows, if any */
10099 List * groupClause ; /* overrides parse->groupClause */
101100} standard_qp_extra ;
@@ -182,15 +181,13 @@ static RelOptInfo *create_window_paths(PlannerInfo *root,
182181 PathTarget * input_target ,
183182 PathTarget * output_target ,
184183 bool output_target_parallel_safe ,
185- List * tlist ,
186184 WindowFuncLists * wflists ,
187185 List * activeWindows );
188186static void create_one_window_path (PlannerInfo * root ,
189187 RelOptInfo * window_rel ,
190188 Path * path ,
191189 PathTarget * input_target ,
192190 PathTarget * output_target ,
193- List * tlist ,
194191 WindowFuncLists * wflists ,
195192 List * activeWindows );
196193static RelOptInfo * create_distinct_paths (PlannerInfo * root ,
@@ -1588,12 +1585,11 @@ inheritance_planner(PlannerInfo *root)
15881585 * cleaner if we fixed nodeModifyTable.c to support zero child nodes,
15891586 * but that probably wouldn't be a net win.)
15901587 */
1591- List * tlist ;
15921588 Path * dummy_path ;
15931589
15941590 /* tlist processing never got done, either */
1595- tlist = root -> processed_tlist = preprocess_targetlist (root );
1596- final_rel -> reltarget = create_pathtarget (root , tlist );
1591+ root -> processed_tlist = preprocess_targetlist (root );
1592+ final_rel -> reltarget = create_pathtarget (root , root -> processed_tlist );
15971593
15981594 /* Make a dummy path, cf set_dummy_rel_pathlist() */
15991595 dummy_path = (Path * ) create_append_path (NULL , final_rel , NIL , NIL ,
@@ -1693,7 +1689,6 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
16931689 double tuple_fraction )
16941690{
16951691 Query * parse = root -> parse ;
1696- List * tlist ;
16971692 int64 offset_est = 0 ;
16981693 int64 count_est = 0 ;
16991694 double limit_tuples = -1.0 ;
@@ -1746,20 +1741,17 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
17461741
17471742 /*
17481743 * We should not need to call preprocess_targetlist, since we must be
1749- * in a SELECT query node. Instead, use the targetlist returned by
1750- * plan_set_operations (since this tells whether it returned any
1744+ * in a SELECT query node. Instead, use the processed_tlist returned
1745+ * by plan_set_operations (since this tells whether it returned any
17511746 * resjunk columns!), and transfer any sort key information from the
17521747 * original tlist.
17531748 */
17541749 Assert (parse -> commandType == CMD_SELECT );
17551750
1756- tlist = root -> processed_tlist ; /* from plan_set_operations */
1757-
17581751 /* for safety, copy processed_tlist instead of modifying in-place */
1759- tlist = postprocess_setop_tlist (copyObject (tlist ), parse -> targetList );
1760-
1761- /* Save aside the final decorated tlist */
1762- root -> processed_tlist = tlist ;
1752+ root -> processed_tlist =
1753+ postprocess_setop_tlist (copyObject (root -> processed_tlist ),
1754+ parse -> targetList );
17631755
17641756 /* Also extract the PathTarget form of the setop result tlist */
17651757 final_target = current_rel -> cheapest_total_path -> pathtarget ;
@@ -1791,7 +1783,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
17911783 Assert (parse -> distinctClause == NIL );
17921784 root -> sort_pathkeys = make_pathkeys_for_sortclauses (root ,
17931785 parse -> sortClause ,
1794- tlist );
1786+ root -> processed_tlist );
17951787 }
17961788 else
17971789 {
@@ -1831,17 +1823,14 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
18311823 parse -> groupClause = preprocess_groupclause (root , NIL );
18321824 }
18331825
1834- /* Preprocess targetlist */
1835- tlist = preprocess_targetlist (root );
1836-
18371826 /*
1838- * We are now done hacking up the query's targetlist. Most of the
1839- * remaining planning work will be done with the PathTarget
1840- * representation of tlists, but save aside the full representation so
1827+ * Preprocess targetlist. Note that much of the remaining planning
1828+ * work will be done with the PathTarget representation of tlists, but
1829+ * we must also maintain the full representation of the final tlist so
18411830 * that we can transfer its decoration (resnames etc) to the topmost
1842- * tlist of the finished Plan.
1831+ * tlist of the finished Plan. This is kept in processed_tlist.
18431832 */
1844- root -> processed_tlist = tlist ;
1833+ root -> processed_tlist = preprocess_targetlist ( root ) ;
18451834
18461835 /*
18471836 * Collect statistics about aggregates for estimating costs, and mark
@@ -1859,8 +1848,8 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
18591848 MemSet (& agg_costs , 0 , sizeof (AggClauseCosts ));
18601849 if (parse -> hasAggs )
18611850 {
1862- get_agg_clause_costs (root , (Node * ) tlist , AGGSPLIT_SIMPLE ,
1863- & agg_costs );
1851+ get_agg_clause_costs (root , (Node * ) root -> processed_tlist ,
1852+ AGGSPLIT_SIMPLE , & agg_costs );
18641853 get_agg_clause_costs (root , parse -> havingQual , AGGSPLIT_SIMPLE ,
18651854 & agg_costs );
18661855 }
@@ -1873,7 +1862,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
18731862 */
18741863 if (parse -> hasWindowFuncs )
18751864 {
1876- wflists = find_window_functions ((Node * ) tlist ,
1865+ wflists = find_window_functions ((Node * ) root -> processed_tlist ,
18771866 list_length (parse -> windowClause ));
18781867 if (wflists -> numWindowFuncs > 0 )
18791868 activeWindows = select_active_windows (root , wflists );
@@ -1888,7 +1877,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
18881877 * duplicated in planagg.c.
18891878 */
18901879 if (parse -> hasAggs )
1891- preprocess_minmax_aggregates (root , tlist );
1880+ preprocess_minmax_aggregates (root );
18921881
18931882 /*
18941883 * Figure out whether there's a hard limit on the number of rows that
@@ -1908,7 +1897,6 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
19081897 root -> limit_tuples = limit_tuples ;
19091898
19101899 /* Set up data needed by standard_qp_callback */
1911- qp_extra .tlist = tlist ;
19121900 qp_extra .activeWindows = activeWindows ;
19131901 qp_extra .groupClause = (gset_data
19141902 ? (gset_data -> rollups ? linitial_node (RollupData , gset_data -> rollups )-> groupClause : NIL )
@@ -1921,17 +1909,18 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
19211909 * We also generate (in standard_qp_callback) pathkey representations
19221910 * of the query's sort clause, distinct clause, etc.
19231911 */
1924- current_rel = query_planner (root , tlist ,
1925- standard_qp_callback , & qp_extra );
1912+ current_rel = query_planner (root , standard_qp_callback , & qp_extra );
19261913
19271914 /*
19281915 * Convert the query's result tlist into PathTarget format.
19291916 *
1930- * Note: it's desirable to not do this till after query_planner(),
1917+ * Note: this cannot be done before query_planner() has performed
1918+ * appendrel expansion, because that might add resjunk entries to
1919+ * root->processed_tlist. Waiting till afterwards is also helpful
19311920 * because the target width estimates can use per-Var width numbers
19321921 * that were obtained within query_planner().
19331922 */
1934- final_target = create_pathtarget (root , tlist );
1923+ final_target = create_pathtarget (root , root -> processed_tlist );
19351924 final_target_parallel_safe =
19361925 is_parallel_safe (root , (Node * ) final_target -> exprs );
19371926
@@ -2087,7 +2076,6 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
20872076 grouping_target ,
20882077 sort_input_target ,
20892078 sort_input_target_parallel_safe ,
2090- tlist ,
20912079 wflists ,
20922080 activeWindows );
20932081 /* Fix things up if sort_input_target contains SRFs */
@@ -3455,7 +3443,7 @@ standard_qp_callback(PlannerInfo *root, void *extra)
34553443{
34563444 Query * parse = root -> parse ;
34573445 standard_qp_extra * qp_extra = (standard_qp_extra * ) extra ;
3458- List * tlist = qp_extra -> tlist ;
3446+ List * tlist = root -> processed_tlist ;
34593447 List * activeWindows = qp_extra -> activeWindows ;
34603448
34613449 /*
@@ -4401,7 +4389,6 @@ consider_groupingsets_paths(PlannerInfo *root,
44014389 * input_rel: contains the source-data Paths
44024390 * input_target: result of make_window_input_target
44034391 * output_target: what the topmost WindowAggPath should return
4404- * tlist: query's target list (needed to look up pathkeys)
44054392 * wflists: result of find_window_functions
44064393 * activeWindows: result of select_active_windows
44074394 *
@@ -4413,7 +4400,6 @@ create_window_paths(PlannerInfo *root,
44134400 PathTarget * input_target ,
44144401 PathTarget * output_target ,
44154402 bool output_target_parallel_safe ,
4416- List * tlist ,
44174403 WindowFuncLists * wflists ,
44184404 List * activeWindows )
44194405{
@@ -4456,7 +4442,6 @@ create_window_paths(PlannerInfo *root,
44564442 path ,
44574443 input_target ,
44584444 output_target ,
4459- tlist ,
44604445 wflists ,
44614446 activeWindows );
44624447 }
@@ -4490,7 +4475,6 @@ create_window_paths(PlannerInfo *root,
44904475 * path: input Path to use (must return input_target)
44914476 * input_target: result of make_window_input_target
44924477 * output_target: what the topmost WindowAggPath should return
4493- * tlist: query's target list (needed to look up pathkeys)
44944478 * wflists: result of find_window_functions
44954479 * activeWindows: result of select_active_windows
44964480 */
@@ -4500,7 +4484,6 @@ create_one_window_path(PlannerInfo *root,
45004484 Path * path ,
45014485 PathTarget * input_target ,
45024486 PathTarget * output_target ,
4503- List * tlist ,
45044487 WindowFuncLists * wflists ,
45054488 List * activeWindows )
45064489{
@@ -4531,7 +4514,7 @@ create_one_window_path(PlannerInfo *root,
45314514
45324515 window_pathkeys = make_pathkeys_for_window (root ,
45334516 wc ,
4534- tlist );
4517+ root -> processed_tlist );
45354518
45364519 /* Sort if necessary */
45374520 if (!pathkeys_contained_in (window_pathkeys , path -> pathkeys ))
0 commit comments