diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/subselect.out | 52 | ||||
| -rw-r--r-- | src/test/regress/sql/subselect.sql | 46 |
2 files changed, 98 insertions, 0 deletions
diff --git a/src/test/regress/expected/subselect.out b/src/test/regress/expected/subselect.out index ed7d6d8034e..8419dea08e3 100644 --- a/src/test/regress/expected/subselect.out +++ b/src/test/regress/expected/subselect.out @@ -1041,3 +1041,55 @@ NOTICE: x = 9, y = 13 (3 rows) drop function tattle(x int, y int); +-- +-- Test that LIMIT can be pushed to SORT through a subquery that just +-- projects columns +-- +create table sq_limit (pk int primary key, c1 int, c2 int); +insert into sq_limit values + (1, 1, 1), + (2, 2, 2), + (3, 3, 3), + (4, 4, 4), + (5, 1, 1), + (6, 2, 2), + (7, 3, 3), + (8, 4, 4); +-- The explain contains data that may not be invariant, so +-- filter for just the interesting bits. The goal here is that +-- we should see three notices, in order: +-- NOTICE: Limit +-- NOTICE: Subquery +-- NOTICE: Top-N Sort +-- A missing step, or steps out of order means we have a problem. +do $$ + declare x text; + begin + for x in + explain (analyze, summary off, timing off, costs off) + select * from (select pk,c2 from sq_limit order by c1,pk) as x limit 3 + loop + if (left(ltrim(x), 5) = 'Limit') then + raise notice 'Limit'; + end if; + if (left(ltrim(x), 12) = '-> Subquery') then + raise notice 'Subquery'; + end if; + if (left(ltrim(x), 18) = 'Sort Method: top-N') then + raise notice 'Top-N Sort'; + end if; + end loop; + end; +$$; +NOTICE: Limit +NOTICE: Subquery +NOTICE: Top-N Sort +select * from (select pk,c2 from sq_limit order by c1,pk) as x limit 3; + pk | c2 +----+---- + 1 | 1 + 5 | 1 + 2 | 2 +(3 rows) + +drop table sq_limit; diff --git a/src/test/regress/sql/subselect.sql b/src/test/regress/sql/subselect.sql index 2fc0e26ca06..7087ee27cd4 100644 --- a/src/test/regress/sql/subselect.sql +++ b/src/test/regress/sql/subselect.sql @@ -540,3 +540,49 @@ select * from where tattle(x, u); drop function tattle(x int, y int); + +-- +-- Test that LIMIT can be pushed to SORT through a subquery that just +-- projects columns +-- +create table sq_limit (pk int primary key, c1 int, c2 int); +insert into sq_limit values + (1, 1, 1), + (2, 2, 2), + (3, 3, 3), + (4, 4, 4), + (5, 1, 1), + (6, 2, 2), + (7, 3, 3), + (8, 4, 4); + +-- The explain contains data that may not be invariant, so +-- filter for just the interesting bits. The goal here is that +-- we should see three notices, in order: +-- NOTICE: Limit +-- NOTICE: Subquery +-- NOTICE: Top-N Sort +-- A missing step, or steps out of order means we have a problem. +do $$ + declare x text; + begin + for x in + explain (analyze, summary off, timing off, costs off) + select * from (select pk,c2 from sq_limit order by c1,pk) as x limit 3 + loop + if (left(ltrim(x), 5) = 'Limit') then + raise notice 'Limit'; + end if; + if (left(ltrim(x), 12) = '-> Subquery') then + raise notice 'Subquery'; + end if; + if (left(ltrim(x), 18) = 'Sort Method: top-N') then + raise notice 'Top-N Sort'; + end if; + end loop; + end; +$$; + +select * from (select pk,c2 from sq_limit order by c1,pk) as x limit 3; + +drop table sq_limit; |
