@ -1469,3 +1469,101 @@ explain (costs off) select * from t union select * from t order by 1,3;
(13 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
-- go above joins since otherwise we'll incorrectly use expression evaluations
-- across multiple rows.
set enable_hashagg=off;
set enable_seqscan=off;
set enable_incremental_sort = off;
set parallel_tuple_cost=0;
set parallel_setup_cost=0;
set min_parallel_table_scan_size = 0;
set min_parallel_index_scan_size = 0;
-- Parallel sort below join.
explain (costs off) select distinct sub.unique1, stringu1
from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub;
QUERY PLAN
--------------------------------------------------------------------------
Unique
-> Nested Loop
-> Gather Merge
Workers Planned: 2
-> Sort
Sort Key: tenk1.unique1, tenk1.stringu1
-> Parallel Index Scan using tenk1_unique1 on tenk1
-> Function Scan on generate_series
(8 rows)
explain (costs off) select sub.unique1, stringu1
from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub
order by 1, 2;
QUERY PLAN
--------------------------------------------------------------------
Nested Loop
-> Gather Merge
Workers Planned: 2
-> Sort
Sort Key: tenk1.unique1, tenk1.stringu1
-> Parallel Index Scan using tenk1_unique1 on tenk1
-> Function Scan on generate_series
(7 rows)
-- Parallel sort but with expression that can be safely generated at the base rel.
explain (costs off) select distinct sub.unique1, md5(stringu1)
from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub;
QUERY PLAN
----------------------------------------------------------------------------------------
Unique
-> Nested Loop
-> Gather Merge
Workers Planned: 2
-> Sort
Sort Key: tenk1.unique1, (md5((tenk1.stringu1)::text)) COLLATE "C"
-> Parallel Index Scan using tenk1_unique1 on tenk1
-> Function Scan on generate_series
(8 rows)
explain (costs off) select sub.unique1, md5(stringu1)
from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub
order by 1, 2;
QUERY PLAN
----------------------------------------------------------------------------------
Nested Loop
-> Gather Merge
Workers Planned: 2
-> Sort
Sort Key: tenk1.unique1, (md5((tenk1.stringu1)::text)) COLLATE "C"
-> Parallel Index Scan using tenk1_unique1 on tenk1
-> Function Scan on generate_series
(7 rows)
-- Parallel sort but with expression not available until the upper rel.
explain (costs off) select distinct sub.unique1, stringu1 || random()::text
from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub;
QUERY PLAN
---------------------------------------------------------------------------------------------
Unique
-> Sort
Sort Key: tenk1.unique1, (((tenk1.stringu1)::text || (random())::text)) COLLATE "C"
-> Gather
Workers Planned: 2
-> Nested Loop
-> Parallel Index Scan using tenk1_unique1 on tenk1
-> Function Scan on generate_series
(8 rows)
explain (costs off) select sub.unique1, stringu1 || random()::text
from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub
order by 1, 2;
QUERY PLAN
---------------------------------------------------------------------------------------
Sort
Sort Key: tenk1.unique1, (((tenk1.stringu1)::text || (random())::text)) COLLATE "C"
-> Gather
Workers Planned: 2
-> Nested Loop
-> Parallel Index Scan using tenk1_unique1 on tenk1
-> Function Scan on generate_series
(7 rows)