| 1 |
# REINDEX CONCURRENTLY with toast relations |
| 2 |
# |
| 3 |
# Ensure that concurrent operations work correctly when a REINDEX is performed |
| 4 |
# concurrently on toast relations. Toast relation names are not deterministic, |
| 5 |
# so this abuses of allow_system_table_mods to change the names of toast |
| 6 |
# tables and its indexes so as they can be executed with REINDEX CONCURRENTLY, |
| 7 |
# which cannot be launched in a transaction context. |
| 8 |
|
| 9 |
# Create a table, with deterministic names for its toast relation and indexes. |
| 10 |
# Fortunately ALTER TABLE is transactional, making the renaming of toast |
| 11 |
# relations possible with allow_system_table_mods. |
| 12 |
setup |
| 13 |
{ |
| 14 |
CREATE TABLE reind_con_wide(id int primary key, data text); |
| 15 |
INSERT INTO reind_con_wide |
| 16 |
SELECT 1, repeat('1', 11) || string_agg(g.i::text || random()::text, '') FROM generate_series(1, 500) g(i); |
| 17 |
INSERT INTO reind_con_wide |
| 18 |
SELECT 2, repeat('2', 11) || string_agg(g.i::text || random()::text, '') FROM generate_series(1, 500) g(i); |
| 19 |
SET allow_system_table_mods TO true; |
| 20 |
DO $$DECLARE r record; |
| 21 |
BEGIN |
| 22 |
SELECT INTO r reltoastrelid::regclass::text AS table_name FROM pg_class |
| 23 |
WHERE oid = 'reind_con_wide'::regclass; |
| 24 |
EXECUTE 'ALTER TABLE ' || r.table_name || ' RENAME TO reind_con_toast;'; |
| 25 |
SELECT INTO r indexrelid::regclass::text AS index_name FROM pg_index |
| 26 |
WHERE indrelid = (SELECT oid FROM pg_class where relname = 'reind_con_toast'); |
| 27 |
EXECUTE 'ALTER INDEX ' || r.index_name || ' RENAME TO reind_con_toast_idx;'; |
| 28 |
END$$; |
| 29 |
} |
| 30 |
|
| 31 |
teardown |
| 32 |
{ |
| 33 |
DROP TABLE IF EXISTS reind_con_wide; |
| 34 |
} |
| 35 |
|
| 36 |
session s1 |
| 37 |
setup { BEGIN; } |
| 38 |
step lrex1 { lock TABLE reind_con_wide in ROW EXCLUSIVE MODE; } |
| 39 |
step lsha1 { lock TABLE reind_con_wide in SHARE MODE; } |
| 40 |
step lexc1 { lock TABLE reind_con_wide in EXCLUSIVE MODE; } |
| 41 |
step ins1 { INSERT INTO reind_con_wide SELECT 3, repeat('3', 11) || string_agg(g.i::text || random()::text, '') FROM generate_series(1, 500) g(i); } |
| 42 |
step upd1 { UPDATE reind_con_wide SET data = (SELECT repeat('4', 11) || string_agg(g.i::text || random()::text, '') FROM generate_series(1, 500) g(i)) WHERE id = 1; } |
| 43 |
step del1 { DELETE FROM reind_con_wide WHERE id = 2; } |
| 44 |
step dro1 { DROP TABLE reind_con_wide; } |
| 45 |
step end1 { COMMIT; } |
| 46 |
step rol1 { ROLLBACK; } |
| 47 |
|
| 48 |
session s2 |
| 49 |
step retab2 { REINDEX TABLE CONCURRENTLY pg_toast.reind_con_toast; } |
| 50 |
step reind2 { REINDEX INDEX CONCURRENTLY pg_toast.reind_con_toast_idx; } |
| 51 |
step sel2 { SELECT id, substr(data, 1, 10) FROM reind_con_wide ORDER BY id; } |
| 52 |
|
| 53 |
# Transaction commit with ROW EXCLUSIVE MODE |
| 54 |
permutation lrex1 ins1 retab2 end1 sel2 |
| 55 |
permutation lrex1 ins1 reind2 end1 sel2 |
| 56 |
permutation lrex1 upd1 retab2 end1 sel2 |
| 57 |
permutation lrex1 upd1 reind2 end1 sel2 |
| 58 |
permutation lrex1 del1 retab2 end1 sel2 |
| 59 |
permutation lrex1 del1 reind2 end1 sel2 |
| 60 |
permutation lrex1 dro1 retab2 end1 sel2 |
| 61 |
permutation lrex1 dro1 reind2 end1 sel2 |
| 62 |
permutation lrex1 retab2 dro1 end1 sel2 |
| 63 |
permutation lrex1 reind2 dro1 end1 sel2 |
| 64 |
# Transaction commit with SHARE MODE |
| 65 |
permutation lsha1 ins1 retab2 end1 sel2 |
| 66 |
permutation lsha1 ins1 reind2 end1 sel2 |
| 67 |
permutation lsha1 upd1 retab2 end1 sel2 |
| 68 |
permutation lsha1 upd1 reind2 end1 sel2 |
| 69 |
permutation lsha1 del1 retab2 end1 sel2 |
| 70 |
permutation lsha1 del1 reind2 end1 sel2 |
| 71 |
permutation lsha1 dro1 retab2 end1 sel2 |
| 72 |
permutation lsha1 dro1 reind2 end1 sel2 |
| 73 |
permutation lsha1 retab2 dro1 end1 sel2 |
| 74 |
permutation lsha1 reind2 dro1 end1 sel2 |
| 75 |
# Transaction commit with EXCLUSIVE MODE |
| 76 |
permutation lexc1 ins1 retab2 end1 sel2 |
| 77 |
permutation lexc1 ins1 reind2 end1 sel2 |
| 78 |
permutation lexc1 upd1 retab2 end1 sel2 |
| 79 |
permutation lexc1 upd1 reind2 end1 sel2 |
| 80 |
permutation lexc1 del1 retab2 end1 sel2 |
| 81 |
permutation lexc1 del1 reind2 end1 sel2 |
| 82 |
permutation lexc1 dro1 retab2 end1 sel2 |
| 83 |
permutation lexc1 dro1 reind2 end1 sel2 |
| 84 |
permutation lexc1 retab2 dro1 end1 sel2 |
| 85 |
permutation lexc1 reind2 dro1 end1 sel2 |
| 86 |
|
| 87 |
# Transaction rollback with ROW EXCLUSIVE MODE |
| 88 |
permutation lrex1 ins1 retab2 rol1 sel2 |
| 89 |
permutation lrex1 ins1 reind2 rol1 sel2 |
| 90 |
permutation lrex1 upd1 retab2 rol1 sel2 |
| 91 |
permutation lrex1 upd1 reind2 rol1 sel2 |
| 92 |
permutation lrex1 del1 retab2 rol1 sel2 |
| 93 |
permutation lrex1 del1 reind2 rol1 sel2 |
| 94 |
permutation lrex1 dro1 retab2 rol1 sel2 |
| 95 |
permutation lrex1 dro1 reind2 rol1 sel2 |
| 96 |
permutation lrex1 retab2 dro1 rol1 sel2 |
| 97 |
permutation lrex1 reind2 dro1 rol1 sel2 |
| 98 |
# Transaction rollback with SHARE MODE |
| 99 |
permutation lsha1 ins1 retab2 rol1 sel2 |
| 100 |
permutation lsha1 ins1 reind2 rol1 sel2 |
| 101 |
permutation lsha1 upd1 retab2 rol1 sel2 |
| 102 |
permutation lsha1 upd1 reind2 rol1 sel2 |
| 103 |
permutation lsha1 del1 retab2 rol1 sel2 |
| 104 |
permutation lsha1 del1 reind2 rol1 sel2 |
| 105 |
permutation lsha1 dro1 retab2 rol1 sel2 |
| 106 |
permutation lsha1 dro1 reind2 rol1 sel2 |
| 107 |
permutation lsha1 retab2 dro1 rol1 sel2 |
| 108 |
permutation lsha1 reind2 dro1 rol1 sel2 |
| 109 |
# Transaction rollback with EXCLUSIVE MODE |
| 110 |
permutation lexc1 ins1 retab2 rol1 sel2 |
| 111 |
permutation lexc1 ins1 reind2 rol1 sel2 |
| 112 |
permutation lexc1 upd1 retab2 rol1 sel2 |
| 113 |
permutation lexc1 upd1 reind2 rol1 sel2 |
| 114 |
permutation lexc1 del1 retab2 rol1 sel2 |
| 115 |
permutation lexc1 del1 reind2 rol1 sel2 |
| 116 |
permutation lexc1 dro1 retab2 rol1 sel2 |
| 117 |
permutation lexc1 dro1 reind2 rol1 sel2 |
| 118 |
permutation lexc1 retab2 dro1 rol1 sel2 |
| 119 |
permutation lexc1 reind2 dro1 rol1 sel2 |