1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-07 12:02:30 +03:00

Make stats_ext test faster under cache-clobbering test conditions.

Commit 1eccb9315 added a test case that will cause a large number
of evaluations of a plpgsql function.  With -DCLOBBER_CACHE_ALWAYS,
that takes an unreasonable amount of time (hours) because the
function's cache entries are repeatedly deleted and rebuilt.
That doesn't add any useful test coverage --- other test cases
already exercise plpgsql well enough --- and it's not part of what
this test intended to cover.  We can get the same planner coverage,
if not more, by making the test directly invoke numeric_lt().

Reported-by: Tomas Vondra <tomas@vondra.me>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/baf1ae02-83bd-4f5d-872a-1d04f11a9073@vondra.me
This commit is contained in:
Tom Lane
2025-12-03 13:23:45 -05:00
parent 7b81be9b42
commit 8d61228717
2 changed files with 6 additions and 15 deletions

View File

@@ -3786,18 +3786,15 @@ SELECT FROM sb_1 LEFT JOIN sb_2
RESET enable_nestloop;
RESET enable_mergejoin;
-- Check that we can use statistics on a bool-valued function.
CREATE FUNCTION extstat_small(x numeric) RETURNS bool
STRICT IMMUTABLE LANGUAGE plpgsql
AS $$ BEGIN RETURN x < 1; END $$;
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)');
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE numeric_lt(y, 1.0)');
estimated | actual
-----------+--------
3333 | 196
(1 row)
CREATE STATISTICS extstat_sb_2_small ON extstat_small(y) FROM sb_2;
CREATE STATISTICS extstat_sb_2_small ON numeric_lt(y, 1.0) FROM sb_2;
ANALYZE sb_2;
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)');
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE numeric_lt(y, 1.0)');
estimated | actual
-----------+--------
196 | 196
@@ -3805,4 +3802,3 @@ SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)');
-- Tidy up
DROP TABLE sb_1, sb_2 CASCADE;
DROP FUNCTION extstat_small(x numeric);

View File

@@ -1855,17 +1855,12 @@ RESET enable_nestloop;
RESET enable_mergejoin;
-- Check that we can use statistics on a bool-valued function.
CREATE FUNCTION extstat_small(x numeric) RETURNS bool
STRICT IMMUTABLE LANGUAGE plpgsql
AS $$ BEGIN RETURN x < 1; END $$;
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE numeric_lt(y, 1.0)');
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)');
CREATE STATISTICS extstat_sb_2_small ON extstat_small(y) FROM sb_2;
CREATE STATISTICS extstat_sb_2_small ON numeric_lt(y, 1.0) FROM sb_2;
ANALYZE sb_2;
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)');
SELECT * FROM check_estimated_rows('SELECT * FROM sb_2 WHERE numeric_lt(y, 1.0)');
-- Tidy up
DROP TABLE sb_1, sb_2 CASCADE;
DROP FUNCTION extstat_small(x numeric);