@@ -99,18 +99,13 @@ static void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
9999 Index rti , RangeTblEntry * rte );
100100static void generate_orderedappend_paths (PlannerInfo * root , RelOptInfo * rel ,
101101 List * live_childrels ,
102- List * all_child_pathkeys ,
103- List * partitioned_rels );
102+ List * all_child_pathkeys );
104103static Path * get_cheapest_parameterized_child_path (PlannerInfo * root ,
105104 RelOptInfo * rel ,
106105 Relids required_outer );
107- static List * accumulate_partitioned_rels (List * partitioned_rels ,
108- List * sub_partitioned_rels ,
109- bool flatten_partitioned_rels );
110106static void accumulate_append_subpath (Path * path ,
111- List * * subpaths , List * * special_subpaths ,
112- List * * partitioned_rels ,
113- bool flatten_partitioned_rels );
107+ List * * subpaths ,
108+ List * * special_subpaths );
114109static Path * get_singleton_append_subpath (Path * path );
115110static void set_dummy_rel_pathlist (RelOptInfo * rel );
116111static void set_subquery_pathlist (PlannerInfo * root , RelOptInfo * rel ,
@@ -1299,38 +1294,11 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
12991294 List * all_child_pathkeys = NIL ;
13001295 List * all_child_outers = NIL ;
13011296 ListCell * l ;
1302- List * partitioned_rels = NIL ;
1303- List * partial_partitioned_rels = NIL ;
1304- List * pa_partitioned_rels = NIL ;
13051297 double partial_rows = -1 ;
1306- bool flatten_partitioned_rels ;
13071298
13081299 /* If appropriate, consider parallel append */
13091300 pa_subpaths_valid = enable_parallel_append && rel -> consider_parallel ;
13101301
1311- /* What we do with the partitioned_rels list is different for UNION ALL */
1312- flatten_partitioned_rels = (rel -> rtekind != RTE_SUBQUERY );
1313-
1314- /*
1315- * For partitioned tables, we accumulate a list of Relids of each
1316- * partitioned table which has at least one of its subpartitions directly
1317- * present as a subpath in this Append. This is used later for run-time
1318- * partition pruning. We must maintain separate lists for each Append
1319- * Path that we create as some paths that we create here can't flatten
1320- * sub-Appends and sub-MergeAppends into the top-level Append. We needn't
1321- * bother doing this for join rels as no run-time pruning is done on
1322- * those.
1323- */
1324- if (rel -> reloptkind != RELOPT_JOINREL && rel -> part_scheme != NULL )
1325- {
1326- partitioned_rels = list_make1 (bms_make_singleton (rel -> relid ));
1327- partial_partitioned_rels = list_make1 (bms_make_singleton (rel -> relid ));
1328-
1329- /* skip this one if we're not going to make a Parallel Append path */
1330- if (pa_subpaths_valid )
1331- pa_partitioned_rels = list_make1 (bms_make_singleton (rel -> relid ));
1332- }
1333-
13341302 /*
13351303 * For every non-dummy child, remember the cheapest path. Also, identify
13361304 * all pathkeys (orderings) and parameterizations (required_outer sets)
@@ -1353,8 +1321,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
13531321 if (childrel -> pathlist != NIL &&
13541322 childrel -> cheapest_total_path -> param_info == NULL )
13551323 accumulate_append_subpath (childrel -> cheapest_total_path ,
1356- & subpaths , NULL , & partitioned_rels ,
1357- flatten_partitioned_rels );
1324+ & subpaths , NULL );
13581325 else
13591326 subpaths_valid = false;
13601327
@@ -1363,9 +1330,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
13631330 {
13641331 cheapest_partial_path = linitial (childrel -> partial_pathlist );
13651332 accumulate_append_subpath (cheapest_partial_path ,
1366- & partial_subpaths , NULL ,
1367- & partial_partitioned_rels ,
1368- flatten_partitioned_rels );
1333+ & partial_subpaths , NULL );
13691334 }
13701335 else
13711336 partial_subpaths_valid = false;
@@ -1394,10 +1359,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
13941359 Assert (cheapest_partial_path != NULL );
13951360 accumulate_append_subpath (cheapest_partial_path ,
13961361 & pa_partial_subpaths ,
1397- & pa_nonpartial_subpaths ,
1398- & pa_partitioned_rels ,
1399- flatten_partitioned_rels );
1400-
1362+ & pa_nonpartial_subpaths );
14011363 }
14021364 else
14031365 {
@@ -1416,9 +1378,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
14161378 */
14171379 accumulate_append_subpath (nppath ,
14181380 & pa_nonpartial_subpaths ,
1419- NULL ,
1420- & pa_partitioned_rels ,
1421- flatten_partitioned_rels );
1381+ NULL );
14221382 }
14231383 }
14241384
@@ -1495,7 +1455,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
14951455 if (subpaths_valid )
14961456 add_path (rel , (Path * ) create_append_path (root , rel , subpaths , NIL ,
14971457 NIL , NULL , 0 , false,
1498- partitioned_rels , -1 ));
1458+ -1 ));
14991459
15001460 /*
15011461 * Consider an append of unordered, unparameterized partial paths. Make
@@ -1538,7 +1498,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
15381498 appendpath = create_append_path (root , rel , NIL , partial_subpaths ,
15391499 NIL , NULL , parallel_workers ,
15401500 enable_parallel_append ,
1541- partial_partitioned_rels , -1 );
1501+ -1 );
15421502
15431503 /*
15441504 * Make sure any subsequent partial paths use the same row count
@@ -1587,7 +1547,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
15871547 appendpath = create_append_path (root , rel , pa_nonpartial_subpaths ,
15881548 pa_partial_subpaths ,
15891549 NIL , NULL , parallel_workers , true,
1590- pa_partitioned_rels , partial_rows );
1550+ partial_rows );
15911551 add_partial_path (rel , (Path * ) appendpath );
15921552 }
15931553
@@ -1597,8 +1557,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
15971557 */
15981558 if (subpaths_valid )
15991559 generate_orderedappend_paths (root , rel , live_childrels ,
1600- all_child_pathkeys ,
1601- partitioned_rels );
1560+ all_child_pathkeys );
16021561
16031562 /*
16041563 * Build Append paths for each parameterization seen among the child rels.
@@ -1617,10 +1576,6 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
16171576 {
16181577 Relids required_outer = (Relids ) lfirst (l );
16191578 ListCell * lcr ;
1620- List * part_rels = NIL ;
1621-
1622- if (rel -> reloptkind != RELOPT_JOINREL && rel -> part_scheme != NULL )
1623- part_rels = list_make1 (bms_make_singleton (rel -> relid ));
16241579
16251580 /* Select the child paths for an Append with this parameterization */
16261581 subpaths = NIL ;
@@ -1646,15 +1601,14 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
16461601 subpaths_valid = false;
16471602 break ;
16481603 }
1649- accumulate_append_subpath (subpath , & subpaths , NULL , & part_rels ,
1650- flatten_partitioned_rels );
1604+ accumulate_append_subpath (subpath , & subpaths , NULL );
16511605 }
16521606
16531607 if (subpaths_valid )
16541608 add_path (rel , (Path * )
16551609 create_append_path (root , rel , subpaths , NIL ,
16561610 NIL , required_outer , 0 , false,
1657- part_rels , -1 ));
1611+ -1 ));
16581612 }
16591613
16601614 /*
@@ -1681,7 +1635,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
16811635 appendpath = create_append_path (root , rel , NIL , list_make1 (path ),
16821636 NIL , NULL ,
16831637 path -> parallel_workers , true,
1684- partitioned_rels , partial_rows );
1638+ partial_rows );
16851639 add_partial_path (rel , (Path * ) appendpath );
16861640 }
16871641 }
@@ -1717,26 +1671,13 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
17171671static void
17181672generate_orderedappend_paths (PlannerInfo * root , RelOptInfo * rel ,
17191673 List * live_childrels ,
1720- List * all_child_pathkeys ,
1721- List * partitioned_rels )
1674+ List * all_child_pathkeys )
17221675{
17231676 ListCell * lcp ;
17241677 List * partition_pathkeys = NIL ;
17251678 List * partition_pathkeys_desc = NIL ;
17261679 bool partition_pathkeys_partial = true;
17271680 bool partition_pathkeys_desc_partial = true;
1728- List * startup_partitioned_rels = NIL ;
1729- List * total_partitioned_rels = NIL ;
1730- bool flatten_partitioned_rels ;
1731-
1732- /* Set up the method for building the partitioned rels lists */
1733- flatten_partitioned_rels = (rel -> rtekind != RTE_SUBQUERY );
1734-
1735- if (rel -> reloptkind != RELOPT_JOINREL && rel -> part_scheme != NULL )
1736- {
1737- startup_partitioned_rels = list_make1 (bms_make_singleton (rel -> relid ));
1738- total_partitioned_rels = list_make1 (bms_make_singleton (rel -> relid ));
1739- }
17401681
17411682 /*
17421683 * Some partitioned table setups may allow us to use an Append node
@@ -1878,13 +1819,9 @@ generate_orderedappend_paths(PlannerInfo *root, RelOptInfo *rel,
18781819 * child paths for the MergeAppend.
18791820 */
18801821 accumulate_append_subpath (cheapest_startup ,
1881- & startup_subpaths , NULL ,
1882- & startup_partitioned_rels ,
1883- flatten_partitioned_rels );
1822+ & startup_subpaths , NULL );
18841823 accumulate_append_subpath (cheapest_total ,
1885- & total_subpaths , NULL ,
1886- & total_partitioned_rels ,
1887- flatten_partitioned_rels );
1824+ & total_subpaths , NULL );
18881825 }
18891826 }
18901827
@@ -1900,7 +1837,6 @@ generate_orderedappend_paths(PlannerInfo *root, RelOptInfo *rel,
19001837 NULL ,
19011838 0 ,
19021839 false,
1903- startup_partitioned_rels ,
19041840 -1 ));
19051841 if (startup_neq_total )
19061842 add_path (rel , (Path * ) create_append_path (root ,
@@ -1911,7 +1847,6 @@ generate_orderedappend_paths(PlannerInfo *root, RelOptInfo *rel,
19111847 NULL ,
19121848 0 ,
19131849 false,
1914- total_partitioned_rels ,
19151850 -1 ));
19161851 }
19171852 else
@@ -1921,15 +1856,13 @@ generate_orderedappend_paths(PlannerInfo *root, RelOptInfo *rel,
19211856 rel ,
19221857 startup_subpaths ,
19231858 pathkeys ,
1924- NULL ,
1925- startup_partitioned_rels ));
1859+ NULL ));
19261860 if (startup_neq_total )
19271861 add_path (rel , (Path * ) create_merge_append_path (root ,
19281862 rel ,
19291863 total_subpaths ,
19301864 pathkeys ,
1931- NULL ,
1932- total_partitioned_rels ));
1865+ NULL ));
19331866 }
19341867 }
19351868}
@@ -2008,54 +1941,6 @@ get_cheapest_parameterized_child_path(PlannerInfo *root, RelOptInfo *rel,
20081941 return cheapest ;
20091942}
20101943
2011- /*
2012- * accumulate_partitioned_rels
2013- * Record 'sub_partitioned_rels' in the 'partitioned_rels' list,
2014- * flattening as appropriate.
2015- */
2016- static List *
2017- accumulate_partitioned_rels (List * partitioned_rels ,
2018- List * sub_partitioned_rels ,
2019- bool flatten )
2020- {
2021- if (flatten )
2022- {
2023- /*
2024- * We're only called with flatten == true when the partitioned_rels
2025- * list has at most 1 element. So we can just add the members from
2026- * sub list's first element onto the first element of
2027- * partitioned_rels. Only later in planning when doing UNION ALL
2028- * Append processing will we see flatten == false. partitioned_rels
2029- * may end up with more than 1 element then, but we never expect to be
2030- * called with flatten == true again after that, so we needn't bother
2031- * doing anything here for anything but the initial element.
2032- */
2033- if (partitioned_rels != NIL && sub_partitioned_rels != NIL )
2034- {
2035- Relids partrels = (Relids ) linitial (partitioned_rels );
2036- Relids subpartrels = (Relids ) linitial (sub_partitioned_rels );
2037-
2038- /* Ensure the above comment holds true */
2039- Assert (list_length (partitioned_rels ) == 1 );
2040- Assert (list_length (sub_partitioned_rels ) == 1 );
2041-
2042- linitial (partitioned_rels ) = bms_add_members (partrels , subpartrels );
2043- }
2044- }
2045- else
2046- {
2047- /*
2048- * Handle UNION ALL to partitioned tables. This always occurs after
2049- * we've done the accumulation for sub-partitioned tables, so there's
2050- * no need to consider how adding multiple elements to the top level
2051- * list affects the flatten == true case above.
2052- */
2053- partitioned_rels = list_concat (partitioned_rels , sub_partitioned_rels );
2054- }
2055-
2056- return partitioned_rels ;
2057- }
2058-
20591944/*
20601945 * accumulate_append_subpath
20611946 * Add a subpath to the list being built for an Append or MergeAppend.
@@ -2076,24 +1961,9 @@ accumulate_partitioned_rels(List *partitioned_rels,
20761961 * children to subpaths and the rest to special_subpaths. If the latter is
20771962 * NULL, we don't flatten the path at all (unless it contains only partial
20781963 * paths).
2079- *
2080- * When pulling up sub-Appends and sub-Merge Appends, we also gather the
2081- * path's list of partitioned tables and store in 'partitioned_rels'. The
2082- * exact behavior here depends on the value of 'flatten_partitioned_rels'.
2083- *
2084- * When 'flatten_partitioned_rels' is true, 'partitioned_rels' will contain at
2085- * most one element which is a Relids of the partitioned relations which there
2086- * are subpaths for. In this case, we just add the RT indexes for the
2087- * partitioned tables for the subpath we're pulling up to the single entry in
2088- * 'partitioned_rels'. When 'flatten_partitioned_rels' is false we
2089- * concatenate the path's partitioned rel list onto the top-level list. This
2090- * done for UNION ALLs which could have a partitioned table in each union
2091- * branch.
20921964 */
20931965static void
2094- accumulate_append_subpath (Path * path , List * * subpaths , List * * special_subpaths ,
2095- List * * partitioned_rels ,
2096- bool flatten_partitioned_rels )
1966+ accumulate_append_subpath (Path * path , List * * subpaths , List * * special_subpaths )
20971967{
20981968 if (IsA (path , AppendPath ))
20991969 {
@@ -2102,9 +1972,6 @@ accumulate_append_subpath(Path *path, List **subpaths, List **special_subpaths,
21021972 if (!apath -> path .parallel_aware || apath -> first_partial_path == 0 )
21031973 {
21041974 * subpaths = list_concat (* subpaths , apath -> subpaths );
2105- * partitioned_rels = accumulate_partitioned_rels (* partitioned_rels ,
2106- apath -> partitioned_rels ,
2107- flatten_partitioned_rels );
21081975 return ;
21091976 }
21101977 else if (special_subpaths != NULL )
@@ -2120,9 +1987,6 @@ accumulate_append_subpath(Path *path, List **subpaths, List **special_subpaths,
21201987 apath -> first_partial_path );
21211988 * special_subpaths = list_concat (* special_subpaths ,
21221989 new_special_subpaths );
2123- * partitioned_rels = accumulate_partitioned_rels (* partitioned_rels ,
2124- apath -> partitioned_rels ,
2125- flatten_partitioned_rels );
21261990 return ;
21271991 }
21281992 }
@@ -2131,9 +1995,6 @@ accumulate_append_subpath(Path *path, List **subpaths, List **special_subpaths,
21311995 MergeAppendPath * mpath = (MergeAppendPath * ) path ;
21321996
21331997 * subpaths = list_concat (* subpaths , mpath -> subpaths );
2134- * partitioned_rels = accumulate_partitioned_rels (* partitioned_rels ,
2135- mpath -> partitioned_rels ,
2136- flatten_partitioned_rels );
21371998 return ;
21381999 }
21392000
@@ -2195,7 +2056,7 @@ set_dummy_rel_pathlist(RelOptInfo *rel)
21952056 /* Set up the dummy path */
21962057 add_path (rel , (Path * ) create_append_path (NULL , rel , NIL , NIL ,
21972058 NIL , rel -> lateral_relids ,
2198- 0 , false, NIL , -1 ));
2059+ 0 , false, -1 ));
21992060
22002061 /*
22012062 * We set the cheapest-path fields immediately, just in case they were
0 commit comments