| 1 |
# Verify that DROP INDEX properly locks all downward sub-partitions |
| 2 |
# and partitions before locking the indexes. |
| 3 |
|
| 4 |
setup |
| 5 |
{ |
| 6 |
CREATE TABLE part_drop_index_locking (id int) PARTITION BY RANGE(id); |
| 7 |
CREATE TABLE part_drop_index_locking_subpart PARTITION OF part_drop_index_locking FOR VALUES FROM (1) TO (100) PARTITION BY RANGE(id); |
| 8 |
CREATE TABLE part_drop_index_locking_subpart_child PARTITION OF part_drop_index_locking_subpart FOR VALUES FROM (1) TO (100); |
| 9 |
CREATE INDEX part_drop_index_locking_idx ON part_drop_index_locking(id); |
| 10 |
CREATE INDEX part_drop_index_locking_subpart_idx ON part_drop_index_locking_subpart(id); |
| 11 |
} |
| 12 |
|
| 13 |
teardown |
| 14 |
{ |
| 15 |
DROP TABLE part_drop_index_locking; |
| 16 |
} |
| 17 |
|
| 18 |
# SELECT will take AccessShare lock first on the table and then on its index. |
| 19 |
# We can simulate the case where DROP INDEX starts between those steps |
| 20 |
# by manually taking the table lock beforehand. |
| 21 |
session s1 |
| 22 |
step s1begin { BEGIN; } |
| 23 |
step s1lock { LOCK TABLE part_drop_index_locking_subpart_child IN ACCESS SHARE MODE; } |
| 24 |
step s1select { SELECT * FROM part_drop_index_locking_subpart_child; } |
| 25 |
step s1commit { COMMIT; } |
| 26 |
|
| 27 |
session s2 |
| 28 |
step s2begin { BEGIN; } |
| 29 |
step s2drop { DROP INDEX part_drop_index_locking_idx; } |
| 30 |
step s2dropsub { DROP INDEX part_drop_index_locking_subpart_idx; } |
| 31 |
step s2commit { COMMIT; } |
| 32 |
|
| 33 |
session s3 |
| 34 |
step s3getlocks { |
| 35 |
SELECT s.query, c.relname, l.mode, l.granted |
| 36 |
FROM pg_locks l |
| 37 |
JOIN pg_class c ON l.relation = c.oid |
| 38 |
JOIN pg_stat_activity s ON l.pid = s.pid |
| 39 |
WHERE c.relname LIKE 'part_drop_index_locking%' |
| 40 |
ORDER BY s.query, c.relname, l.mode, l.granted; |
| 41 |
} |
| 42 |
|
| 43 |
# Run DROP INDEX on top partitioned table |
| 44 |
permutation s1begin s1lock s2begin s2drop(s1commit) s1select s3getlocks s1commit s3getlocks s2commit |
| 45 |
|
| 46 |
# Run DROP INDEX on top sub-partition table |
| 47 |
permutation s1begin s1lock s2begin s2dropsub(s1commit) s1select s3getlocks s1commit s3getlocks s2commit |