| 1 |
# Subtransaction overflow |
| 2 |
# |
| 3 |
# This test is designed to cover some code paths which only occur when |
| 4 |
# one transaction has overflowed the subtransaction cache. |
| 5 |
|
| 6 |
setup |
| 7 |
{ |
| 8 |
DROP TABLE IF EXISTS subxids; |
| 9 |
CREATE TABLE subxids (subx integer, val integer); |
| 10 |
|
| 11 |
CREATE OR REPLACE FUNCTION gen_subxids (n integer) |
| 12 |
RETURNS VOID |
| 13 |
LANGUAGE plpgsql |
| 14 |
AS $$ |
| 15 |
BEGIN |
| 16 |
IF n <= 0 THEN |
| 17 |
UPDATE subxids SET val = 1 WHERE subx = 0; |
| 18 |
RETURN; |
| 19 |
ELSE |
| 20 |
PERFORM gen_subxids(n - 1); |
| 21 |
RETURN; |
| 22 |
END IF; |
| 23 |
EXCEPTION /* generates a subxid */ |
| 24 |
WHEN raise_exception THEN NULL; |
| 25 |
END; |
| 26 |
$$; |
| 27 |
} |
| 28 |
|
| 29 |
teardown |
| 30 |
{ |
| 31 |
DROP TABLE subxids; |
| 32 |
DROP FUNCTION gen_subxids(integer); |
| 33 |
} |
| 34 |
|
| 35 |
session s1 |
| 36 |
# setup step for each test |
| 37 |
step ins { TRUNCATE subxids; INSERT INTO subxids VALUES (0, 0); } |
| 38 |
# long running transaction with overflowed subxids |
| 39 |
step subxov { BEGIN; SELECT gen_subxids(100); } |
| 40 |
# commit should always come last to make this long running |
| 41 |
step s1c { COMMIT; } |
| 42 |
|
| 43 |
session s2 |
| 44 |
# move xmax forwards |
| 45 |
step xmax { BEGIN; INSERT INTO subxids VALUES (99, 0); COMMIT;} |
| 46 |
|
| 47 |
# step for test1 |
| 48 |
step s2sel { SELECT val FROM subxids WHERE subx = 0; } |
| 49 |
|
| 50 |
# steps for test2 |
| 51 |
step s2brr { BEGIN ISOLATION LEVEL REPEATABLE READ; } |
| 52 |
step s2brc { BEGIN ISOLATION LEVEL READ COMMITTED; } |
| 53 |
# look for data written by sub3 |
| 54 |
step s2s3 { SELECT val FROM subxids WHERE subx = 1; } |
| 55 |
step s2c { COMMIT; } |
| 56 |
|
| 57 |
# step for test3 |
| 58 |
step s2upd { UPDATE subxids SET val = 1 WHERE subx = 0; } |
| 59 |
|
| 60 |
session s3 |
| 61 |
# transaction with subxids that can commit before s1c |
| 62 |
step sub3 { BEGIN; SAVEPOINT s; INSERT INTO subxids VALUES (1, 0); } |
| 63 |
step s3c { COMMIT; } |
| 64 |
|
| 65 |
# test1 |
| 66 |
# s2sel will see subxid as still running |
| 67 |
# designed to test XidInMVCCSnapshot() when overflows, xid is found |
| 68 |
permutation ins subxov xmax s2sel s1c |
| 69 |
|
| 70 |
# test2 |
| 71 |
# designed to test XidInMVCCSnapshot() when overflows, xid is not found |
| 72 |
# both SELECTs invisible |
| 73 |
permutation ins subxov sub3 xmax s2brr s2s3 s3c s2s3 s2c s1c |
| 74 |
# 2nd SELECT visible after commit |
| 75 |
permutation ins subxov sub3 xmax s2brc s2s3 s3c s2s3 s2c s1c |
| 76 |
|
| 77 |
# test3 |
| 78 |
# designed to test XactLockTableWait() for overflows |
| 79 |
permutation ins subxov xmax s2upd s1c |