Make stats_ext test faster under cache-clobbering test conditions.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 3 Dec 2025 18:23:45 +0000 (13:23 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 3 Dec 2025 18:23:50 +0000 (13:23 -0500)
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

src/test/regress/expected/stats_ext.out
src/test/regress/sql/stats_ext.sql

index 5a4077f8ed564d6f3fdbf027a5dd9651e6778ea6..eb70ea5a2eef01addb853ae770a07a4a55953972 100644 (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);
index 94e2139c50421f70ce9204e4c99733c40445ddf7..3f8e03f28a039988ea69a20e9227f5a570cd9651 100644 (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);