mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-21 13:56:59 +08:00
In commit 915b703e1 I gave get_agg_clause_costs() the responsibility of marking Aggref nodes with the appropriate aggtranstype. I failed to notice that where it was being called from, it might see only a subset of the Aggref nodes that were in the original targetlist. Specifically, if there are duplicate aggregate calls in the tlist, either make_sort_input_target or make_window_input_target might put just a single instance into the grouping_target, and then only that instance would get marked. Fix by moving the call back into grouping_planner(), before we start building assorted PathTargets from the query tlist. Per report from Stefan Huehner. Report: <20160702131056.GD3165@huehner.biz>
102 lines
3.1 KiB
SQL
102 lines
3.1 KiB
SQL
--
|
|
-- LIMIT
|
|
-- Check the LIMIT/OFFSET feature of SELECT
|
|
--
|
|
|
|
SELECT ''::text AS two, unique1, unique2, stringu1
|
|
FROM onek WHERE unique1 > 50
|
|
ORDER BY unique1 LIMIT 2;
|
|
SELECT ''::text AS five, unique1, unique2, stringu1
|
|
FROM onek WHERE unique1 > 60
|
|
ORDER BY unique1 LIMIT 5;
|
|
SELECT ''::text AS two, unique1, unique2, stringu1
|
|
FROM onek WHERE unique1 > 60 AND unique1 < 63
|
|
ORDER BY unique1 LIMIT 5;
|
|
SELECT ''::text AS three, unique1, unique2, stringu1
|
|
FROM onek WHERE unique1 > 100
|
|
ORDER BY unique1 LIMIT 3 OFFSET 20;
|
|
SELECT ''::text AS zero, unique1, unique2, stringu1
|
|
FROM onek WHERE unique1 < 50
|
|
ORDER BY unique1 DESC LIMIT 8 OFFSET 99;
|
|
SELECT ''::text AS eleven, unique1, unique2, stringu1
|
|
FROM onek WHERE unique1 < 50
|
|
ORDER BY unique1 DESC LIMIT 20 OFFSET 39;
|
|
SELECT ''::text AS ten, unique1, unique2, stringu1
|
|
FROM onek
|
|
ORDER BY unique1 OFFSET 990;
|
|
SELECT ''::text AS five, unique1, unique2, stringu1
|
|
FROM onek
|
|
ORDER BY unique1 OFFSET 990 LIMIT 5;
|
|
SELECT ''::text AS five, unique1, unique2, stringu1
|
|
FROM onek
|
|
ORDER BY unique1 LIMIT 5 OFFSET 900;
|
|
|
|
-- Stress test for variable LIMIT in conjunction with bounded-heap sorting
|
|
|
|
SELECT
|
|
(SELECT n
|
|
FROM (VALUES (1)) AS x,
|
|
(SELECT n FROM generate_series(1,10) AS n
|
|
ORDER BY n LIMIT 1 OFFSET s-1) AS y) AS z
|
|
FROM generate_series(1,10) AS s;
|
|
|
|
--
|
|
-- Test behavior of volatile and set-returning functions in conjunction
|
|
-- with ORDER BY and LIMIT.
|
|
--
|
|
|
|
create temp sequence testseq;
|
|
|
|
explain (verbose, costs off)
|
|
select unique1, unique2, nextval('testseq')
|
|
from tenk1 order by unique2 limit 10;
|
|
|
|
select unique1, unique2, nextval('testseq')
|
|
from tenk1 order by unique2 limit 10;
|
|
|
|
select currval('testseq');
|
|
|
|
explain (verbose, costs off)
|
|
select unique1, unique2, nextval('testseq')
|
|
from tenk1 order by tenthous limit 10;
|
|
|
|
select unique1, unique2, nextval('testseq')
|
|
from tenk1 order by tenthous limit 10;
|
|
|
|
select currval('testseq');
|
|
|
|
explain (verbose, costs off)
|
|
select unique1, unique2, generate_series(1,10)
|
|
from tenk1 order by unique2 limit 7;
|
|
|
|
select unique1, unique2, generate_series(1,10)
|
|
from tenk1 order by unique2 limit 7;
|
|
|
|
explain (verbose, costs off)
|
|
select unique1, unique2, generate_series(1,10)
|
|
from tenk1 order by tenthous limit 7;
|
|
|
|
select unique1, unique2, generate_series(1,10)
|
|
from tenk1 order by tenthous limit 7;
|
|
|
|
-- use of random() is to keep planner from folding the expressions together
|
|
explain (verbose, costs off)
|
|
select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2;
|
|
|
|
select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2;
|
|
|
|
explain (verbose, costs off)
|
|
select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2
|
|
order by s2 desc;
|
|
|
|
select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2
|
|
order by s2 desc;
|
|
|
|
-- test for failure to set all aggregates' aggtranstype
|
|
explain (verbose, costs off)
|
|
select sum(tenthous) as s1, sum(tenthous) + random()*0 as s2
|
|
from tenk1 group by thousand order by thousand limit 3;
|
|
|
|
select sum(tenthous) as s1, sum(tenthous) + random()*0 as s2
|
|
from tenk1 group by thousand order by thousand limit 3;
|