| 1 |
# Tests for locking conflicts with TRUNCATE commands. |
| 2 |
|
| 3 |
setup |
| 4 |
{ |
| 5 |
CREATE ROLE regress_truncate_conflict; |
| 6 |
CREATE TABLE truncate_tab (a int); |
| 7 |
} |
| 8 |
|
| 9 |
teardown |
| 10 |
{ |
| 11 |
DROP TABLE truncate_tab; |
| 12 |
DROP ROLE regress_truncate_conflict; |
| 13 |
} |
| 14 |
|
| 15 |
session s1 |
| 16 |
step s1_begin { BEGIN; } |
| 17 |
step s1_tab_lookup { SELECT count(*) >= 0 FROM truncate_tab; } |
| 18 |
step s1_commit { COMMIT; } |
| 19 |
|
| 20 |
session s2 |
| 21 |
step s2_grant { GRANT TRUNCATE ON truncate_tab TO regress_truncate_conflict; } |
| 22 |
step s2_auth { SET ROLE regress_truncate_conflict; } |
| 23 |
step s2_truncate { TRUNCATE truncate_tab; } |
| 24 |
step s2_reset { RESET ROLE; } |
| 25 |
|
| 26 |
# The role doesn't have privileges to truncate the table, so TRUNCATE should |
| 27 |
# immediately fail without waiting for a lock. |
| 28 |
permutation s1_begin s1_tab_lookup s2_auth s2_truncate s1_commit s2_reset |
| 29 |
permutation s1_begin s2_auth s2_truncate s1_tab_lookup s1_commit s2_reset |
| 30 |
permutation s1_begin s2_auth s1_tab_lookup s2_truncate s1_commit s2_reset |
| 31 |
permutation s2_auth s2_truncate s1_begin s1_tab_lookup s1_commit s2_reset |
| 32 |
|
| 33 |
# The role has privileges to truncate the table, TRUNCATE will block if |
| 34 |
# another session holds a lock on the table and succeed in all cases. |
| 35 |
permutation s1_begin s1_tab_lookup s2_grant s2_auth s2_truncate s1_commit s2_reset |
| 36 |
permutation s1_begin s2_grant s2_auth s2_truncate s1_tab_lookup s1_commit s2_reset |
| 37 |
permutation s1_begin s2_grant s2_auth s1_tab_lookup s2_truncate s1_commit s2_reset |
| 38 |
permutation s2_grant s2_auth s2_truncate s1_begin s1_tab_lookup s1_commit s2_reset |