| 1 |
CREATE TABLE heaptest (a integer, b text); |
| 2 |
REVOKE ALL ON heaptest FROM PUBLIC; |
| 3 |
|
| 4 |
-- Check that invalid skip option is rejected |
| 5 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'rope'); |
| 6 |
|
| 7 |
-- Check specifying invalid block ranges when verifying an empty table |
| 8 |
SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0); |
| 9 |
SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 5, endblock := 8); |
| 10 |
|
| 11 |
-- Check that valid options are not rejected nor corruption reported |
| 12 |
-- for an empty table, and that skip enum-like parameter is case-insensitive |
| 13 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none'); |
| 14 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen'); |
| 15 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible'); |
| 16 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'None'); |
| 17 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'All-Frozen'); |
| 18 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'All-Visible'); |
| 19 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'NONE'); |
| 20 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'ALL-FROZEN'); |
| 21 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'ALL-VISIBLE'); |
| 22 |
|
| 23 |
|
| 24 |
-- Add some data so subsequent tests are not entirely trivial |
| 25 |
INSERT INTO heaptest (a, b) |
| 26 |
(SELECT gs, repeat('x', gs) |
| 27 |
FROM generate_series(1,50) gs); |
| 28 |
|
| 29 |
-- pg_stat_io test: |
| 30 |
-- verify_heapam always uses a BAS_BULKREAD BufferAccessStrategy, whereas a |
| 31 |
-- sequential scan does so only if the table is large enough when compared to |
| 32 |
-- shared buffers (see initscan()). CREATE DATABASE ... also unconditionally |
| 33 |
-- uses a BAS_BULKREAD strategy, but we have chosen to use a tablespace and |
| 34 |
-- verify_heapam to provide coverage instead of adding another expensive |
| 35 |
-- operation to the main regression test suite. |
| 36 |
-- |
| 37 |
-- Create an alternative tablespace and move the heaptest table to it, causing |
| 38 |
-- it to be rewritten and all the blocks to reliably evicted from shared |
| 39 |
-- buffers -- guaranteeing actual reads when we next select from it in the |
| 40 |
-- same transaction. The heaptest table is smaller than the default |
| 41 |
-- wal_skip_threshold, so a wal_level=minimal commit reads the table into |
| 42 |
-- shared_buffers. A transaction delays that and excludes any autovacuum. |
| 43 |
SET allow_in_place_tablespaces = true; |
| 44 |
CREATE TABLESPACE regress_test_stats_tblspc LOCATION ''; |
| 45 |
SELECT sum(reads) AS stats_bulkreads_before |
| 46 |
FROM pg_stat_io WHERE context = 'bulkread' \gset |
| 47 |
BEGIN; |
| 48 |
ALTER TABLE heaptest SET TABLESPACE regress_test_stats_tblspc; |
| 49 |
-- Check that valid options are not rejected nor corruption reported |
| 50 |
-- for a non-empty table |
| 51 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none'); |
| 52 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen'); |
| 53 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible'); |
| 54 |
SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0); |
| 55 |
COMMIT; |
| 56 |
|
| 57 |
-- verify_heapam should have read in the page written out by |
| 58 |
-- ALTER TABLE ... SET TABLESPACE ... |
| 59 |
-- causing an additional bulkread, which should be reflected in pg_stat_io. |
| 60 |
SELECT pg_stat_force_next_flush(); |
| 61 |
SELECT sum(reads) AS stats_bulkreads_after |
| 62 |
FROM pg_stat_io WHERE context = 'bulkread' \gset |
| 63 |
SELECT :stats_bulkreads_after > :stats_bulkreads_before; |
| 64 |
|
| 65 |
CREATE ROLE regress_heaptest_role; |
| 66 |
|
| 67 |
-- verify permissions are checked (error due to function not callable) |
| 68 |
SET ROLE regress_heaptest_role; |
| 69 |
SELECT * FROM verify_heapam(relation := 'heaptest'); |
| 70 |
RESET ROLE; |
| 71 |
|
| 72 |
GRANT EXECUTE ON FUNCTION verify_heapam(regclass, boolean, boolean, text, bigint, bigint) TO regress_heaptest_role; |
| 73 |
|
| 74 |
-- verify permissions are now sufficient |
| 75 |
SET ROLE regress_heaptest_role; |
| 76 |
SELECT * FROM verify_heapam(relation := 'heaptest'); |
| 77 |
RESET ROLE; |
| 78 |
|
| 79 |
-- Check specifying invalid block ranges when verifying a non-empty table. |
| 80 |
SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 10000); |
| 81 |
SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 10000, endblock := 11000); |
| 82 |
|
| 83 |
-- Vacuum freeze to change the xids encountered in subsequent tests |
| 84 |
VACUUM (FREEZE, DISABLE_PAGE_SKIPPING) heaptest; |
| 85 |
|
| 86 |
-- Check that valid options are not rejected nor corruption reported |
| 87 |
-- for a non-empty frozen table |
| 88 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none'); |
| 89 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen'); |
| 90 |
SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible'); |
| 91 |
SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0); |
| 92 |
|
| 93 |
-- Check that partitioned tables (the parent ones) which don't have visibility |
| 94 |
-- maps are rejected |
| 95 |
CREATE TABLE test_partitioned (a int, b text default repeat('x', 5000)) |
| 96 |
PARTITION BY list (a); |
| 97 |
SELECT * FROM verify_heapam('test_partitioned', |
| 98 |
startblock := NULL, |
| 99 |
endblock := NULL); |
| 100 |
|
| 101 |
-- Check that valid options are not rejected nor corruption reported |
| 102 |
-- for an empty partition table (the child one) |
| 103 |
CREATE TABLE test_partition partition OF test_partitioned FOR VALUES IN (1); |
| 104 |
SELECT * FROM verify_heapam('test_partition', |
| 105 |
startblock := NULL, |
| 106 |
endblock := NULL); |
| 107 |
|
| 108 |
-- Check that valid options are not rejected nor corruption reported |
| 109 |
-- for a non-empty partition table (the child one) |
| 110 |
INSERT INTO test_partitioned (a) (SELECT 1 FROM generate_series(1,1000) gs); |
| 111 |
SELECT * FROM verify_heapam('test_partition', |
| 112 |
startblock := NULL, |
| 113 |
endblock := NULL); |
| 114 |
|
| 115 |
-- Check that indexes are rejected |
| 116 |
CREATE INDEX test_index ON test_partition (a); |
| 117 |
SELECT * FROM verify_heapam('test_index', |
| 118 |
startblock := NULL, |
| 119 |
endblock := NULL); |
| 120 |
|
| 121 |
-- Check that views are rejected |
| 122 |
CREATE VIEW test_view AS SELECT 1; |
| 123 |
SELECT * FROM verify_heapam('test_view', |
| 124 |
startblock := NULL, |
| 125 |
endblock := NULL); |
| 126 |
|
| 127 |
-- Check that sequences are rejected |
| 128 |
CREATE SEQUENCE test_sequence; |
| 129 |
SELECT * FROM verify_heapam('test_sequence', |
| 130 |
startblock := NULL, |
| 131 |
endblock := NULL); |
| 132 |
|
| 133 |
-- Check that foreign tables are rejected |
| 134 |
CREATE FOREIGN DATA WRAPPER dummy; |
| 135 |
CREATE SERVER dummy_server FOREIGN DATA WRAPPER dummy; |
| 136 |
CREATE FOREIGN TABLE test_foreign_table () SERVER dummy_server; |
| 137 |
SELECT * FROM verify_heapam('test_foreign_table', |
| 138 |
startblock := NULL, |
| 139 |
endblock := NULL); |
| 140 |
|
| 141 |
-- cleanup |
| 142 |
DROP TABLE heaptest; |
| 143 |
DROP TABLESPACE regress_test_stats_tblspc; |
| 144 |
DROP TABLE test_partition; |
| 145 |
DROP TABLE test_partitioned; |
| 146 |
DROP OWNED BY regress_heaptest_role; -- permissions |
| 147 |
DROP ROLE regress_heaptest_role; |