diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index ae0f9bdc8a..c4271c9179 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -1365,6 +1365,27 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, } } + if (rel->part_scheme != NULL && IS_SIMPLE_REL(rel) && + partitions_are_ordered(rel->boundinfo, rel->live_parts)) + { + List *partition_pathkeys; + bool partial; + + partition_pathkeys = build_partition_pathkeys(root, rel, + ForwardScanDirection, + &partial); + + if (!partial) + all_child_pathkeys = lappend(all_child_pathkeys, partition_pathkeys); + + partition_pathkeys = build_partition_pathkeys(root, rel, + BackwardScanDirection, + &partial); + + if (!partial) + all_child_pathkeys = lappend(all_child_pathkeys, partition_pathkeys); + } + /* * Collect lists of all the available path orderings and * parameterizations for all the children. We use these as a