|
| 1 | +SELECT setseed(1); |
| 2 | + setseed |
| 3 | +--------- |
| 4 | + |
| 5 | +(1 row) |
| 6 | + |
| 7 | +-- Test that index built with bulk load is correct |
| 8 | +CREATE TABLE gist_check AS SELECT point(random(),s) c, random() p FROM generate_series(1,10000) s; |
| 9 | +CREATE INDEX gist_check_idx1 ON gist_check USING gist(c); |
| 10 | +CREATE INDEX gist_check_idx2 ON gist_check USING gist(c) INCLUDE(p); |
| 11 | +SELECT gist_index_check('gist_check_idx1', false); |
| 12 | + gist_index_check |
| 13 | +------------------ |
| 14 | + |
| 15 | +(1 row) |
| 16 | + |
| 17 | +SELECT gist_index_check('gist_check_idx2', false); |
| 18 | + gist_index_check |
| 19 | +------------------ |
| 20 | + |
| 21 | +(1 row) |
| 22 | + |
| 23 | +SELECT gist_index_check('gist_check_idx1', true); |
| 24 | + gist_index_check |
| 25 | +------------------ |
| 26 | + |
| 27 | +(1 row) |
| 28 | + |
| 29 | +SELECT gist_index_check('gist_check_idx2', true); |
| 30 | + gist_index_check |
| 31 | +------------------ |
| 32 | + |
| 33 | +(1 row) |
| 34 | + |
| 35 | +-- Test that index is correct after inserts |
| 36 | +INSERT INTO gist_check SELECT point(random(),s) c, random() p FROM generate_series(1,10000) s; |
| 37 | +SELECT gist_index_check('gist_check_idx1', false); |
| 38 | + gist_index_check |
| 39 | +------------------ |
| 40 | + |
| 41 | +(1 row) |
| 42 | + |
| 43 | +SELECT gist_index_check('gist_check_idx2', false); |
| 44 | + gist_index_check |
| 45 | +------------------ |
| 46 | + |
| 47 | +(1 row) |
| 48 | + |
| 49 | +SELECT gist_index_check('gist_check_idx1', true); |
| 50 | + gist_index_check |
| 51 | +------------------ |
| 52 | + |
| 53 | +(1 row) |
| 54 | + |
| 55 | +SELECT gist_index_check('gist_check_idx2', true); |
| 56 | + gist_index_check |
| 57 | +------------------ |
| 58 | + |
| 59 | +(1 row) |
| 60 | + |
| 61 | +-- Test that index is correct after vacuuming |
| 62 | +DELETE FROM gist_check WHERE c[1] < 5000; -- delete clustered data |
| 63 | +DELETE FROM gist_check WHERE c[1]::int % 2 = 0; -- delete scattered data |
| 64 | +-- We need two passes through the index and one global vacuum to actually |
| 65 | +-- reuse page |
| 66 | +VACUUM gist_check; |
| 67 | +VACUUM; |
| 68 | +SELECT gist_index_check('gist_check_idx1', false); |
| 69 | + gist_index_check |
| 70 | +------------------ |
| 71 | + |
| 72 | +(1 row) |
| 73 | + |
| 74 | +SELECT gist_index_check('gist_check_idx2', false); |
| 75 | + gist_index_check |
| 76 | +------------------ |
| 77 | + |
| 78 | +(1 row) |
| 79 | + |
| 80 | +SELECT gist_index_check('gist_check_idx1', true); |
| 81 | + gist_index_check |
| 82 | +------------------ |
| 83 | + |
| 84 | +(1 row) |
| 85 | + |
| 86 | +SELECT gist_index_check('gist_check_idx2', true); |
| 87 | + gist_index_check |
| 88 | +------------------ |
| 89 | + |
| 90 | +(1 row) |
| 91 | + |
| 92 | +-- Test that index is correct after reusing pages |
| 93 | +INSERT INTO gist_check SELECT point(random(),s) c, random() p FROM generate_series(1,10000) s; |
| 94 | +SELECT gist_index_check('gist_check_idx1', false); |
| 95 | + gist_index_check |
| 96 | +------------------ |
| 97 | + |
| 98 | +(1 row) |
| 99 | + |
| 100 | +SELECT gist_index_check('gist_check_idx2', false); |
| 101 | + gist_index_check |
| 102 | +------------------ |
| 103 | + |
| 104 | +(1 row) |
| 105 | + |
| 106 | +SELECT gist_index_check('gist_check_idx1', true); |
| 107 | + gist_index_check |
| 108 | +------------------ |
| 109 | + |
| 110 | +(1 row) |
| 111 | + |
| 112 | +SELECT gist_index_check('gist_check_idx2', true); |
| 113 | + gist_index_check |
| 114 | +------------------ |
| 115 | + |
| 116 | +(1 row) |
| 117 | + |
| 118 | +-- cleanup |
| 119 | +DROP TABLE gist_check; |
| 120 | +-- |
| 121 | +-- Similar to BUG #15597 |
| 122 | +-- |
| 123 | +CREATE TABLE toast_bug(c point,buggy text); |
| 124 | +ALTER TABLE toast_bug ALTER COLUMN buggy SET STORAGE extended; |
| 125 | +CREATE INDEX toasty ON toast_bug USING gist(c) INCLUDE(buggy); |
| 126 | +-- pg_attribute entry for toasty.buggy (the index) will have plain storage: |
| 127 | +UPDATE pg_attribute SET attstorage = 'p' |
| 128 | +WHERE attrelid = 'toasty'::regclass AND attname = 'buggy'; |
| 129 | +-- Whereas pg_attribute entry for toast_bug.buggy (the table) still has extended storage: |
| 130 | +SELECT attstorage FROM pg_attribute |
| 131 | +WHERE attrelid = 'toast_bug'::regclass AND attname = 'buggy'; |
| 132 | + attstorage |
| 133 | +------------ |
| 134 | + x |
| 135 | +(1 row) |
| 136 | + |
| 137 | +-- Insert compressible heap tuple (comfortably exceeds TOAST_TUPLE_THRESHOLD): |
| 138 | +INSERT INTO toast_bug SELECT point(0,0), repeat('a', 2200); |
| 139 | +-- Should not get false positive report of corruption: |
| 140 | +SELECT gist_index_check('toasty', true); |
| 141 | + gist_index_check |
| 142 | +------------------ |
| 143 | + |
| 144 | +(1 row) |
| 145 | + |
0 commit comments