|
| 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 | +-- Check that valid options are not rejected nor corruption reported |
| 70 | +-- for a non-empty table |
| 71 | +SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none'); |
| 72 | + blkno | offnum | attnum | msg |
| 73 | +-------+--------+--------+----- |
| 74 | +(0 rows) |
| 75 | + |
| 76 | +SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen'); |
| 77 | + blkno | offnum | attnum | msg |
| 78 | +-------+--------+--------+----- |
| 79 | +(0 rows) |
| 80 | + |
| 81 | +SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible'); |
| 82 | + blkno | offnum | attnum | msg |
| 83 | +-------+--------+--------+----- |
| 84 | +(0 rows) |
| 85 | + |
| 86 | +SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0); |
| 87 | + blkno | offnum | attnum | msg |
| 88 | +-------+--------+--------+----- |
| 89 | +(0 rows) |
| 90 | + |
| 91 | +CREATE ROLE regress_heaptest_role; |
| 92 | +-- verify permissions are checked (error due to function not callable) |
| 93 | +SET ROLE regress_heaptest_role; |
| 94 | +SELECT * FROM verify_heapam(relation := 'heaptest'); |
| 95 | +ERROR: permission denied for function verify_heapam |
| 96 | +RESET ROLE; |
| 97 | +GRANT EXECUTE ON FUNCTION verify_heapam(regclass, boolean, boolean, text, bigint, bigint) TO regress_heaptest_role; |
| 98 | +-- verify permissions are now sufficient |
| 99 | +SET ROLE regress_heaptest_role; |
| 100 | +SELECT * FROM verify_heapam(relation := 'heaptest'); |
| 101 | + blkno | offnum | attnum | msg |
| 102 | +-------+--------+--------+----- |
| 103 | +(0 rows) |
| 104 | + |
| 105 | +RESET ROLE; |
| 106 | +-- Check specifying invalid block ranges when verifying a non-empty table. |
| 107 | +SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 10000); |
| 108 | +ERROR: ending block number must be between 0 and 0 |
| 109 | +SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 10000, endblock := 11000); |
| 110 | +ERROR: starting block number must be between 0 and 0 |
| 111 | +-- Vacuum freeze to change the xids encountered in subsequent tests |
| 112 | +VACUUM FREEZE heaptest; |
| 113 | +-- Check that valid options are not rejected nor corruption reported |
| 114 | +-- for a non-empty frozen table |
| 115 | +SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'none'); |
| 116 | + blkno | offnum | attnum | msg |
| 117 | +-------+--------+--------+----- |
| 118 | +(0 rows) |
| 119 | + |
| 120 | +SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-frozen'); |
| 121 | + blkno | offnum | attnum | msg |
| 122 | +-------+--------+--------+----- |
| 123 | +(0 rows) |
| 124 | + |
| 125 | +SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'all-visible'); |
| 126 | + blkno | offnum | attnum | msg |
| 127 | +-------+--------+--------+----- |
| 128 | +(0 rows) |
| 129 | + |
| 130 | +SELECT * FROM verify_heapam(relation := 'heaptest', startblock := 0, endblock := 0); |
| 131 | + blkno | offnum | attnum | msg |
| 132 | +-------+--------+--------+----- |
| 133 | +(0 rows) |
| 134 | + |
| 135 | +-- Check that partitioned tables (the parent ones) which don't have visibility |
| 136 | +-- maps are rejected |
| 137 | +CREATE TABLE test_partitioned (a int, b text default repeat('x', 5000)) |
| 138 | + PARTITION BY list (a); |
| 139 | +SELECT * FROM verify_heapam('test_partitioned', |
| 140 | + startblock := NULL, |
| 141 | + endblock := NULL); |
| 142 | +ERROR: "test_partitioned" is not a table, materialized view, or TOAST table |
| 143 | +-- Check that valid options are not rejected nor corruption reported |
| 144 | +-- for an empty partition table (the child one) |
| 145 | +CREATE TABLE test_partition partition OF test_partitioned FOR VALUES IN (1); |
| 146 | +SELECT * FROM verify_heapam('test_partition', |
| 147 | + startblock := NULL, |
| 148 | + endblock := NULL); |
| 149 | + blkno | offnum | attnum | msg |
| 150 | +-------+--------+--------+----- |
| 151 | +(0 rows) |
| 152 | + |
| 153 | +-- Check that valid options are not rejected nor corruption reported |
| 154 | +-- for a non-empty partition table (the child one) |
| 155 | +INSERT INTO test_partitioned (a) (SELECT 1 FROM generate_series(1,1000) gs); |
| 156 | +SELECT * FROM verify_heapam('test_partition', |
| 157 | + startblock := NULL, |
| 158 | + endblock := NULL); |
| 159 | + blkno | offnum | attnum | msg |
| 160 | +-------+--------+--------+----- |
| 161 | +(0 rows) |
| 162 | + |
| 163 | +-- Check that indexes are rejected |
| 164 | +CREATE INDEX test_index ON test_partition (a); |
| 165 | +SELECT * FROM verify_heapam('test_index', |
| 166 | + startblock := NULL, |
| 167 | + endblock := NULL); |
| 168 | +ERROR: "test_index" is not a table, materialized view, or TOAST table |
| 169 | +-- Check that views are rejected |
| 170 | +CREATE VIEW test_view AS SELECT 1; |
| 171 | +SELECT * FROM verify_heapam('test_view', |
| 172 | + startblock := NULL, |
| 173 | + endblock := NULL); |
| 174 | +ERROR: "test_view" is not a table, materialized view, or TOAST table |
| 175 | +-- Check that sequences are rejected |
| 176 | +CREATE SEQUENCE test_sequence; |
| 177 | +SELECT * FROM verify_heapam('test_sequence', |
| 178 | + startblock := NULL, |
| 179 | + endblock := NULL); |
| 180 | +ERROR: "test_sequence" is not a table, materialized view, or TOAST table |
| 181 | +-- Check that foreign tables are rejected |
| 182 | +CREATE FOREIGN DATA WRAPPER dummy; |
| 183 | +CREATE SERVER dummy_server FOREIGN DATA WRAPPER dummy; |
| 184 | +CREATE FOREIGN TABLE test_foreign_table () SERVER dummy_server; |
| 185 | +SELECT * FROM verify_heapam('test_foreign_table', |
| 186 | + startblock := NULL, |
| 187 | + endblock := NULL); |
| 188 | +ERROR: "test_foreign_table" is not a table, materialized view, or TOAST table |
| 189 | +-- cleanup |
| 190 | +DROP TABLE heaptest; |
| 191 | +DROP TABLE test_partition; |
| 192 | +DROP TABLE test_partitioned; |
| 193 | +DROP OWNED BY regress_heaptest_role; -- permissions |
| 194 | +DROP ROLE regress_heaptest_role; |
0 commit comments