@@ -95,7 +95,6 @@ create_upper_paths_hook_type create_upper_paths_hook = NULL;
95
95
/* Passthrough data for standard_qp_callback */
96
96
typedef struct
97
97
{
98
- List * tlist ; /* preprocessed query targetlist */
99
98
List * activeWindows ; /* active windows, if any */
100
99
List * groupClause ; /* overrides parse->groupClause */
101
100
} standard_qp_extra ;
@@ -182,15 +181,13 @@ static RelOptInfo *create_window_paths(PlannerInfo *root,
182
181
PathTarget * input_target ,
183
182
PathTarget * output_target ,
184
183
bool output_target_parallel_safe ,
185
- List * tlist ,
186
184
WindowFuncLists * wflists ,
187
185
List * activeWindows );
188
186
static void create_one_window_path (PlannerInfo * root ,
189
187
RelOptInfo * window_rel ,
190
188
Path * path ,
191
189
PathTarget * input_target ,
192
190
PathTarget * output_target ,
193
- List * tlist ,
194
191
WindowFuncLists * wflists ,
195
192
List * activeWindows );
196
193
static RelOptInfo * create_distinct_paths (PlannerInfo * root ,
@@ -1588,12 +1585,11 @@ inheritance_planner(PlannerInfo *root)
1588
1585
* cleaner if we fixed nodeModifyTable.c to support zero child nodes,
1589
1586
* but that probably wouldn't be a net win.)
1590
1587
*/
1591
- List * tlist ;
1592
1588
Path * dummy_path ;
1593
1589
1594
1590
/* 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 );
1597
1593
1598
1594
/* Make a dummy path, cf set_dummy_rel_pathlist() */
1599
1595
dummy_path = (Path * ) create_append_path (NULL , final_rel , NIL , NIL ,
@@ -1693,7 +1689,6 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1693
1689
double tuple_fraction )
1694
1690
{
1695
1691
Query * parse = root -> parse ;
1696
- List * tlist ;
1697
1692
int64 offset_est = 0 ;
1698
1693
int64 count_est = 0 ;
1699
1694
double limit_tuples = -1.0 ;
@@ -1746,20 +1741,17 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1746
1741
1747
1742
/*
1748
1743
* 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
1751
1746
* resjunk columns!), and transfer any sort key information from the
1752
1747
* original tlist.
1753
1748
*/
1754
1749
Assert (parse -> commandType == CMD_SELECT );
1755
1750
1756
- tlist = root -> processed_tlist ; /* from plan_set_operations */
1757
-
1758
1751
/* 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 );
1763
1755
1764
1756
/* Also extract the PathTarget form of the setop result tlist */
1765
1757
final_target = current_rel -> cheapest_total_path -> pathtarget ;
@@ -1791,7 +1783,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1791
1783
Assert (parse -> distinctClause == NIL );
1792
1784
root -> sort_pathkeys = make_pathkeys_for_sortclauses (root ,
1793
1785
parse -> sortClause ,
1794
- tlist );
1786
+ root -> processed_tlist );
1795
1787
}
1796
1788
else
1797
1789
{
@@ -1831,17 +1823,14 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1831
1823
parse -> groupClause = preprocess_groupclause (root , NIL );
1832
1824
}
1833
1825
1834
- /* Preprocess targetlist */
1835
- tlist = preprocess_targetlist (root );
1836
-
1837
1826
/*
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
1841
1830
* 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.
1843
1832
*/
1844
- root -> processed_tlist = tlist ;
1833
+ root -> processed_tlist = preprocess_targetlist ( root ) ;
1845
1834
1846
1835
/*
1847
1836
* Collect statistics about aggregates for estimating costs, and mark
@@ -1859,8 +1848,8 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1859
1848
MemSet (& agg_costs , 0 , sizeof (AggClauseCosts ));
1860
1849
if (parse -> hasAggs )
1861
1850
{
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 );
1864
1853
get_agg_clause_costs (root , parse -> havingQual , AGGSPLIT_SIMPLE ,
1865
1854
& agg_costs );
1866
1855
}
@@ -1873,7 +1862,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1873
1862
*/
1874
1863
if (parse -> hasWindowFuncs )
1875
1864
{
1876
- wflists = find_window_functions ((Node * ) tlist ,
1865
+ wflists = find_window_functions ((Node * ) root -> processed_tlist ,
1877
1866
list_length (parse -> windowClause ));
1878
1867
if (wflists -> numWindowFuncs > 0 )
1879
1868
activeWindows = select_active_windows (root , wflists );
@@ -1888,7 +1877,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1888
1877
* duplicated in planagg.c.
1889
1878
*/
1890
1879
if (parse -> hasAggs )
1891
- preprocess_minmax_aggregates (root , tlist );
1880
+ preprocess_minmax_aggregates (root );
1892
1881
1893
1882
/*
1894
1883
* 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,
1908
1897
root -> limit_tuples = limit_tuples ;
1909
1898
1910
1899
/* Set up data needed by standard_qp_callback */
1911
- qp_extra .tlist = tlist ;
1912
1900
qp_extra .activeWindows = activeWindows ;
1913
1901
qp_extra .groupClause = (gset_data
1914
1902
? (gset_data -> rollups ? linitial_node (RollupData , gset_data -> rollups )-> groupClause : NIL )
@@ -1921,17 +1909,18 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
1921
1909
* We also generate (in standard_qp_callback) pathkey representations
1922
1910
* of the query's sort clause, distinct clause, etc.
1923
1911
*/
1924
- current_rel = query_planner (root , tlist ,
1925
- standard_qp_callback , & qp_extra );
1912
+ current_rel = query_planner (root , standard_qp_callback , & qp_extra );
1926
1913
1927
1914
/*
1928
1915
* Convert the query's result tlist into PathTarget format.
1929
1916
*
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
1931
1920
* because the target width estimates can use per-Var width numbers
1932
1921
* that were obtained within query_planner().
1933
1922
*/
1934
- final_target = create_pathtarget (root , tlist );
1923
+ final_target = create_pathtarget (root , root -> processed_tlist );
1935
1924
final_target_parallel_safe =
1936
1925
is_parallel_safe (root , (Node * ) final_target -> exprs );
1937
1926
@@ -2087,7 +2076,6 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
2087
2076
grouping_target ,
2088
2077
sort_input_target ,
2089
2078
sort_input_target_parallel_safe ,
2090
- tlist ,
2091
2079
wflists ,
2092
2080
activeWindows );
2093
2081
/* Fix things up if sort_input_target contains SRFs */
@@ -3455,7 +3443,7 @@ standard_qp_callback(PlannerInfo *root, void *extra)
3455
3443
{
3456
3444
Query * parse = root -> parse ;
3457
3445
standard_qp_extra * qp_extra = (standard_qp_extra * ) extra ;
3458
- List * tlist = qp_extra -> tlist ;
3446
+ List * tlist = root -> processed_tlist ;
3459
3447
List * activeWindows = qp_extra -> activeWindows ;
3460
3448
3461
3449
/*
@@ -4401,7 +4389,6 @@ consider_groupingsets_paths(PlannerInfo *root,
4401
4389
* input_rel: contains the source-data Paths
4402
4390
* input_target: result of make_window_input_target
4403
4391
* output_target: what the topmost WindowAggPath should return
4404
- * tlist: query's target list (needed to look up pathkeys)
4405
4392
* wflists: result of find_window_functions
4406
4393
* activeWindows: result of select_active_windows
4407
4394
*
@@ -4413,7 +4400,6 @@ create_window_paths(PlannerInfo *root,
4413
4400
PathTarget * input_target ,
4414
4401
PathTarget * output_target ,
4415
4402
bool output_target_parallel_safe ,
4416
- List * tlist ,
4417
4403
WindowFuncLists * wflists ,
4418
4404
List * activeWindows )
4419
4405
{
@@ -4456,7 +4442,6 @@ create_window_paths(PlannerInfo *root,
4456
4442
path ,
4457
4443
input_target ,
4458
4444
output_target ,
4459
- tlist ,
4460
4445
wflists ,
4461
4446
activeWindows );
4462
4447
}
@@ -4490,7 +4475,6 @@ create_window_paths(PlannerInfo *root,
4490
4475
* path: input Path to use (must return input_target)
4491
4476
* input_target: result of make_window_input_target
4492
4477
* output_target: what the topmost WindowAggPath should return
4493
- * tlist: query's target list (needed to look up pathkeys)
4494
4478
* wflists: result of find_window_functions
4495
4479
* activeWindows: result of select_active_windows
4496
4480
*/
@@ -4500,7 +4484,6 @@ create_one_window_path(PlannerInfo *root,
4500
4484
Path * path ,
4501
4485
PathTarget * input_target ,
4502
4486
PathTarget * output_target ,
4503
- List * tlist ,
4504
4487
WindowFuncLists * wflists ,
4505
4488
List * activeWindows )
4506
4489
{
@@ -4531,7 +4514,7 @@ create_one_window_path(PlannerInfo *root,
4531
4514
4532
4515
window_pathkeys = make_pathkeys_for_window (root ,
4533
4516
wc ,
4534
- tlist );
4517
+ root -> processed_tlist );
4535
4518
4536
4519
/* Sort if necessary */
4537
4520
if (!pathkeys_contained_in (window_pathkeys , path -> pathkeys ))
0 commit comments