mirror of
https://github.com/postgres/postgres.git
synced 2025-05-15 19:15:29 +03:00
Speed up "brin" regression test a little bit.
In the large DO block, collect row TIDs into array variables instead of creating and dropping a pile of temporary tables. In a normal build, this reduces the brin test script's runtime from about 1.1 sec to 0.4 sec on my workstation. That's not all that exciting perhaps, but in a CLOBBER_CACHE_ALWAYS test build, the runtime drops from 20 min to 17 min, which is a little more useful. In combination with some other changes I plan to propose, this will help provide a noticeable reduction in cycle time for CLOBBER_CACHE_ALWAYS buildfarm critters.
This commit is contained in:
parent
ac8eb972f2
commit
242066cc8e
@ -288,13 +288,13 @@ DECLARE
|
|||||||
r record;
|
r record;
|
||||||
r2 record;
|
r2 record;
|
||||||
cond text;
|
cond text;
|
||||||
|
idx_ctids tid[];
|
||||||
|
ss_ctids tid[];
|
||||||
count int;
|
count int;
|
||||||
mismatch bool;
|
|
||||||
plan_ok bool;
|
plan_ok bool;
|
||||||
plan_line text;
|
plan_line text;
|
||||||
BEGIN
|
BEGIN
|
||||||
FOR r IN SELECT colname, oper, typ, value[ordinality], matches[ordinality] FROM brinopers, unnest(op) WITH ORDINALITY AS oper LOOP
|
FOR r IN SELECT colname, oper, typ, value[ordinality], matches[ordinality] FROM brinopers, unnest(op) WITH ORDINALITY AS oper LOOP
|
||||||
mismatch := false;
|
|
||||||
|
|
||||||
-- prepare the condition
|
-- prepare the condition
|
||||||
IF r.value IS NULL THEN
|
IF r.value IS NULL THEN
|
||||||
@ -304,13 +304,12 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- run the query using the brin index
|
-- run the query using the brin index
|
||||||
CREATE TEMP TABLE brin_result (cid tid);
|
|
||||||
SET enable_seqscan = 0;
|
SET enable_seqscan = 0;
|
||||||
SET enable_bitmapscan = 1;
|
SET enable_bitmapscan = 1;
|
||||||
|
|
||||||
plan_ok := false;
|
plan_ok := false;
|
||||||
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT ctid FROM brintest WHERE %s $y$, cond) LOOP
|
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond) LOOP
|
||||||
IF plan_line LIKE 'Bitmap Heap Scan on brintest%' THEN
|
IF plan_line LIKE '%Bitmap Heap Scan on brintest%' THEN
|
||||||
plan_ok := true;
|
plan_ok := true;
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
@ -318,16 +317,16 @@ BEGIN
|
|||||||
RAISE WARNING 'did not get bitmap indexscan plan for %', r;
|
RAISE WARNING 'did not get bitmap indexscan plan for %', r;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
EXECUTE format($y$INSERT INTO brin_result SELECT ctid FROM brintest WHERE %s $y$, cond);
|
EXECUTE format($y$SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond)
|
||||||
|
INTO idx_ctids;
|
||||||
|
|
||||||
-- run the query using a seqscan
|
-- run the query using a seqscan
|
||||||
CREATE TEMP TABLE brin_result_ss (cid tid);
|
|
||||||
SET enable_seqscan = 1;
|
SET enable_seqscan = 1;
|
||||||
SET enable_bitmapscan = 0;
|
SET enable_bitmapscan = 0;
|
||||||
|
|
||||||
plan_ok := false;
|
plan_ok := false;
|
||||||
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT ctid FROM brintest WHERE %s $y$, cond) LOOP
|
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond) LOOP
|
||||||
IF plan_line LIKE 'Seq Scan on brintest%' THEN
|
IF plan_line LIKE '%Seq Scan on brintest%' THEN
|
||||||
plan_ok := true;
|
plan_ok := true;
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
@ -335,22 +334,16 @@ BEGIN
|
|||||||
RAISE WARNING 'did not get seqscan plan for %', r;
|
RAISE WARNING 'did not get seqscan plan for %', r;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
EXECUTE format($y$INSERT INTO brin_result_ss SELECT ctid FROM brintest WHERE %s $y$, cond);
|
EXECUTE format($y$SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond)
|
||||||
|
INTO ss_ctids;
|
||||||
|
|
||||||
-- make sure both return the same results
|
-- make sure both return the same results
|
||||||
PERFORM * FROM brin_result EXCEPT ALL SELECT * FROM brin_result_ss;
|
count := array_length(idx_ctids, 1);
|
||||||
GET DIAGNOSTICS count = ROW_COUNT;
|
|
||||||
IF count <> 0 THEN
|
|
||||||
mismatch = true;
|
|
||||||
END IF;
|
|
||||||
PERFORM * FROM brin_result_ss EXCEPT ALL SELECT * FROM brin_result;
|
|
||||||
GET DIAGNOSTICS count = ROW_COUNT;
|
|
||||||
IF count <> 0 THEN
|
|
||||||
mismatch = true;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
|
IF NOT (count = array_length(ss_ctids, 1) AND
|
||||||
|
idx_ctids @> ss_ctids AND
|
||||||
|
idx_ctids <@ ss_ctids) THEN
|
||||||
-- report the results of each scan to make the differences obvious
|
-- report the results of each scan to make the differences obvious
|
||||||
IF mismatch THEN
|
|
||||||
RAISE WARNING 'something not right in %: count %', r, count;
|
RAISE WARNING 'something not right in %: count %', r, count;
|
||||||
SET enable_seqscan = 1;
|
SET enable_seqscan = 1;
|
||||||
SET enable_bitmapscan = 0;
|
SET enable_bitmapscan = 0;
|
||||||
@ -366,12 +359,7 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- make sure we found expected number of matches
|
-- make sure we found expected number of matches
|
||||||
SELECT count(*) INTO count FROM brin_result;
|
|
||||||
IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF;
|
IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF;
|
||||||
|
|
||||||
-- drop the temporary tables
|
|
||||||
DROP TABLE brin_result;
|
|
||||||
DROP TABLE brin_result_ss;
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END;
|
END;
|
||||||
$x$;
|
$x$;
|
||||||
|
@ -294,13 +294,13 @@ DECLARE
|
|||||||
r record;
|
r record;
|
||||||
r2 record;
|
r2 record;
|
||||||
cond text;
|
cond text;
|
||||||
|
idx_ctids tid[];
|
||||||
|
ss_ctids tid[];
|
||||||
count int;
|
count int;
|
||||||
mismatch bool;
|
|
||||||
plan_ok bool;
|
plan_ok bool;
|
||||||
plan_line text;
|
plan_line text;
|
||||||
BEGIN
|
BEGIN
|
||||||
FOR r IN SELECT colname, oper, typ, value[ordinality], matches[ordinality] FROM brinopers, unnest(op) WITH ORDINALITY AS oper LOOP
|
FOR r IN SELECT colname, oper, typ, value[ordinality], matches[ordinality] FROM brinopers, unnest(op) WITH ORDINALITY AS oper LOOP
|
||||||
mismatch := false;
|
|
||||||
|
|
||||||
-- prepare the condition
|
-- prepare the condition
|
||||||
IF r.value IS NULL THEN
|
IF r.value IS NULL THEN
|
||||||
@ -310,13 +310,12 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- run the query using the brin index
|
-- run the query using the brin index
|
||||||
CREATE TEMP TABLE brin_result (cid tid);
|
|
||||||
SET enable_seqscan = 0;
|
SET enable_seqscan = 0;
|
||||||
SET enable_bitmapscan = 1;
|
SET enable_bitmapscan = 1;
|
||||||
|
|
||||||
plan_ok := false;
|
plan_ok := false;
|
||||||
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT ctid FROM brintest WHERE %s $y$, cond) LOOP
|
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond) LOOP
|
||||||
IF plan_line LIKE 'Bitmap Heap Scan on brintest%' THEN
|
IF plan_line LIKE '%Bitmap Heap Scan on brintest%' THEN
|
||||||
plan_ok := true;
|
plan_ok := true;
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
@ -324,16 +323,16 @@ BEGIN
|
|||||||
RAISE WARNING 'did not get bitmap indexscan plan for %', r;
|
RAISE WARNING 'did not get bitmap indexscan plan for %', r;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
EXECUTE format($y$INSERT INTO brin_result SELECT ctid FROM brintest WHERE %s $y$, cond);
|
EXECUTE format($y$SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond)
|
||||||
|
INTO idx_ctids;
|
||||||
|
|
||||||
-- run the query using a seqscan
|
-- run the query using a seqscan
|
||||||
CREATE TEMP TABLE brin_result_ss (cid tid);
|
|
||||||
SET enable_seqscan = 1;
|
SET enable_seqscan = 1;
|
||||||
SET enable_bitmapscan = 0;
|
SET enable_bitmapscan = 0;
|
||||||
|
|
||||||
plan_ok := false;
|
plan_ok := false;
|
||||||
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT ctid FROM brintest WHERE %s $y$, cond) LOOP
|
FOR plan_line IN EXECUTE format($y$EXPLAIN SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond) LOOP
|
||||||
IF plan_line LIKE 'Seq Scan on brintest%' THEN
|
IF plan_line LIKE '%Seq Scan on brintest%' THEN
|
||||||
plan_ok := true;
|
plan_ok := true;
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
@ -341,22 +340,16 @@ BEGIN
|
|||||||
RAISE WARNING 'did not get seqscan plan for %', r;
|
RAISE WARNING 'did not get seqscan plan for %', r;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
EXECUTE format($y$INSERT INTO brin_result_ss SELECT ctid FROM brintest WHERE %s $y$, cond);
|
EXECUTE format($y$SELECT array_agg(ctid) FROM brintest WHERE %s $y$, cond)
|
||||||
|
INTO ss_ctids;
|
||||||
|
|
||||||
-- make sure both return the same results
|
-- make sure both return the same results
|
||||||
PERFORM * FROM brin_result EXCEPT ALL SELECT * FROM brin_result_ss;
|
count := array_length(idx_ctids, 1);
|
||||||
GET DIAGNOSTICS count = ROW_COUNT;
|
|
||||||
IF count <> 0 THEN
|
|
||||||
mismatch = true;
|
|
||||||
END IF;
|
|
||||||
PERFORM * FROM brin_result_ss EXCEPT ALL SELECT * FROM brin_result;
|
|
||||||
GET DIAGNOSTICS count = ROW_COUNT;
|
|
||||||
IF count <> 0 THEN
|
|
||||||
mismatch = true;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
|
IF NOT (count = array_length(ss_ctids, 1) AND
|
||||||
|
idx_ctids @> ss_ctids AND
|
||||||
|
idx_ctids <@ ss_ctids) THEN
|
||||||
-- report the results of each scan to make the differences obvious
|
-- report the results of each scan to make the differences obvious
|
||||||
IF mismatch THEN
|
|
||||||
RAISE WARNING 'something not right in %: count %', r, count;
|
RAISE WARNING 'something not right in %: count %', r, count;
|
||||||
SET enable_seqscan = 1;
|
SET enable_seqscan = 1;
|
||||||
SET enable_bitmapscan = 0;
|
SET enable_bitmapscan = 0;
|
||||||
@ -372,12 +365,7 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- make sure we found expected number of matches
|
-- make sure we found expected number of matches
|
||||||
SELECT count(*) INTO count FROM brin_result;
|
|
||||||
IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF;
|
IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF;
|
||||||
|
|
||||||
-- drop the temporary tables
|
|
||||||
DROP TABLE brin_result;
|
|
||||||
DROP TABLE brin_result_ss;
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END;
|
END;
|
||||||
$x$;
|
$x$;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user