# LogicTest: default parallel-stmts distsql

# Prevents regression of #4293: We used the commit timestamp candidate instead
# of the original timestamp for reads, which means that transactions were
# changing their snapshot while they were active, which is wildly inconsistent.

statement ok
CREATE TABLE t (a INT)

statement ok
GRANT ALL on t TO testuser

# UserA starts the first transaction.
statement ok
BEGIN TRANSACTION ISOLATION LEVEL SNAPSHOT

# The SELECT forces the timestamp to be chosen.
query I
SELECT * FROM t
----

# UserB starts a transaction and inserts into the table.
# TransactionB operates at a timestamp higher than TransactionA since we're
# single-node and TransactionA has already picked its timestamp.
user testuser

# This insert will never become visible to TransactionA since it isn't present
# in its snapshot.
statement ok
INSERT INTO t VALUES (1)

# Touch all (relevant) keys with a timestamp ahead of TransactionA. This means
# that future attempts of TransactionA to write with its original timestamp
# must push TransactionA in the future.
query I
SELECT * FROM t
----
1

user root

# This insert forces TransactionA's timestamp ahead of that of TransactionB.
statement ok
INSERT INTO t VALUES (2)

# The read is carried out at the original timestamp, not the pushed one;
# consequently, we see only our own write.
query I
SELECT * FROM t
----
2

statement ok
COMMIT
