From 45e727dd4265baf338c641dd1460ed222be1a68a Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 22 Mar 2023 16:47:09 -0700
Subject: [PATCH] epq-delete-returning spec test

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 .../isolation/expected/eval-plan-qual2.out    | 37 +++++++++++++++++++
 src/test/isolation/isolation_schedule         |  1 +
 src/test/isolation/specs/eval-plan-qual2.spec | 25 +++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 src/test/isolation/expected/eval-plan-qual2.out
 create mode 100644 src/test/isolation/specs/eval-plan-qual2.spec

diff --git a/src/test/isolation/expected/eval-plan-qual2.out b/src/test/isolation/expected/eval-plan-qual2.out
new file mode 100644
index 00000000000..66ffdde3279
--- /dev/null
+++ b/src/test/isolation/expected/eval-plan-qual2.out
@@ -0,0 +1,37 @@
+Parsed test spec with 3 sessions
+
+starting permutation: read_u wx2 wb1 c2 c1 read_u read
+step read_u: SELECT * FROM accounts
+accountid|balance|balance2
+---------+-------+--------
+checking |    600|    1200
+savings  |    600|    1200
+(2 rows)
+
+step wx2: UPDATE accounts SET balance = balance + 450 WHERE accountid = 'checking' RETURNING balance;
+balance
+-------
+   1050
+(1 row)
+
+step wb1: DELETE FROM accounts WHERE balance = 600 RETURNING *; <waiting ...>
+step c2: COMMIT;
+step wb1: <... completed>
+accountid|balance|balance2
+---------+-------+--------
+savings  |    600|    1200
+(1 row)
+
+step c1: COMMIT;
+step read_u: SELECT * FROM accounts
+accountid|balance|balance2
+---------+-------+--------
+checking |   1050|    2100
+(1 row)
+
+step read: SELECT * FROM accounts ORDER BY accountid;
+accountid|balance|balance2
+---------+-------+--------
+checking |   1050|    2100
+(1 row)
+
diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule
index 4fc56ae99c9..029f7da674f 100644
--- a/src/test/isolation/isolation_schedule
+++ b/src/test/isolation/isolation_schedule
@@ -1,3 +1,4 @@
+test: eval-plan-qual2
 test: read-only-anomaly
 test: read-only-anomaly-2
 test: read-only-anomaly-3
diff --git a/src/test/isolation/specs/eval-plan-qual2.spec b/src/test/isolation/specs/eval-plan-qual2.spec
new file mode 100644
index 00000000000..4dae3193ca0
--- /dev/null
+++ b/src/test/isolation/specs/eval-plan-qual2.spec
@@ -0,0 +1,25 @@
+setup
+{
+ CREATE TABLE accounts (accountid text PRIMARY KEY, balance numeric not null,
+   balance2 numeric GENERATED ALWAYS AS (balance * 2) STORED);
+ INSERT INTO accounts VALUES ('checking', 600), ('savings', 600);
+}
+
+
+session s1
+setup		{ BEGIN ISOLATION LEVEL READ COMMITTED; }
+step wb1	{ DELETE FROM accounts WHERE balance = 600 RETURNING *; }
+step c1		{ COMMIT; }
+
+session s2
+setup		{ BEGIN ISOLATION LEVEL READ COMMITTED; }
+step wx2	{ UPDATE accounts SET balance = balance + 450 WHERE accountid = 'checking' RETURNING balance; }
+step c2	{ COMMIT; }
+
+session s3
+setup		{ BEGIN ISOLATION LEVEL READ COMMITTED; }
+step read	{ SELECT * FROM accounts ORDER BY accountid; }
+step read_u	{ SELECT * FROM accounts }
+
+
+permutation read_u wx2 wb1 c2 c1 read_u read
-- 
2.38.0

