]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Stabilize plancache test against on-access VM setting master github/master
authorMelanie Plageman <melanieplageman@gmail.com>
Tue, 21 Apr 2026 18:36:59 +0000 (14:36 -0400)
committerMelanie Plageman <melanieplageman@gmail.com>
Tue, 21 Apr 2026 18:36:59 +0000 (14:36 -0400)
Since b46e1e54d07 allowed setting the VM on-access and 378a21618 set
pd_prune_xid on INSERT, the testing of generic/custom plans in
src/test/regress/sql/plancache.sql was destabilized.

One of the queries of test_mode could have set the pages all-visible and
if autovacuum/autoanalyze ran and updated pg_class.relallvisible, it
would affect whether we got an index-only or sequential scan.

Preclude this by disabling autovacuum and autoanalyze for test_mode and
carefully sequencing when ANALYZE is run.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Discussion: https://postgr.es/m/71277259-264e-4983-a201-938b404049d7%40gmail.com

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

index 4e59188196c96fecd1c20cac6a80b9260f778721..d58534ca1cd649fef20cce2ad339ea103163479b 100644 (file)
@@ -279,10 +279,14 @@ execute pstmt_def_insert(1);
 drop table pc_list_parted, pc_list_part_null;
 deallocate pstmt_def_insert;
 -- Test plan_cache_mode
-create table test_mode (a int);
+create table test_mode (a int) with (autovacuum_enabled = false);
 insert into test_mode select 1 from generate_series(1,1000) union all select 2;
-create index on test_mode (a);
+-- ANALYZE before creating the index. CREATE INDEX scans the table, which may
+-- set pages all-visible via on-access pruning. If relallvisible is then updated
+-- by ANALYZE, the generic plan may pick an index-only scan instead of the
+-- expected sequential scan.
 analyze test_mode;
+create index on test_mode (a);
 prepare test_mode_pp (int) as select count(*) from test_mode where a = $1;
 select name, generic_plans, custom_plans from pg_prepared_statements
   where  name = 'test_mode_pp';
index 4b2f11dcc6418f2082dff4fb571bf6fb4bc67001..aed388d03a1d48a78c1f343e5718a7830c3c208a 100644 (file)
@@ -180,10 +180,15 @@ deallocate pstmt_def_insert;
 
 -- Test plan_cache_mode
 
-create table test_mode (a int);
+create table test_mode (a int) with (autovacuum_enabled = false);
 insert into test_mode select 1 from generate_series(1,1000) union all select 2;
-create index on test_mode (a);
+
+-- ANALYZE before creating the index. CREATE INDEX scans the table, which may
+-- set pages all-visible via on-access pruning. If relallvisible is then updated
+-- by ANALYZE, the generic plan may pick an index-only scan instead of the
+-- expected sequential scan.
 analyze test_mode;
+create index on test_mode (a);
 
 prepare test_mode_pp (int) as select count(*) from test_mode where a = $1;
 select name, generic_plans, custom_plans from pg_prepared_statements