# LogicTest: default parallel-stmts distsql

# This example session documents that a SERIALIZABLE transaction is
# not immediately poisoned when it revisits a Range on which one of
# its intents has had its timestamp pushed. This allows it to continue
# laying down intents in a single pass, despite the certainty that it
# will restart on commit. A SNAPSHOT transaction can proceed and
# commit with its new timestamp.

statement ok
CREATE TABLE t (id INT PRIMARY KEY)

statement ok
INSERT INTO t VALUES (1)

statement ok
GRANT ALL ON t TO testuser

statement ok
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE, PRIORITY LOW

statement ok
INSERT INTO t VALUES (2)

# Switch users and push the above insert to a higher timestamp.
user testuser

statement ok
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE, PRIORITY HIGH

# This pushes the intent.
query I
SELECT * FROM t
----
1

statement ok
COMMIT

# Switch back and observe that we can still read our data - the txn is left
# operational in order to lay down its intents in the first pass.
user root

query I
SELECT * FROM t
----
1
2

# On commit, we should see the retry error.
statement error retry txn.*
COMMIT

# The same type of session for a SNAPSHOT transaction shouldn't be poisoned.
statement ok
BEGIN TRANSACTION ISOLATION LEVEL SNAPSHOT, PRIORITY LOW

statement ok
INSERT INTO t VALUES (2)

user testuser

statement ok
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE, PRIORITY HIGH

# This pushes the intent.
query I
SELECT * FROM t
----
1

statement ok
COMMIT

user root

query I
SELECT * FROM t
----
1
2

statement ok
COMMIT
