Browse Source

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
REL_12_STABLE
Michael Paquier 3 weeks ago
parent
commit
ce59b75d44

+ 1
- 1
doc/src/sgml/ref/create_table.sgml View File

@@ -1406,7 +1406,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1406 1406
    </varlistentry>
1407 1407
 
1408 1408
    <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>)
1410 1410
     <indexterm>
1411 1411
      <primary><varname>vacuum_index_cleanup</varname> storage parameter</primary>
1412 1412
     </indexterm>

+ 1
- 1
src/backend/access/common/reloptions.c View File

@@ -144,7 +144,7 @@ static relopt_bool boolRelOpts[] =
144 144
 		{
145 145
 			"vacuum_index_cleanup",
146 146
 			"Enables index vacuuming and index cleanup",
147
-			RELOPT_KIND_HEAP,
147
+			RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
148 148
 			ShareUpdateExclusiveLock
149 149
 		},
150 150
 		true

+ 1
- 0
src/bin/psql/tab-complete.c View File

@@ -1069,6 +1069,7 @@ static const char *const table_storage_parameters[] = {
1069 1069
 	"toast.autovacuum_vacuum_scale_factor",
1070 1070
 	"toast.autovacuum_vacuum_threshold",
1071 1071
 	"toast.log_autovacuum_min_duration",
1072
+	"toast.vacuum_index_cleanup",
1072 1073
 	"toast.vacuum_truncate",
1073 1074
 	"toast_tuple_target",
1074 1075
 	"user_catalog_table",

+ 30
- 4
src/test/regress/expected/vacuum.out View File

@@ -93,13 +93,39 @@ SQL function "wrap_do_analyze" statement 1
93 93
 VACUUM FULL vactst;
94 94
 VACUUM (DISABLE_PAGE_SKIPPING) vaccluster;
95 95
 -- 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));
100 102
 -- index cleanup option is ignored if VACUUM FULL
101 103
 VACUUM (INDEX_CLEANUP TRUE, FULL TRUE) no_index_cleanup;
102 104
 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;
103 129
 -- TRUNCATE option
104 130
 CREATE TABLE vac_truncate_test(i INT NOT NULL, j text)
105 131
 	WITH (vacuum_truncate=true, autovacuum_enabled=false);

+ 30
- 4
src/test/regress/sql/vacuum.sql View File

@@ -76,13 +76,39 @@ VACUUM FULL vactst;
76 76
 VACUUM (DISABLE_PAGE_SKIPPING) vaccluster;
77 77
 
78 78
 -- 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));
83 85
 -- index cleanup option is ignored if VACUUM FULL
84 86
 VACUUM (INDEX_CLEANUP TRUE, FULL TRUE) no_index_cleanup;
85 87
 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;
86 112
 
87 113
 -- TRUNCATE option
88 114
 CREATE TABLE vac_truncate_test(i INT NOT NULL, j text)

Loading…
Cancel
Save