1SET max_parallel_maintenance_workers TO 4; 2SET min_parallel_index_scan_size TO '128kB'; 3 4-- Bug #17245: Make sure that we don't totally fail to VACUUM individual indexes that 5-- happen to be below min_parallel_index_scan_size during parallel VACUUM: 6CREATE TABLE parallel_vacuum_table (a int) WITH (autovacuum_enabled = off); 7INSERT INTO parallel_vacuum_table SELECT i from generate_series(1, 10000) i; 8 9-- Parallel VACUUM will never be used unless there are at least two indexes 10-- that exceed min_parallel_index_scan_size. Create two such indexes, and 11-- a third index that is smaller than min_parallel_index_scan_size. 12CREATE INDEX regular_sized_index ON parallel_vacuum_table(a); 13CREATE INDEX typically_sized_index ON parallel_vacuum_table(a); 14-- Note: vacuum_in_leader_small_index can apply deduplication, making it ~3x 15-- smaller than the other indexes 16CREATE INDEX vacuum_in_leader_small_index ON parallel_vacuum_table((1)); 17 18-- Verify (as best we can) that the cost model for parallel VACUUM 19-- will make our VACUUM run in parallel, while always leaving it up to the 20-- parallel leader to handle the vacuum_in_leader_small_index index: 21SELECT EXISTS ( 22SELECT 1 23FROM pg_class 24WHERE oid = 'vacuum_in_leader_small_index'::regclass AND 25 pg_relation_size(oid) < 26 pg_size_bytes(current_setting('min_parallel_index_scan_size')) 27) as leader_will_handle_small_index; 28SELECT count(*) as trigger_parallel_vacuum_nindexes 29FROM pg_class 30WHERE oid in ('regular_sized_index'::regclass, 'typically_sized_index'::regclass) AND 31 pg_relation_size(oid) >= 32 pg_size_bytes(current_setting('min_parallel_index_scan_size')); 33 34-- Parallel VACUUM with B-Tree page deletions, ambulkdelete calls: 35DELETE FROM parallel_vacuum_table; 36VACUUM (PARALLEL 4, INDEX_CLEANUP ON) parallel_vacuum_table; 37 38-- Since vacuum_in_leader_small_index uses deduplication, we expect an 39-- assertion failure with bug #17245 (in the absence of bugfix): 40INSERT INTO parallel_vacuum_table SELECT i FROM generate_series(1, 10000) i; 41 42RESET max_parallel_maintenance_workers; 43RESET min_parallel_index_scan_size; 44 45-- Deliberately don't drop table, to get further coverage from tools like 46-- pg_amcheck in some testing scenarios 47