2 -- Tests for some likely failure cases with combo cmin/cmax mechanism
4 CREATE TEMP TABLE combocidtest (foobar int);
6 -- a few dummy ops to push up the CommandId counter
7 INSERT INTO combocidtest SELECT 1 LIMIT 0;
8 INSERT INTO combocidtest SELECT 1 LIMIT 0;
9 INSERT INTO combocidtest SELECT 1 LIMIT 0;
10 INSERT INTO combocidtest SELECT 1 LIMIT 0;
11 INSERT INTO combocidtest SELECT 1 LIMIT 0;
12 INSERT INTO combocidtest SELECT 1 LIMIT 0;
13 INSERT INTO combocidtest SELECT 1 LIMIT 0;
14 INSERT INTO combocidtest SELECT 1 LIMIT 0;
15 INSERT INTO combocidtest SELECT 1 LIMIT 0;
16 INSERT INTO combocidtest SELECT 1 LIMIT 0;
17 INSERT INTO combocidtest VALUES (1);
18 INSERT INTO combocidtest VALUES (2);
19 SELECT ctid,cmin,* FROM combocidtest;
21 -------+------+--------
27 UPDATE combocidtest SET foobar = foobar + 10;
28 -- here we should see only updated tuples
29 SELECT ctid,cmin,* FROM combocidtest;
31 -------+------+--------
37 -- now we should see old tuples, but with combo CIDs starting at 0
38 SELECT ctid,cmin,* FROM combocidtest;
40 -------+------+--------
46 -- combo data is not there anymore, but should still see tuples
47 SELECT ctid,cmin,* FROM combocidtest;
49 -------+------+--------
54 -- Test combo CIDs with portals
56 INSERT INTO combocidtest VALUES (333);
57 DECLARE c CURSOR FOR SELECT ctid,cmin,* FROM combocidtest;
58 DELETE FROM combocidtest;
61 -------+------+--------
68 SELECT ctid,cmin,* FROM combocidtest;
70 -------+------+--------
75 -- check behavior with locked tuples
77 -- a few dummy ops to push up the CommandId counter
78 INSERT INTO combocidtest SELECT 1 LIMIT 0;
79 INSERT INTO combocidtest SELECT 1 LIMIT 0;
80 INSERT INTO combocidtest SELECT 1 LIMIT 0;
81 INSERT INTO combocidtest SELECT 1 LIMIT 0;
82 INSERT INTO combocidtest SELECT 1 LIMIT 0;
83 INSERT INTO combocidtest SELECT 1 LIMIT 0;
84 INSERT INTO combocidtest SELECT 1 LIMIT 0;
85 INSERT INTO combocidtest SELECT 1 LIMIT 0;
86 INSERT INTO combocidtest SELECT 1 LIMIT 0;
87 INSERT INTO combocidtest SELECT 1 LIMIT 0;
88 INSERT INTO combocidtest VALUES (444);
89 SELECT ctid,cmin,* FROM combocidtest;
91 -------+------+--------
98 -- this doesn't affect cmin
99 SELECT ctid,cmin,* FROM combocidtest FOR UPDATE;
101 -------+------+--------
107 SELECT ctid,cmin,* FROM combocidtest;
109 -------+------+--------
116 UPDATE combocidtest SET foobar = foobar + 10;
117 SELECT ctid,cmin,* FROM combocidtest;
119 -------+------+--------
126 SELECT ctid,cmin,* FROM combocidtest;
128 -------+------+--------
135 SELECT ctid,cmin,* FROM combocidtest;
137 -------+------+--------
143 -- test for bug reported in
144 -- CABRT9RC81YUf1=jsmWopcKJEro=VoeG2ou6sPwyOUTx_qteRsg@mail.gmail.com
145 CREATE TABLE IF NOT EXISTS testcase(
149 INSERT INTO testcase VALUES (1, 0);
151 SELECT * FROM testcase WHERE testcase.id = 1 FOR UPDATE;
157 UPDATE testcase SET balance = balance + 400 WHERE id=1;
159 UPDATE testcase SET balance = balance - 100 WHERE id=1;
160 ROLLBACK TO SAVEPOINT subxact;
161 -- should return one tuple
162 SELECT * FROM testcase WHERE id = 1 FOR UPDATE;