Skip to content

Commit 7e30f9d

Browse files
tglsfdcreshke
authored andcommitted
Add proper regression test for the recent SRFs-in-pathkeys problem.
Remove the test case added by commit fac1b47, which never actually worked to expose the problem it claimed to test. Replace it with a case that does expose the problem, and also covers the SRF-not- at-the-top deficiency repaired in 1aa8dad. Richard Guo, with some editorialization by me Discussion: https://postgr.es/m/17564-c7472c2f90ef2da3@postgresql.org
1 parent 029421f commit 7e30f9d

5 files changed

Lines changed: 33 additions & 28 deletions

File tree

src/test/regress/expected/incremental_sort.out

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,15 +1804,3 @@ order by 1, 2;
18041804
-> Function Scan on generate_series
18051805
(7 rows)
18061806

1807-
-- Disallow pushing down sort when pathkey is an SRF.
1808-
explain (costs off) select unique1 from tenk1 order by unnest('{1,2}'::int[]);
1809-
QUERY PLAN
1810-
-------------------------------------------------------------------------
1811-
Gather Motion 3:1 (slice1; segments: 3)
1812-
Merge Key: (unnest('{1,2}'::anyarray))
1813-
-> Sort
1814-
Sort Key: (unnest('{1,2}'::anyarray))
1815-
-> ProjectSet
1816-
-> Index Only Scan using tenk1_unique1 on tenk1
1817-
(6 rows)
1818-

src/test/regress/expected/incremental_sort_optimizer.out

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,17 +1658,3 @@ order by 1, 2;
16581658
Optimizer: Postgres query optimizer
16591659
(8 rows)
16601660

1661-
-- Disallow pushing down sort when pathkey is an SRF.
1662-
explain (costs off) select unique1 from tenk1 order by unnest('{1,2}'::int[]);
1663-
QUERY PLAN
1664-
-----------------------------------------------------
1665-
Result
1666-
-> Gather Motion 3:1 (slice1; segments: 3)
1667-
Merge Key: (unnest('{1,2}'::anyarray))
1668-
-> Sort
1669-
Sort Key: (unnest('{1,2}'::anyarray))
1670-
-> ProjectSet
1671-
-> Seq Scan on tenk1
1672-
Optimizer: Pivotal Optimizer (GPORCA)
1673-
(8 rows)
1674-

src/test/regress/expected/select_parallel.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,33 @@ SELECT generate_series(1, two), array(select generate_series(1, two))
12171217
Optimizer: Postgres query optimizer
12181218
(18 rows)
12191219

1220+
-- must disallow pushing sort below gather when pathkey contains an SRF
1221+
EXPLAIN (VERBOSE, COSTS OFF)
1222+
SELECT unnest(ARRAY[]::integer[]) + 1 AS pathkey
1223+
FROM tenk1 t1 JOIN tenk1 t2 ON TRUE
1224+
ORDER BY pathkey;
1225+
QUERY PLAN
1226+
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1227+
Gather Motion 6:1 (slice1; segments: 6)
1228+
Output: (((unnest('{}'::integer[])) + 1))
1229+
Merge Key: (((unnest('{}'::integer[])) + 1))
1230+
-> Sort
1231+
Output: (((unnest('{}'::integer[])) + 1))
1232+
Sort Key: (((unnest('{}'::integer[])) + 1))
1233+
-> Result
1234+
Output: ((unnest('{}'::integer[])) + 1)
1235+
-> ProjectSet
1236+
Output: unnest('{}'::integer[])
1237+
-> Nested Loop
1238+
-> Parallel Seq Scan on public.tenk1 t1
1239+
Output: t1.unique1, t1.unique2, t1.two, t1.four, t1.ten, t1.twenty, t1.hundred, t1.thousand, t1.twothousand, t1.fivethous, t1.tenthous, t1.odd, t1.even, t1.stringu1, t1.stringu2, t1.string4
1240+
-> Materialize
1241+
-> Broadcast Motion 3:6 (slice2; segments: 3)
1242+
-> Seq Scan on public.tenk1 t2
1243+
Settings: enable_parallel = 'on', min_parallel_table_scan_size = '0', optimizer = 'off', parallel_setup_cost = '0', parallel_tuple_cost = '0'
1244+
Optimizer: Postgres query optimizer
1245+
(18 rows)
1246+
12201247
-- test passing expanded-value representations to workers
12211248
CREATE FUNCTION make_some_array(int,int) returns int[] as
12221249
$$declare x int[];

src/test/regress/sql/incremental_sort.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,5 +294,3 @@ from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub;
294294
explain (costs off) select sub.unique1, stringu1 || random()::text
295295
from tenk1, lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub
296296
order by 1, 2;
297-
-- Disallow pushing down sort when pathkey is an SRF.
298-
explain (costs off) select unique1 from tenk1 order by unnest('{1,2}'::int[]);

src/test/regress/sql/select_parallel.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ EXPLAIN (VERBOSE, COSTS OFF)
443443
SELECT generate_series(1, two), array(select generate_series(1, two))
444444
FROM tenk1 ORDER BY tenthous;
445445

446+
-- must disallow pushing sort below gather when pathkey contains an SRF
447+
EXPLAIN (VERBOSE, COSTS OFF)
448+
SELECT unnest(ARRAY[]::integer[]) + 1 AS pathkey
449+
FROM tenk1 t1 JOIN tenk1 t2 ON TRUE
450+
ORDER BY pathkey;
451+
446452
-- test passing expanded-value representations to workers
447453
CREATE FUNCTION make_some_array(int,int) returns int[] as
448454
$$declare x int[];

0 commit comments

Comments
 (0)