-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sequences: Fixing concurrent "NEXT VALUE FOR" (#143)
This fixes a bug where concurrent transactions using "NEXT VALUE FOR" would make the sequence invisible to the other concurrent transaction. The properties of a sequence (such as the `INCREMENT BY`, etc) are held in the same record as the next value. Since the next value of a sequence needs to be atomic (and separate from the transaction isolation) a `ROLLBACK` on a transaction that contains an `ALTER SEQUENCE` will not undo any changes. Ideally, the properties of a `SEQUENCE` can be stored in a separate location on disk. However, for now it's a documented limitation.
- Loading branch information
1 parent
a1d68d2
commit b503d7f
Showing
4 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
CREATE SEQUENCE seq1; | ||
CREATE TABLE bar (baz INTEGER); | ||
INSERT INTO bar (baz) VALUES (NEXT VALUE FOR seq1); | ||
INSERT INTO bar (baz) VALUES (NEXT VALUE FOR seq1); | ||
SELECT * FROM bar; | ||
UPDATE bar SET baz = NEXT VALUE FOR seq1; | ||
SELECT * FROM bar; | ||
-- msg: CREATE SEQUENCE 1 | ||
-- msg: CREATE TABLE 1 | ||
-- msg: INSERT 1 | ||
-- msg: INSERT 1 | ||
-- BAZ: 1 | ||
-- BAZ: 2 | ||
-- msg: UPDATE 2 | ||
-- BAZ: 3 | ||
-- BAZ: 4 | ||
|
||
/* connection 1 */ | ||
CREATE SEQUENCE seq1; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
/* connection 2 */ | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
/* connection 3 */ | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
-- 1: msg: CREATE SEQUENCE 1 | ||
-- 1: COL1: 1 COL2: 2 | ||
-- 2: COL1: 3 COL2: 4 | ||
-- 3: COL1: 5 COL2: 6 | ||
|
||
/* connection 1 */ | ||
CREATE SEQUENCE seq1; | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
COMMIT; | ||
/* connection 2 */ | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
COMMIT; | ||
/* connection 3 */ | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
COMMIT; | ||
-- 1: msg: CREATE SEQUENCE 1 | ||
-- 1: msg: START TRANSACTION | ||
-- 1: COL1: 1 COL2: 2 | ||
-- 1: msg: COMMIT | ||
-- 2: msg: START TRANSACTION | ||
-- 2: COL1: 3 COL2: 4 | ||
-- 2: msg: COMMIT | ||
-- 3: msg: START TRANSACTION | ||
-- 3: COL1: 5 COL2: 6 | ||
-- 3: msg: COMMIT | ||
|
||
/* connection 1 */ | ||
CREATE SEQUENCE seq1; | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
ROLLBACK; | ||
/* connection 2 */ | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
ROLLBACK; | ||
/* connection 3 */ | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
ROLLBACK; | ||
-- 1: msg: CREATE SEQUENCE 1 | ||
-- 1: msg: START TRANSACTION | ||
-- 1: COL1: 1 COL2: 2 | ||
-- 1: msg: ROLLBACK | ||
-- 2: msg: START TRANSACTION | ||
-- 2: COL1: 3 COL2: 4 | ||
-- 2: msg: ROLLBACK | ||
-- 3: msg: START TRANSACTION | ||
-- 3: COL1: 5 COL2: 6 | ||
-- 3: msg: ROLLBACK | ||
|
||
/* connection 1 */ | ||
CREATE SEQUENCE seq1; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
ROLLBACK; | ||
/* connection 2 */ | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
START TRANSACTION; | ||
/* connection 1 */ | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
/* connection 2 */ | ||
COMMIT; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
-- 1: msg: CREATE SEQUENCE 1 | ||
-- 1: COL1: 1 COL2: 2 | ||
-- 1: msg: START TRANSACTION | ||
-- 1: COL1: 3 COL2: 4 | ||
-- 1: msg: ROLLBACK | ||
-- 2: COL1: 5 COL2: 6 | ||
-- 2: msg: START TRANSACTION | ||
-- 1: COL1: 7 COL2: 8 | ||
-- 2: msg: COMMIT | ||
-- 2: COL1: 9 COL2: 10 | ||
|
||
/* connection 1 */ | ||
CREATE SEQUENCE seq1; | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
/* connection 2 */ | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
/* connection 3 */ | ||
START TRANSACTION; | ||
VALUES NEXT VALUE FOR seq1, NEXT VALUE FOR seq1; | ||
/* connection 1 */ | ||
COMMIT; | ||
/* connection 2 */ | ||
COMMIT; | ||
/* connection 3 */ | ||
COMMIT; | ||
-- 1: msg: CREATE SEQUENCE 1 | ||
-- 1: msg: START TRANSACTION | ||
-- 1: COL1: 1 COL2: 2 | ||
-- 2: msg: START TRANSACTION | ||
-- 2: COL1: 3 COL2: 4 | ||
-- 3: msg: START TRANSACTION | ||
-- 3: COL1: 5 COL2: 6 | ||
-- 1: msg: COMMIT | ||
-- 2: msg: COMMIT | ||
-- 3: msg: COMMIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters