cheapest_partial_path = linitial(rel->partial_pathlist);
/*
- * Consider incremental sort paths for each interesting ordering.
+ * Consider sorted paths for each interesting ordering. We generate both
+ * incremental and full sort.
*/
foreach(lc, useful_pathkeys_list)
{
Path *subpath = (Path *) lfirst(lc2);
GatherMergePath *path;
- /*
- * If the path has no ordering at all, then we can't use either
- * incremental sort or rely on implicit sorting with a gather
- * merge.
- */
- if (subpath->pathkeys == NIL)
- continue;
-
is_sorted = pathkeys_count_contained_in(useful_pathkeys,
subpath->pathkeys,
&presorted_keys);
-> Parallel Seq Scan on t t_1
(13 rows)
+-- Full sort, not just incremental sort can be pushed below a gather merge path
+-- by generate_useful_gather_paths.
+explain (costs off) select distinct a,b from t;
+ QUERY PLAN
+------------------------------------------
+ Unique
+ -> Gather Merge
+ Workers Planned: 2
+ -> Sort
+ Sort Key: a, b
+ -> Parallel Seq Scan on t
+(6 rows)
+
drop table t;
-- Sort pushdown can't go below where expressions are part of the rel target.
-- In particular this is interesting for volatile expressions which have to
set enable_hashagg to off;
explain (costs off) select * from t union select * from t order by 1,3;
+-- Full sort, not just incremental sort can be pushed below a gather merge path
+-- by generate_useful_gather_paths.
+explain (costs off) select distinct a,b from t;
+
drop table t;
-- Sort pushdown can't go below where expressions are part of the rel target.