Debian Codegraph @

contrib/amcheck/expected/check_heap.out

raw
1 CREATE TABLE heaptest (a integer, b text);
2 REVOKE ALL ON heaptest FROM PUBLIC;
3 -- Check that invalid skip option is rejected
4 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'rope');
5 ERROR: invalid skip option
6 HINT: Valid skip options are "all-visible", "all-frozen", and "none".
7 -- Check specifying invalid block ranges when verifying an empty table
8 SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0);
9 blkno | offnum | attnum | msg
10 -------+--------+--------+-----
11 (0 rows)
12
13 SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 5, endblock := 8);
14 blkno | offnum | attnum | msg
15 -------+--------+--------+-----
16 (0 rows)
17
18 -- Check that valid options are not rejected nor corruption reported
19 -- for an empty table, and that skip enum-like parameter is case-insensitive
20 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none');
21 blkno | offnum | attnum | msg
22 -------+--------+--------+-----
23 (0 rows)
24
25 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen');
26 blkno | offnum | attnum | msg
27 -------+--------+--------+-----
28 (0 rows)
29
30 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible');
31 blkno | offnum | attnum | msg
32 -------+--------+--------+-----
33 (0 rows)
34
35 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'None');
36 blkno | offnum | attnum | msg
37 -------+--------+--------+-----
38 (0 rows)
39
40 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'All-Frozen');
41 blkno | offnum | attnum | msg
42 -------+--------+--------+-----
43 (0 rows)
44
45 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'All-Visible');
46 blkno | offnum | attnum | msg
47 -------+--------+--------+-----
48 (0 rows)
49
50 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'NONE');
51 blkno | offnum | attnum | msg
52 -------+--------+--------+-----
53 (0 rows)
54
55 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'ALL-FROZEN');
56 blkno | offnum | attnum | msg
57 -------+--------+--------+-----
58 (0 rows)
59
60 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'ALL-VISIBLE');
61 blkno | offnum | attnum | msg
62 -------+--------+--------+-----
63 (0 rows)
64
65 -- Add some data so subsequent tests are not entirely trivial
66 INSERT INTO heaptest (a, b)
67 (SELECT gs, repeat('x', gs)
68 FROM generate_series(1,50) gs);
69 -- pg_stat_io test:
70 -- verify_heapam always uses a BAS_BULKREAD BufferAccessStrategy, whereas a
71 -- sequential scan does so only if the table is large enough when compared to
72 -- shared buffers (see initscan()). CREATE DATABASE ... also unconditionally
73 -- uses a BAS_BULKREAD strategy, but we have chosen to use a tablespace and
74 -- verify_heapam to provide coverage instead of adding another expensive
75 -- operation to the main regression test suite.
76 --
77 -- Create an alternative tablespace and move the heaptest table to it, causing
78 -- it to be rewritten and all the blocks to reliably evicted from shared
79 -- buffers -- guaranteeing actual reads when we next select from it in the
80 -- same transaction. The heaptest table is smaller than the default
81 -- wal_skip_threshold, so a wal_level=minimal commit reads the table into
82 -- shared_buffers. A transaction delays that and excludes any autovacuum.
83 SET allow_in_place_tablespaces = true;
84 CREATE TABLESPACE regress_test_stats_tblspc LOCATION '';
85 SELECT sum(reads) AS stats_bulkreads_before
86 FROM pg_stat_io WHERE context = 'bulkread' \gset
87 BEGIN;
88 ALTER TABLE heaptest SET TABLESPACE regress_test_stats_tblspc;
89 -- Check that valid options are not rejected nor corruption reported
90 -- for a non-empty table
91 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none');
92 blkno | offnum | attnum | msg
93 -------+--------+--------+-----
94 (0 rows)
95
96 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen');
97 blkno | offnum | attnum | msg
98 -------+--------+--------+-----
99 (0 rows)
100
101 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible');
102 blkno | offnum | attnum | msg
103 -------+--------+--------+-----
104 (0 rows)
105
106 SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0);
107 blkno | offnum | attnum | msg
108 -------+--------+--------+-----
109 (0 rows)
110
111 COMMIT;
112 -- verify_heapam should have read in the page written out by
113 -- ALTER TABLE ... SET TABLESPACE ...
114 -- causing an additional bulkread, which should be reflected in pg_stat_io.
115 SELECT pg_stat_force_next_flush();
116 pg_stat_force_next_flush
117 --------------------------
118
119 (1 row)
120
121 SELECT sum(reads) AS stats_bulkreads_after
122 FROM pg_stat_io WHERE context = 'bulkread' \gset
123 SELECT :stats_bulkreads_after > :stats_bulkreads_before;
124 ?column?
125 ----------
126 t
127 (1 row)
128
129 CREATE ROLE regress_heaptest_role;
130 -- verify permissions are checked (error due to function not callable)
131 SET ROLE regress_heaptest_role;
132 SELECT * FROM verify_heapam(relation := 'heaptest');
133 ERROR: permission denied for function verify_heapam
134 RESET ROLE;
135 GRANT EXECUTE ON FUNCTION verify_heapam(regclass, boolean, boolean, text, bigint, bigint) TO regress_heaptest_role;
136 -- verify permissions are now sufficient
137 SET ROLE regress_heaptest_role;
138 SELECT * FROM verify_heapam(relation := 'heaptest');
139 blkno | offnum | attnum | msg
140 -------+--------+--------+-----
141 (0 rows)
142
143 RESET ROLE;
144 -- Check specifying invalid block ranges when verifying a non-empty table.
145 SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 10000);
146 ERROR: ending block number must be between 0 and 0
147 SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 10000, endblock := 11000);
148 ERROR: starting block number must be between 0 and 0
149 -- Vacuum freeze to change the xids encountered in subsequent tests
150 VACUUM (FREEZE, DISABLE_PAGE_SKIPPING) heaptest;
151 -- Check that valid options are not rejected nor corruption reported
152 -- for a non-empty frozen table
153 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none');
154 blkno | offnum | attnum | msg
155 -------+--------+--------+-----
156 (0 rows)
157
158 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen');
159 blkno | offnum | attnum | msg
160 -------+--------+--------+-----
161 (0 rows)
162
163 SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible');
164 blkno | offnum | attnum | msg
165 -------+--------+--------+-----
166 (0 rows)
167
168 SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0);
169 blkno | offnum | attnum | msg
170 -------+--------+--------+-----
171 (0 rows)
172
173 -- Check that partitioned tables (the parent ones) which don't have visibility
174 -- maps are rejected
175 CREATE TABLE test_partitioned (a int, b text default repeat('x', 5000))
176 PARTITION BY list (a);
177 SELECT * FROM verify_heapam('test_partitioned',
178 startblock := NULL,
179 endblock := NULL);
180 ERROR: cannot check relation "test_partitioned"
181 DETAIL: This operation is not supported for partitioned tables.
182 -- Check that valid options are not rejected nor corruption reported
183 -- for an empty partition table (the child one)
184 CREATE TABLE test_partition partition OF test_partitioned FOR VALUES IN (1);
185 SELECT * FROM verify_heapam('test_partition',
186 startblock := NULL,
187 endblock := NULL);
188 blkno | offnum | attnum | msg
189 -------+--------+--------+-----
190 (0 rows)
191
192 -- Check that valid options are not rejected nor corruption reported
193 -- for a non-empty partition table (the child one)
194 INSERT INTO test_partitioned (a) (SELECT 1 FROM generate_series(1,1000) gs);
195 SELECT * FROM verify_heapam('test_partition',
196 startblock := NULL,
197 endblock := NULL);
198 blkno | offnum | attnum | msg
199 -------+--------+--------+-----
200 (0 rows)
201
202 -- Check that indexes are rejected
203 CREATE INDEX test_index ON test_partition (a);
204 SELECT * FROM verify_heapam('test_index',
205 startblock := NULL,
206 endblock := NULL);
207 ERROR: cannot check relation "test_index"
208 DETAIL: This operation is not supported for indexes.
209 -- Check that views are rejected
210 CREATE VIEW test_view AS SELECT 1;
211 SELECT * FROM verify_heapam('test_view',
212 startblock := NULL,
213 endblock := NULL);
214 ERROR: cannot check relation "test_view"
215 DETAIL: This operation is not supported for views.
216 -- Check that sequences are rejected
217 CREATE SEQUENCE test_sequence;
218 SELECT * FROM verify_heapam('test_sequence',
219 startblock := NULL,
220 endblock := NULL);
221 blkno | offnum | attnum | msg
222 -------+--------+--------+-----
223 (0 rows)
224
225 -- Check that foreign tables are rejected
226 CREATE FOREIGN DATA WRAPPER dummy;
227 CREATE SERVER dummy_server FOREIGN DATA WRAPPER dummy;
228 CREATE FOREIGN TABLE test_foreign_table () SERVER dummy_server;
229 SELECT * FROM verify_heapam('test_foreign_table',
230 startblock := NULL,
231 endblock := NULL);
232 ERROR: cannot check relation "test_foreign_table"
233 DETAIL: This operation is not supported for foreign tables.
234 -- cleanup
235 DROP TABLE heaptest;
236 DROP TABLESPACE regress_test_stats_tblspc;
237 DROP TABLE test_partition;
238 DROP TABLE test_partitioned;
239 DROP OWNED BY regress_heaptest_role; -- permissions
240 DROP ROLE regress_heaptest_role;