Commit 1177ab1d authored by Tom Lane's avatar Tom Lane

Make new regression test case parallel-safe, and improve its output.

The test case added by commit 1f6d515a fails on buildfarm members that
have force_parallel_mode turned on, because we currently don't report sort
performance details from worker processes back to the master.  To fix that,
just make the test table be temp rather than regular; that's a good idea
anyway to forestall any possible interference from auto-analyze.
(The restriction that workers can't access temp tables might go away
someday, but almost certainly not before the other thing gets fixed.)

Also, improve the test so that we retain as much as possible of the
EXPLAIN ANALYZE output.  This aids debugging failures, and might also
expose problems that the preceding version masked.

Discussion: http://postgr.es/m/CADE5jYLuugnEEUsyW6Q_4mZFYTxHxaVCQmGAsF0yiY8ZDggi-w@mail.gmail.com
parent 27b89876
......@@ -1042,10 +1042,12 @@ NOTICE: x = 9, y = 13
drop function tattle(x int, y int);
--
-- Test that LIMIT can be pushed to SORT through a subquery that just
-- projects columns
-- Test that LIMIT can be pushed to SORT through a subquery that just projects
-- columns. We check for that having happened by looking to see if EXPLAIN
-- ANALYZE shows that a top-N sort was used. We must suppress or filter away
-- all the non-invariant parts of the EXPLAIN ANALYZE output.
--
create table sq_limit (pk int primary key, c1 int, c2 int);
create temp table sq_limit (pk int primary key, c1 int, c2 int);
insert into sq_limit values
(1, 1, 1),
(2, 2, 2),
......@@ -1055,35 +1057,30 @@ insert into sq_limit values
(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
create function explain_sq_limit() returns setof text language plpgsql as
$$
declare ln text;
begin
for ln 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;
ln := regexp_replace(ln, 'Memory: \S*', 'Memory: xxx');
return next ln;
end loop;
end;
end;
$$;
NOTICE: Limit
NOTICE: Subquery
NOTICE: Top-N Sort
select * from explain_sq_limit();
explain_sq_limit
----------------------------------------------------------------
Limit (actual rows=3 loops=1)
-> Subquery Scan on x (actual rows=3 loops=1)
-> Sort (actual rows=3 loops=1)
Sort Key: sq_limit.c1, sq_limit.pk
Sort Method: top-N heapsort Memory: xxx
-> Seq Scan on sq_limit (actual rows=8 loops=1)
(6 rows)
select * from (select pk,c2 from sq_limit order by c1,pk) as x limit 3;
pk | c2
----+----
......@@ -1092,4 +1089,4 @@ select * from (select pk,c2 from sq_limit order by c1,pk) as x limit 3;
2 | 2
(3 rows)
drop table sq_limit;
drop function explain_sq_limit();
......@@ -542,10 +542,12 @@ select * from
drop function tattle(x int, y int);
--
-- Test that LIMIT can be pushed to SORT through a subquery that just
-- projects columns
-- Test that LIMIT can be pushed to SORT through a subquery that just projects
-- columns. We check for that having happened by looking to see if EXPLAIN
-- ANALYZE shows that a top-N sort was used. We must suppress or filter away
-- all the non-invariant parts of the EXPLAIN ANALYZE output.
--
create table sq_limit (pk int primary key, c1 int, c2 int);
create temp table sq_limit (pk int primary key, c1 int, c2 int);
insert into sq_limit values
(1, 1, 1),
(2, 2, 2),
......@@ -556,33 +558,22 @@ insert into sq_limit values
(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
create function explain_sq_limit() returns setof text language plpgsql as
$$
declare ln text;
begin
for ln 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;
ln := regexp_replace(ln, 'Memory: \S*', 'Memory: xxx');
return next ln;
end loop;
end;
end;
$$;
select * from explain_sq_limit();
select * from (select pk,c2 from sq_limit order by c1,pk) as x limit 3;
drop table sq_limit;
drop function explain_sq_limit();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment