| 1 |
# GRANT's lock is the catalog tuple xmax. GRANT doesn't acquire a heavyweight |
| 2 |
# lock on the object undergoing an ACL change. Inplace updates, such as |
| 3 |
# relhasindex=true, need special code to cope. |
| 4 |
|
| 5 |
setup |
| 6 |
{ |
| 7 |
CREATE TABLE intra_grant_inplace (c int); |
| 8 |
} |
| 9 |
|
| 10 |
teardown |
| 11 |
{ |
| 12 |
DROP TABLE IF EXISTS intra_grant_inplace; |
| 13 |
} |
| 14 |
|
| 15 |
# heap_update() |
| 16 |
session s1 |
| 17 |
setup { SET deadlock_timeout = '100s'; } |
| 18 |
step b1 { BEGIN; } |
| 19 |
step grant1 { |
| 20 |
GRANT SELECT ON intra_grant_inplace TO PUBLIC; |
| 21 |
} |
| 22 |
step drop1 { |
| 23 |
DELETE FROM pg_class WHERE relname = 'intra_grant_inplace'; |
| 24 |
} |
| 25 |
step c1 { COMMIT; } |
| 26 |
|
| 27 |
# inplace update |
| 28 |
session s2 |
| 29 |
setup { SET deadlock_timeout = '10ms'; } |
| 30 |
step read2 { |
| 31 |
SELECT relhasindex FROM pg_class |
| 32 |
WHERE oid = 'intra_grant_inplace'::regclass; |
| 33 |
} |
| 34 |
step b2 { BEGIN; } |
| 35 |
step addk2 { ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c); } |
| 36 |
step sfnku2 { |
| 37 |
SELECT relhasindex FROM pg_class |
| 38 |
WHERE oid = 'intra_grant_inplace'::regclass FOR NO KEY UPDATE; |
| 39 |
} |
| 40 |
step c2 { COMMIT; } |
| 41 |
|
| 42 |
# rowmarks |
| 43 |
session s3 |
| 44 |
step b3 { BEGIN ISOLATION LEVEL READ COMMITTED; } |
| 45 |
step sfnku3 { |
| 46 |
SELECT relhasindex FROM pg_class |
| 47 |
WHERE oid = 'intra_grant_inplace'::regclass FOR NO KEY UPDATE; |
| 48 |
} |
| 49 |
step sfu3 { |
| 50 |
SELECT relhasindex FROM pg_class |
| 51 |
WHERE oid = 'intra_grant_inplace'::regclass FOR UPDATE; |
| 52 |
} |
| 53 |
step r3 { ROLLBACK; } |
| 54 |
|
| 55 |
# Additional heap_update() |
| 56 |
session s4 |
| 57 |
# swallow error message to keep any OID value out of expected output |
| 58 |
step revoke4 { |
| 59 |
DO $$ |
| 60 |
BEGIN |
| 61 |
REVOKE SELECT ON intra_grant_inplace FROM PUBLIC; |
| 62 |
EXCEPTION WHEN others THEN |
| 63 |
RAISE WARNING 'got: %', regexp_replace(sqlerrm, '[0-9]+', 'REDACTED'); |
| 64 |
END |
| 65 |
$$; |
| 66 |
} |
| 67 |
|
| 68 |
# Additional rowmarks |
| 69 |
session s5 |
| 70 |
setup { BEGIN; } |
| 71 |
step keyshr5 { |
| 72 |
SELECT relhasindex FROM pg_class |
| 73 |
WHERE oid = 'intra_grant_inplace'::regclass FOR KEY SHARE; |
| 74 |
} |
| 75 |
teardown { ROLLBACK; } |
| 76 |
|
| 77 |
|
| 78 |
permutation |
| 79 |
b1 |
| 80 |
grant1 |
| 81 |
read2 |
| 82 |
addk2(c1) # inplace waits |
| 83 |
c1 |
| 84 |
read2 |
| 85 |
|
| 86 |
# inplace thru KEY SHARE |
| 87 |
permutation |
| 88 |
keyshr5 |
| 89 |
addk2 |
| 90 |
|
| 91 |
# inplace wait NO KEY UPDATE w/ KEY SHARE |
| 92 |
permutation |
| 93 |
keyshr5 |
| 94 |
b3 |
| 95 |
sfnku3 |
| 96 |
addk2(r3) |
| 97 |
r3 |
| 98 |
|
| 99 |
# reproduce bug in DoesMultiXactIdConflict() call |
| 100 |
permutation |
| 101 |
b3 |
| 102 |
sfnku3 |
| 103 |
keyshr5 |
| 104 |
addk2(r3) |
| 105 |
r3 |
| 106 |
|
| 107 |
# same-xact rowmark |
| 108 |
permutation |
| 109 |
b2 |
| 110 |
sfnku2 |
| 111 |
addk2 |
| 112 |
c2 |
| 113 |
|
| 114 |
# same-xact rowmark in multixact |
| 115 |
permutation |
| 116 |
keyshr5 |
| 117 |
b2 |
| 118 |
sfnku2 |
| 119 |
addk2 |
| 120 |
c2 |
| 121 |
|
| 122 |
permutation |
| 123 |
b3 |
| 124 |
sfu3 |
| 125 |
b1 |
| 126 |
grant1(r3) # acquire LockTuple(), await sfu3 xmax |
| 127 |
read2 |
| 128 |
addk2(c1) # block in LockTuple() behind grant1 |
| 129 |
r3 # unblock grant1; addk2 now awaits grant1 xmax |
| 130 |
c1 |
| 131 |
read2 |
| 132 |
|
| 133 |
permutation |
| 134 |
b2 |
| 135 |
sfnku2 |
| 136 |
b1 |
| 137 |
grant1(addk2) # acquire LockTuple(), await sfnku2 xmax |
| 138 |
addk2(*) # block in LockTuple() behind grant1 = deadlock |
| 139 |
c2 |
| 140 |
c1 |
| 141 |
read2 |
| 142 |
|
| 143 |
# SearchSysCacheLocked1() calling LockRelease() |
| 144 |
permutation |
| 145 |
b1 |
| 146 |
grant1 |
| 147 |
b3 |
| 148 |
sfu3(c1) # acquire LockTuple(), await grant1 xmax |
| 149 |
revoke4(r3) # block in LockTuple() behind sfu3 |
| 150 |
c1 |
| 151 |
r3 # revoke4 unlocks old tuple and finds new |
| 152 |
|
| 153 |
# SearchSysCacheLocked1() finding a tuple, then no tuple |
| 154 |
permutation |
| 155 |
b1 |
| 156 |
drop1 |
| 157 |
b3 |
| 158 |
sfu3(c1) # acquire LockTuple(), await drop1 xmax |
| 159 |
revoke4(sfu3) # block in LockTuple() behind sfu3 |
| 160 |
c1 # sfu3 locks none; revoke4 unlocks old and finds none |
| 161 |
r3 |