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