Skip to content

Commit ce59b75

Browse files
committed
Add toast-level reloption for vacuum_index_cleanup
a96c41f has introduced the option for heap, but it still lacked the variant to control the behavior for toast relations. While on it, refactor the tests so as they stress more scenarios with the various values that vacuum_index_cleanup can use. It would be useful to couple those tests with pageinspect to check that pages are actually cleaned up, but this is left for later. Author: Masahiko Sawada, Michael Paquier Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/CAD21AoCqs8iN04RX=i1KtLSaX5RrTEM04b7NHYps4+rqtpWNEg@mail.gmail.com
1 parent 0089c30 commit ce59b75

File tree

5 files changed

+63
-10
lines changed

5 files changed

+63
-10
lines changed

doc/src/sgml/ref/create_table.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
14061406
</varlistentry>
14071407

14081408
<varlistentry id="reloption-vacuum-index-cleanup" xreflabel="vacuum_index_cleanup">
1409-
<term><literal>vacuum_index_cleanup</literal> (<type>boolean</type>)
1409+
<term><literal>vacuum_index_cleanup</literal>, <literal>toast.vacuum_index_cleanup</literal> (<type>boolean</type>)
14101410
<indexterm>
14111411
<primary><varname>vacuum_index_cleanup</varname> storage parameter</primary>
14121412
</indexterm>

src/backend/access/common/reloptions.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static relopt_bool boolRelOpts[] =
144144
{
145145
"vacuum_index_cleanup",
146146
"Enables index vacuuming and index cleanup",
147-
RELOPT_KIND_HEAP,
147+
RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
148148
ShareUpdateExclusiveLock
149149
},
150150
true

src/bin/psql/tab-complete.c

+1
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ static const char *const table_storage_parameters[] = {
10691069
"toast.autovacuum_vacuum_scale_factor",
10701070
"toast.autovacuum_vacuum_threshold",
10711071
"toast.log_autovacuum_min_duration",
1072+
"toast.vacuum_index_cleanup",
10721073
"toast.vacuum_truncate",
10731074
"toast_tuple_target",
10741075
"user_catalog_table",

src/test/regress/expected/vacuum.out

+30-4
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,39 @@ SQL function "wrap_do_analyze" statement 1
9393
VACUUM FULL vactst;
9494
VACUUM (DISABLE_PAGE_SKIPPING) vaccluster;
9595
-- INDEX_CLEANUP option
96-
CREATE TABLE no_index_cleanup (i INT PRIMARY KEY) WITH (vacuum_index_cleanup = false);
97-
VACUUM (INDEX_CLEANUP FALSE) vaccluster;
98-
VACUUM (INDEX_CLEANUP FALSE) vactst; -- index cleanup option is ignored if no indexes
99-
VACUUM (INDEX_CLEANUP FALSE, FREEZE TRUE) vaccluster;
96+
CREATE TABLE no_index_cleanup (i INT PRIMARY KEY, t TEXT);
97+
-- Use uncompressed data stored in toast.
98+
CREATE INDEX no_index_cleanup_idx ON no_index_cleanup(t);
99+
ALTER TABLE no_index_cleanup ALTER COLUMN t SET STORAGE EXTERNAL;
100+
INSERT INTO no_index_cleanup(i, t) VALUES (generate_series(1,30),
101+
repeat('1234567890',300));
100102
-- index cleanup option is ignored if VACUUM FULL
101103
VACUUM (INDEX_CLEANUP TRUE, FULL TRUE) no_index_cleanup;
102104
VACUUM (FULL TRUE) no_index_cleanup;
105+
-- Toast inherits the value from its parent table.
106+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = false);
107+
DELETE FROM no_index_cleanup WHERE i < 15;
108+
-- Nothing is cleaned up.
109+
VACUUM no_index_cleanup;
110+
-- Both parent relation and toast are cleaned up.
111+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = true);
112+
VACUUM no_index_cleanup;
113+
-- Parameter is set for both the parent table and its toast relation.
114+
INSERT INTO no_index_cleanup(i, t) VALUES (generate_series(31,60),
115+
repeat('1234567890',300));
116+
DELETE FROM no_index_cleanup WHERE i < 45;
117+
-- Only toast index is cleaned up.
118+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = false,
119+
toast.vacuum_index_cleanup = true);
120+
VACUUM no_index_cleanup;
121+
-- Only parent is cleaned up.
122+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = true,
123+
toast.vacuum_index_cleanup = false);
124+
VACUUM no_index_cleanup;
125+
-- Test some extra relations.
126+
VACUUM (INDEX_CLEANUP FALSE) vaccluster;
127+
VACUUM (INDEX_CLEANUP FALSE) vactst; -- index cleanup option is ignored if no indexes
128+
VACUUM (INDEX_CLEANUP FALSE, FREEZE TRUE) vaccluster;
103129
-- TRUNCATE option
104130
CREATE TABLE vac_truncate_test(i INT NOT NULL, j text)
105131
WITH (vacuum_truncate=true, autovacuum_enabled=false);

src/test/regress/sql/vacuum.sql

+30-4
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,39 @@ VACUUM FULL vactst;
7676
VACUUM (DISABLE_PAGE_SKIPPING) vaccluster;
7777

7878
-- INDEX_CLEANUP option
79-
CREATE TABLE no_index_cleanup (i INT PRIMARY KEY) WITH (vacuum_index_cleanup = false);
80-
VACUUM (INDEX_CLEANUP FALSE) vaccluster;
81-
VACUUM (INDEX_CLEANUP FALSE) vactst; -- index cleanup option is ignored if no indexes
82-
VACUUM (INDEX_CLEANUP FALSE, FREEZE TRUE) vaccluster;
79+
CREATE TABLE no_index_cleanup (i INT PRIMARY KEY, t TEXT);
80+
-- Use uncompressed data stored in toast.
81+
CREATE INDEX no_index_cleanup_idx ON no_index_cleanup(t);
82+
ALTER TABLE no_index_cleanup ALTER COLUMN t SET STORAGE EXTERNAL;
83+
INSERT INTO no_index_cleanup(i, t) VALUES (generate_series(1,30),
84+
repeat('1234567890',300));
8385
-- index cleanup option is ignored if VACUUM FULL
8486
VACUUM (INDEX_CLEANUP TRUE, FULL TRUE) no_index_cleanup;
8587
VACUUM (FULL TRUE) no_index_cleanup;
88+
-- Toast inherits the value from its parent table.
89+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = false);
90+
DELETE FROM no_index_cleanup WHERE i < 15;
91+
-- Nothing is cleaned up.
92+
VACUUM no_index_cleanup;
93+
-- Both parent relation and toast are cleaned up.
94+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = true);
95+
VACUUM no_index_cleanup;
96+
-- Parameter is set for both the parent table and its toast relation.
97+
INSERT INTO no_index_cleanup(i, t) VALUES (generate_series(31,60),
98+
repeat('1234567890',300));
99+
DELETE FROM no_index_cleanup WHERE i < 45;
100+
-- Only toast index is cleaned up.
101+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = false,
102+
toast.vacuum_index_cleanup = true);
103+
VACUUM no_index_cleanup;
104+
-- Only parent is cleaned up.
105+
ALTER TABLE no_index_cleanup SET (vacuum_index_cleanup = true,
106+
toast.vacuum_index_cleanup = false);
107+
VACUUM no_index_cleanup;
108+
-- Test some extra relations.
109+
VACUUM (INDEX_CLEANUP FALSE) vaccluster;
110+
VACUUM (INDEX_CLEANUP FALSE) vactst; -- index cleanup option is ignored if no indexes
111+
VACUUM (INDEX_CLEANUP FALSE, FREEZE TRUE) vaccluster;
86112

87113
-- TRUNCATE option
88114
CREATE TABLE vac_truncate_test(i INT NOT NULL, j text)

0 commit comments

Comments
 (0)