summaryrefslogtreecommitdiffstats
path: root/src/test/isolation/specs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/isolation/specs/aborted-keyrevoke.spec46
-rw-r--r--src/test/isolation/specs/alter-table-1.spec170
-rw-r--r--src/test/isolation/specs/alter-table-2.spec79
-rw-r--r--src/test/isolation/specs/alter-table-3.spec79
-rw-r--r--src/test/isolation/specs/alter-table-4.spec37
-rw-r--r--src/test/isolation/specs/async-notify.spec84
-rw-r--r--src/test/isolation/specs/classroom-scheduling.spec29
-rw-r--r--src/test/isolation/specs/create-trigger.spec54
-rw-r--r--src/test/isolation/specs/deadlock-hard.spec79
-rw-r--r--src/test/isolation/specs/deadlock-parallel.spec113
-rw-r--r--src/test/isolation/specs/deadlock-simple.spec29
-rw-r--r--src/test/isolation/specs/deadlock-soft-2.spec43
-rw-r--r--src/test/isolation/specs/deadlock-soft.spec40
-rw-r--r--src/test/isolation/specs/delete-abort-savept-2.spec34
-rw-r--r--src/test/isolation/specs/delete-abort-savept.spec37
-rw-r--r--src/test/isolation/specs/drop-index-concurrently-1.spec41
-rw-r--r--src/test/isolation/specs/eval-plan-qual-trigger.spec410
-rw-r--r--src/test/isolation/specs/eval-plan-qual.spec359
-rw-r--r--src/test/isolation/specs/fk-contention.spec19
-rw-r--r--src/test/isolation/specs/fk-deadlock.spec46
-rw-r--r--src/test/isolation/specs/fk-deadlock2.spec48
-rw-r--r--src/test/isolation/specs/fk-partitioned-1.spec45
-rw-r--r--src/test/isolation/specs/fk-partitioned-2.spec29
-rw-r--r--src/test/isolation/specs/freeze-the-dead.spec56
-rw-r--r--src/test/isolation/specs/index-only-scan.spec46
-rw-r--r--src/test/isolation/specs/inherit-temp.spec78
-rw-r--r--src/test/isolation/specs/insert-conflict-do-nothing-2.spec34
-rw-r--r--src/test/isolation/specs/insert-conflict-do-nothing.spec40
-rw-r--r--src/test/isolation/specs/insert-conflict-do-update-2.spec40
-rw-r--r--src/test/isolation/specs/insert-conflict-do-update-3.spec69
-rw-r--r--src/test/isolation/specs/insert-conflict-do-update.spec39
-rw-r--r--src/test/isolation/specs/insert-conflict-specconflict.spec262
-rw-r--r--src/test/isolation/specs/lock-committed-keyupdate.spec66
-rw-r--r--src/test/isolation/specs/lock-committed-update.spec62
-rw-r--r--src/test/isolation/specs/lock-update-delete.spec61
-rw-r--r--src/test/isolation/specs/lock-update-traversal.spec39
-rw-r--r--src/test/isolation/specs/multiple-cic.spec43
-rw-r--r--src/test/isolation/specs/multiple-row-versions.spec47
-rw-r--r--src/test/isolation/specs/multixact-no-deadlock.spec35
-rw-r--r--src/test/isolation/specs/multixact-no-forget.spec44
-rw-r--r--src/test/isolation/specs/nowait-2.spec37
-rw-r--r--src/test/isolation/specs/nowait-3.spec33
-rw-r--r--src/test/isolation/specs/nowait-4.spec35
-rw-r--r--src/test/isolation/specs/nowait-5.spec57
-rw-r--r--src/test/isolation/specs/nowait.spec25
-rw-r--r--src/test/isolation/specs/partial-index.spec32
-rw-r--r--src/test/isolation/specs/partition-concurrent-attach.spec43
-rw-r--r--src/test/isolation/specs/partition-key-update-1.spec86
-rw-r--r--src/test/isolation/specs/partition-key-update-2.spec45
-rw-r--r--src/test/isolation/specs/partition-key-update-3.spec44
-rw-r--r--src/test/isolation/specs/partition-key-update-4.spec76
-rw-r--r--src/test/isolation/specs/plpgsql-toast.spec178
-rw-r--r--src/test/isolation/specs/predicate-gin.spec115
-rw-r--r--src/test/isolation/specs/predicate-gist.spec117
-rw-r--r--src/test/isolation/specs/predicate-hash.spec122
-rw-r--r--src/test/isolation/specs/predicate-lock-hot-tuple.spec37
-rw-r--r--src/test/isolation/specs/prepared-transactions-cic.spec37
-rw-r--r--src/test/isolation/specs/prepared-transactions.spec1507
-rw-r--r--src/test/isolation/specs/project-manager.spec30
-rw-r--r--src/test/isolation/specs/propagate-lock-delete.spec42
-rw-r--r--src/test/isolation/specs/read-only-anomaly-2.spec42
-rw-r--r--src/test/isolation/specs/read-only-anomaly-3.spec39
-rw-r--r--src/test/isolation/specs/read-only-anomaly.spec38
-rw-r--r--src/test/isolation/specs/read-write-unique-2.spec36
-rw-r--r--src/test/isolation/specs/read-write-unique-3.spec33
-rw-r--r--src/test/isolation/specs/read-write-unique-4.spec48
-rw-r--r--src/test/isolation/specs/read-write-unique.spec39
-rw-r--r--src/test/isolation/specs/receipt-report.spec47
-rw-r--r--src/test/isolation/specs/referential-integrity.spec32
-rw-r--r--src/test/isolation/specs/reindex-concurrently.spec40
-rw-r--r--src/test/isolation/specs/ri-trigger.spec53
-rw-r--r--src/test/isolation/specs/sequence-ddl.spec41
-rw-r--r--src/test/isolation/specs/serializable-parallel-2.spec30
-rw-r--r--src/test/isolation/specs/serializable-parallel.spec47
-rw-r--r--src/test/isolation/specs/simple-write-skew.spec30
-rw-r--r--src/test/isolation/specs/skip-locked-2.spec41
-rw-r--r--src/test/isolation/specs/skip-locked-3.spec36
-rw-r--r--src/test/isolation/specs/skip-locked-4.spec36
-rw-r--r--src/test/isolation/specs/skip-locked.spec28
-rw-r--r--src/test/isolation/specs/temporal-range-integrity.spec38
-rw-r--r--src/test/isolation/specs/timeouts.spec49
-rw-r--r--src/test/isolation/specs/total-cash.spec28
-rw-r--r--src/test/isolation/specs/truncate-conflict.spec38
-rw-r--r--src/test/isolation/specs/tuplelock-conflict.spec63
-rw-r--r--src/test/isolation/specs/tuplelock-partition.spec32
-rw-r--r--src/test/isolation/specs/tuplelock-update.spec37
-rw-r--r--src/test/isolation/specs/tuplelock-upgrade-no-deadlock.spec69
-rw-r--r--src/test/isolation/specs/two-ids.spec40
-rw-r--r--src/test/isolation/specs/update-conflict-out.spec54
-rw-r--r--src/test/isolation/specs/update-locked-tuple.spec38
-rw-r--r--src/test/isolation/specs/vacuum-concurrent-drop.spec45
-rw-r--r--src/test/isolation/specs/vacuum-conflict.spec51
-rw-r--r--src/test/isolation/specs/vacuum-reltuples.spec48
-rw-r--r--src/test/isolation/specs/vacuum-skip-locked.spec61
-rw-r--r--src/test/isolation/specscanner.c2220
-rw-r--r--src/test/isolation/specscanner.l157
96 files changed, 9513 insertions, 0 deletions
diff --git a/src/test/isolation/specs/aborted-keyrevoke.spec b/src/test/isolation/specs/aborted-keyrevoke.spec
new file mode 100644
index 0000000..4f6f902
--- /dev/null
+++ b/src/test/isolation/specs/aborted-keyrevoke.spec
@@ -0,0 +1,46 @@
+# When a tuple that has been updated is locked, the locking command
+# should traverse the update chain; thus, a DELETE should not be able
+# to proceed until the lock has been released.
+
+setup
+{
+ CREATE TABLE foo (
+ key int PRIMARY KEY,
+ value int
+ );
+
+ INSERT INTO foo VALUES (1, 1);
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1s { SAVEPOINT f; }
+step s1u { UPDATE foo SET key = 2; } # obtain KEY REVOKE
+step s1r { ROLLBACK TO f; } # lose KEY REVOKE
+step s1l { SELECT * FROM foo FOR KEY SHARE; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2l { SELECT * FROM foo FOR KEY SHARE; }
+step s2c { COMMIT; }
+
+permutation s1s s1u s1r s1l s1c s2l s2c
+permutation s1s s1u s1r s1l s2l s1c s2c
+permutation s1s s1u s1r s1l s2l s2c s1c
+permutation s1s s1u s1r s2l s1l s1c s2c
+permutation s1s s1u s1r s2l s1l s2c s1c
+permutation s1s s1u s1r s2l s2c s1l s1c
+permutation s1s s1u s2l s1r s1l s1c s2c
+permutation s1s s1u s2l s1r s1l s2c s1c
+permutation s1s s1u s2l s1r s2c s1l s1c
+permutation s1s s2l s1u s2c s1r s1l s1c
+permutation s1s s2l s2c s1u s1r s1l s1c
+permutation s2l s1s s1u s2c s1r s1l s1c
+permutation s2l s1s s2c s1u s1r s1l s1c
+permutation s2l s2c s1s s1u s1r s1l s1c
diff --git a/src/test/isolation/specs/alter-table-1.spec b/src/test/isolation/specs/alter-table-1.spec
new file mode 100644
index 0000000..dfd0ce7
--- /dev/null
+++ b/src/test/isolation/specs/alter-table-1.spec
@@ -0,0 +1,170 @@
+# ALTER TABLE - Add and Validate constraint with concurrent writes
+#
+# VALIDATE allows a minimum of ShareUpdateExclusiveLock
+# so we mix reads with it to see what works or waits
+
+setup
+{
+ CREATE TABLE a (i int PRIMARY KEY);
+ CREATE TABLE b (a_id int);
+ INSERT INTO a VALUES (0), (1), (2), (3);
+ INSERT INTO b SELECT generate_series(1,1000) % 4;
+}
+
+teardown
+{
+ DROP TABLE a, b;
+}
+
+session s1
+step s1 { BEGIN; }
+step at1 { ALTER TABLE b ADD CONSTRAINT bfk FOREIGN KEY (a_id) REFERENCES a (i) NOT VALID; }
+step sc1 { COMMIT; }
+step s2 { BEGIN; }
+step at2 { ALTER TABLE b VALIDATE CONSTRAINT bfk; }
+step sc2 { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step rx1 { SELECT * FROM b WHERE a_id = 1 LIMIT 1; }
+step wx { INSERT INTO b VALUES (0); }
+step rx3 { SELECT * FROM b WHERE a_id = 3 LIMIT 3; }
+step c2 { COMMIT; }
+
+permutation s1 at1 sc1 s2 at2 sc2 rx1 wx rx3 c2
+permutation s1 at1 sc1 s2 at2 rx1 sc2 wx rx3 c2
+permutation s1 at1 sc1 s2 at2 rx1 wx sc2 rx3 c2
+permutation s1 at1 sc1 s2 at2 rx1 wx rx3 sc2 c2
+permutation s1 at1 sc1 s2 at2 rx1 wx rx3 c2 sc2
+permutation s1 at1 sc1 s2 rx1 at2 sc2 wx rx3 c2
+permutation s1 at1 sc1 s2 rx1 at2 wx sc2 rx3 c2
+permutation s1 at1 sc1 s2 rx1 at2 wx rx3 sc2 c2
+permutation s1 at1 sc1 s2 rx1 at2 wx rx3 c2 sc2
+permutation s1 at1 sc1 s2 rx1 wx at2 sc2 rx3 c2
+permutation s1 at1 sc1 s2 rx1 wx at2 rx3 sc2 c2
+permutation s1 at1 sc1 s2 rx1 wx at2 rx3 c2 sc2
+permutation s1 at1 sc1 s2 rx1 wx rx3 at2 sc2 c2
+permutation s1 at1 sc1 s2 rx1 wx rx3 at2 c2 sc2
+permutation s1 at1 sc1 s2 rx1 wx rx3 c2 at2 sc2
+permutation s1 at1 sc1 rx1 s2 at2 sc2 wx rx3 c2
+permutation s1 at1 sc1 rx1 s2 at2 wx sc2 rx3 c2
+permutation s1 at1 sc1 rx1 s2 at2 wx rx3 sc2 c2
+permutation s1 at1 sc1 rx1 s2 at2 wx rx3 c2 sc2
+permutation s1 at1 sc1 rx1 s2 wx at2 sc2 rx3 c2
+permutation s1 at1 sc1 rx1 s2 wx at2 rx3 sc2 c2
+permutation s1 at1 sc1 rx1 s2 wx at2 rx3 c2 sc2
+permutation s1 at1 sc1 rx1 s2 wx rx3 at2 sc2 c2
+permutation s1 at1 sc1 rx1 s2 wx rx3 at2 c2 sc2
+permutation s1 at1 sc1 rx1 s2 wx rx3 c2 at2 sc2
+permutation s1 at1 sc1 rx1 wx s2 at2 sc2 rx3 c2
+permutation s1 at1 sc1 rx1 wx s2 at2 rx3 sc2 c2
+permutation s1 at1 sc1 rx1 wx s2 at2 rx3 c2 sc2
+permutation s1 at1 sc1 rx1 wx s2 rx3 at2 sc2 c2
+permutation s1 at1 sc1 rx1 wx s2 rx3 at2 c2 sc2
+permutation s1 at1 sc1 rx1 wx s2 rx3 c2 at2 sc2
+permutation s1 at1 sc1 rx1 wx rx3 s2 at2 sc2 c2
+permutation s1 at1 sc1 rx1 wx rx3 s2 at2 c2 sc2
+permutation s1 at1 sc1 rx1 wx rx3 s2 c2 at2 sc2
+permutation s1 at1 sc1 rx1 wx rx3 c2 s2 at2 sc2
+permutation s1 at1 rx1 sc1 s2 at2 sc2 wx rx3 c2
+permutation s1 at1 rx1 sc1 s2 at2 wx sc2 rx3 c2
+permutation s1 at1 rx1 sc1 s2 at2 wx rx3 sc2 c2
+permutation s1 at1 rx1 sc1 s2 at2 wx rx3 c2 sc2
+permutation s1 at1 rx1 sc1 s2 wx at2 sc2 rx3 c2
+permutation s1 at1 rx1 sc1 s2 wx at2 rx3 sc2 c2
+permutation s1 at1 rx1 sc1 s2 wx at2 rx3 c2 sc2
+permutation s1 at1 rx1 sc1 s2 wx rx3 at2 sc2 c2
+permutation s1 at1 rx1 sc1 s2 wx rx3 at2 c2 sc2
+permutation s1 at1 rx1 sc1 s2 wx rx3 c2 at2 sc2
+permutation s1 at1 rx1 sc1 wx s2 at2 sc2 rx3 c2
+permutation s1 at1 rx1 sc1 wx s2 at2 rx3 sc2 c2
+permutation s1 at1 rx1 sc1 wx s2 at2 rx3 c2 sc2
+permutation s1 at1 rx1 sc1 wx s2 rx3 at2 sc2 c2
+permutation s1 at1 rx1 sc1 wx s2 rx3 at2 c2 sc2
+permutation s1 at1 rx1 sc1 wx s2 rx3 c2 at2 sc2
+permutation s1 at1 rx1 sc1 wx rx3 s2 at2 sc2 c2
+permutation s1 at1 rx1 sc1 wx rx3 s2 at2 c2 sc2
+permutation s1 at1 rx1 sc1 wx rx3 s2 c2 at2 sc2
+permutation s1 at1 rx1 sc1 wx rx3 c2 s2 at2 sc2
+permutation s1 at1 rx1 wx sc1 s2 at2 sc2 rx3 c2
+permutation s1 at1 rx1 wx sc1 s2 at2 rx3 sc2 c2
+permutation s1 at1 rx1 wx sc1 s2 at2 rx3 c2 sc2
+permutation s1 at1 rx1 wx sc1 s2 rx3 at2 sc2 c2
+permutation s1 at1 rx1 wx sc1 s2 rx3 at2 c2 sc2
+permutation s1 at1 rx1 wx sc1 s2 rx3 c2 at2 sc2
+permutation s1 at1 rx1 wx sc1 rx3 s2 at2 sc2 c2
+permutation s1 at1 rx1 wx sc1 rx3 s2 at2 c2 sc2
+permutation s1 at1 rx1 wx sc1 rx3 s2 c2 at2 sc2
+permutation s1 at1 rx1 wx sc1 rx3 c2 s2 at2 sc2
+permutation s1 rx1 at1 sc1 s2 at2 sc2 wx rx3 c2
+permutation s1 rx1 at1 sc1 s2 at2 wx sc2 rx3 c2
+permutation s1 rx1 at1 sc1 s2 at2 wx rx3 sc2 c2
+permutation s1 rx1 at1 sc1 s2 at2 wx rx3 c2 sc2
+permutation s1 rx1 at1 sc1 s2 wx at2 sc2 rx3 c2
+permutation s1 rx1 at1 sc1 s2 wx at2 rx3 sc2 c2
+permutation s1 rx1 at1 sc1 s2 wx at2 rx3 c2 sc2
+permutation s1 rx1 at1 sc1 s2 wx rx3 at2 sc2 c2
+permutation s1 rx1 at1 sc1 s2 wx rx3 at2 c2 sc2
+permutation s1 rx1 at1 sc1 s2 wx rx3 c2 at2 sc2
+permutation s1 rx1 at1 sc1 wx s2 at2 sc2 rx3 c2
+permutation s1 rx1 at1 sc1 wx s2 at2 rx3 sc2 c2
+permutation s1 rx1 at1 sc1 wx s2 at2 rx3 c2 sc2
+permutation s1 rx1 at1 sc1 wx s2 rx3 at2 sc2 c2
+permutation s1 rx1 at1 sc1 wx s2 rx3 at2 c2 sc2
+permutation s1 rx1 at1 sc1 wx s2 rx3 c2 at2 sc2
+permutation s1 rx1 at1 sc1 wx rx3 s2 at2 sc2 c2
+permutation s1 rx1 at1 sc1 wx rx3 s2 at2 c2 sc2
+permutation s1 rx1 at1 sc1 wx rx3 s2 c2 at2 sc2
+permutation s1 rx1 at1 sc1 wx rx3 c2 s2 at2 sc2
+permutation s1 rx1 at1 wx sc1 s2 at2 sc2 rx3 c2
+permutation s1 rx1 at1 wx sc1 s2 at2 rx3 sc2 c2
+permutation s1 rx1 at1 wx sc1 s2 at2 rx3 c2 sc2
+permutation s1 rx1 at1 wx sc1 s2 rx3 at2 sc2 c2
+permutation s1 rx1 at1 wx sc1 s2 rx3 at2 c2 sc2
+permutation s1 rx1 at1 wx sc1 s2 rx3 c2 at2 sc2
+permutation s1 rx1 at1 wx sc1 rx3 s2 at2 sc2 c2
+permutation s1 rx1 at1 wx sc1 rx3 s2 at2 c2 sc2
+permutation s1 rx1 at1 wx sc1 rx3 s2 c2 at2 sc2
+permutation s1 rx1 at1 wx sc1 rx3 c2 s2 at2 sc2
+permutation s1 rx1 wx at1 rx3 c2 sc1 s2 at2 sc2
+permutation s1 rx1 wx rx3 at1 c2 sc1 s2 at2 sc2
+permutation s1 rx1 wx rx3 c2 at1 sc1 s2 at2 sc2
+permutation rx1 s1 at1 sc1 s2 at2 sc2 wx rx3 c2
+permutation rx1 s1 at1 sc1 s2 at2 wx sc2 rx3 c2
+permutation rx1 s1 at1 sc1 s2 at2 wx rx3 sc2 c2
+permutation rx1 s1 at1 sc1 s2 at2 wx rx3 c2 sc2
+permutation rx1 s1 at1 sc1 s2 wx at2 sc2 rx3 c2
+permutation rx1 s1 at1 sc1 s2 wx at2 rx3 sc2 c2
+permutation rx1 s1 at1 sc1 s2 wx at2 rx3 c2 sc2
+permutation rx1 s1 at1 sc1 s2 wx rx3 at2 sc2 c2
+permutation rx1 s1 at1 sc1 s2 wx rx3 at2 c2 sc2
+permutation rx1 s1 at1 sc1 s2 wx rx3 c2 at2 sc2
+permutation rx1 s1 at1 sc1 wx s2 at2 sc2 rx3 c2
+permutation rx1 s1 at1 sc1 wx s2 at2 rx3 sc2 c2
+permutation rx1 s1 at1 sc1 wx s2 at2 rx3 c2 sc2
+permutation rx1 s1 at1 sc1 wx s2 rx3 at2 sc2 c2
+permutation rx1 s1 at1 sc1 wx s2 rx3 at2 c2 sc2
+permutation rx1 s1 at1 sc1 wx s2 rx3 c2 at2 sc2
+permutation rx1 s1 at1 sc1 wx rx3 s2 at2 sc2 c2
+permutation rx1 s1 at1 sc1 wx rx3 s2 at2 c2 sc2
+permutation rx1 s1 at1 sc1 wx rx3 s2 c2 at2 sc2
+permutation rx1 s1 at1 sc1 wx rx3 c2 s2 at2 sc2
+permutation rx1 s1 at1 wx sc1 s2 at2 sc2 rx3 c2
+permutation rx1 s1 at1 wx sc1 s2 at2 rx3 sc2 c2
+permutation rx1 s1 at1 wx sc1 s2 at2 rx3 c2 sc2
+permutation rx1 s1 at1 wx sc1 s2 rx3 at2 sc2 c2
+permutation rx1 s1 at1 wx sc1 s2 rx3 at2 c2 sc2
+permutation rx1 s1 at1 wx sc1 s2 rx3 c2 at2 sc2
+permutation rx1 s1 at1 wx sc1 rx3 s2 at2 sc2 c2
+permutation rx1 s1 at1 wx sc1 rx3 s2 at2 c2 sc2
+permutation rx1 s1 at1 wx sc1 rx3 s2 c2 at2 sc2
+permutation rx1 s1 at1 wx sc1 rx3 c2 s2 at2 sc2
+permutation rx1 s1 wx at1 rx3 c2 sc1 s2 at2 sc2
+permutation rx1 s1 wx rx3 at1 c2 sc1 s2 at2 sc2
+permutation rx1 s1 wx rx3 c2 at1 sc1 s2 at2 sc2
+permutation rx1 wx s1 at1 rx3 c2 sc1 s2 at2 sc2
+permutation rx1 wx s1 rx3 at1 c2 sc1 s2 at2 sc2
+permutation rx1 wx s1 rx3 c2 at1 sc1 s2 at2 sc2
+permutation rx1 wx rx3 s1 at1 c2 sc1 s2 at2 sc2
+permutation rx1 wx rx3 s1 c2 at1 sc1 s2 at2 sc2
+permutation rx1 wx rx3 c2 s1 at1 sc1 s2 at2 sc2
diff --git a/src/test/isolation/specs/alter-table-2.spec b/src/test/isolation/specs/alter-table-2.spec
new file mode 100644
index 0000000..a3e3131
--- /dev/null
+++ b/src/test/isolation/specs/alter-table-2.spec
@@ -0,0 +1,79 @@
+# ALTER TABLE - Add foreign keys with concurrent reads
+#
+# ADD CONSTRAINT uses ShareRowExclusiveLock so we mix writes with it
+# to see what works or waits.
+
+setup
+{
+ CREATE TABLE a (i int PRIMARY KEY);
+ CREATE TABLE b (a_id int);
+ INSERT INTO a VALUES (0), (1), (2), (3);
+ INSERT INTO b SELECT generate_series(1,1000) % 4;
+}
+
+teardown
+{
+ DROP TABLE a, b;
+}
+
+session s1
+step s1a { BEGIN; }
+step s1b { ALTER TABLE b ADD CONSTRAINT bfk FOREIGN KEY (a_id) REFERENCES a (i) NOT VALID; }
+step s1c { COMMIT; }
+
+session s2
+step s2a { BEGIN; }
+step s2b { SELECT * FROM a WHERE i = 1 LIMIT 1 FOR UPDATE; }
+step s2c { SELECT * FROM b WHERE a_id = 3 LIMIT 1 FOR UPDATE; }
+step s2d { INSERT INTO b VALUES (0); }
+step s2e { INSERT INTO a VALUES (4); }
+step s2f { COMMIT; }
+
+permutation s1a s1b s1c s2a s2b s2c s2d s2e s2f
+permutation s1a s1b s2a s1c s2b s2c s2d s2e s2f
+permutation s1a s1b s2a s2b s1c s2c s2d s2e s2f
+permutation s1a s1b s2a s2b s2c s1c s2d s2e s2f
+permutation s1a s1b s2a s2b s2c s2d s1c s2e s2f
+permutation s1a s2a s1b s1c s2b s2c s2d s2e s2f
+permutation s1a s2a s1b s2b s1c s2c s2d s2e s2f
+permutation s1a s2a s1b s2b s2c s1c s2d s2e s2f
+permutation s1a s2a s1b s2b s2c s2d s1c s2e s2f
+permutation s1a s2a s2b s1b s1c s2c s2d s2e s2f
+permutation s1a s2a s2b s1b s2c s1c s2d s2e s2f
+permutation s1a s2a s2b s1b s2c s2d s1c s2e s2f
+permutation s1a s2a s2b s2c s1b s1c s2d s2e s2f
+permutation s1a s2a s2b s2c s1b s2d s1c s2e s2f
+permutation s1a s2a s2b s2c s2d s1b s2e s2f s1c
+permutation s1a s2a s2b s2c s2d s2e s1b s2f s1c
+permutation s1a s2a s2b s2c s2d s2e s2f s1b s1c
+permutation s2a s1a s1b s1c s2b s2c s2d s2e s2f
+permutation s2a s1a s1b s2b s1c s2c s2d s2e s2f
+permutation s2a s1a s1b s2b s2c s1c s2d s2e s2f
+permutation s2a s1a s1b s2b s2c s2d s1c s2e s2f
+permutation s2a s1a s2b s1b s1c s2c s2d s2e s2f
+permutation s2a s1a s2b s1b s2c s1c s2d s2e s2f
+permutation s2a s1a s2b s1b s2c s2d s1c s2e s2f
+permutation s2a s1a s2b s2c s1b s1c s2d s2e s2f
+permutation s2a s1a s2b s2c s1b s2d s1c s2e s2f
+permutation s2a s1a s2b s2c s2d s1b s2e s2f s1c
+permutation s2a s1a s2b s2c s2d s2e s1b s2f s1c
+permutation s2a s1a s2b s2c s2d s2e s2f s1b s1c
+permutation s2a s2b s1a s1b s1c s2c s2d s2e s2f
+permutation s2a s2b s1a s1b s2c s1c s2d s2e s2f
+permutation s2a s2b s1a s1b s2c s2d s1c s2e s2f
+permutation s2a s2b s1a s2c s1b s1c s2d s2e s2f
+permutation s2a s2b s1a s2c s1b s2d s1c s2e s2f
+permutation s2a s2b s1a s2c s2d s1b s2e s2f s1c
+permutation s2a s2b s1a s2c s2d s2e s1b s2f s1c
+permutation s2a s2b s1a s2c s2d s2e s2f s1b s1c
+permutation s2a s2b s2c s1a s1b s1c s2d s2e s2f
+permutation s2a s2b s2c s1a s1b s2d s1c s2e s2f
+permutation s2a s2b s2c s1a s2d s1b s2e s2f s1c
+permutation s2a s2b s2c s1a s2d s2e s1b s2f s1c
+permutation s2a s2b s2c s1a s2d s2e s2f s1b s1c
+permutation s2a s2b s2c s2d s1a s1b s2e s2f s1c
+permutation s2a s2b s2c s2d s1a s2e s1b s2f s1c
+permutation s2a s2b s2c s2d s1a s2e s2f s1b s1c
+permutation s2a s2b s2c s2d s2e s1a s1b s2f s1c
+permutation s2a s2b s2c s2d s2e s1a s2f s1b s1c
+permutation s2a s2b s2c s2d s2e s2f s1a s1b s1c
diff --git a/src/test/isolation/specs/alter-table-3.spec b/src/test/isolation/specs/alter-table-3.spec
new file mode 100644
index 0000000..f70d9c0
--- /dev/null
+++ b/src/test/isolation/specs/alter-table-3.spec
@@ -0,0 +1,79 @@
+# ALTER TABLE - Enable and disable triggers with concurrent reads
+#
+# ENABLE/DISABLE TRIGGER uses ShareRowExclusiveLock so we mix writes with
+# it to see what works or waits.
+
+setup
+{
+ CREATE TABLE a (i int PRIMARY KEY);
+ INSERT INTO a VALUES (0), (1), (2), (3);
+ CREATE FUNCTION f() RETURNS TRIGGER LANGUAGE plpgsql AS 'BEGIN RETURN NULL; END;';
+ CREATE TRIGGER t AFTER UPDATE ON a EXECUTE PROCEDURE f();
+}
+
+teardown
+{
+ DROP TABLE a;
+ DROP FUNCTION f();
+}
+
+session s1
+step s1a { BEGIN; }
+step s1b { ALTER TABLE a DISABLE TRIGGER t; }
+step s1c { ALTER TABLE a ENABLE TRIGGER t; }
+step s1d { COMMIT; }
+
+session s2
+step s2a { BEGIN; }
+step s2b { SELECT * FROM a WHERE i = 1 LIMIT 1 FOR UPDATE; }
+step s2c { INSERT INTO a VALUES (0); }
+step s2d { COMMIT; }
+
+permutation s1a s1b s1c s1d s2a s2b s2c s2d
+permutation s1a s1b s1c s2a s1d s2b s2c s2d
+permutation s1a s1b s1c s2a s2b s1d s2c s2d
+permutation s1a s1b s1c s2a s2b s2c s1d s2d
+permutation s1a s1b s2a s1c s1d s2b s2c s2d
+permutation s1a s1b s2a s1c s2b s1d s2c s2d
+permutation s1a s1b s2a s1c s2b s2c s1d s2d
+permutation s1a s1b s2a s2b s1c s1d s2c s2d
+permutation s1a s1b s2a s2b s1c s2c s1d s2d
+permutation s1a s1b s2a s2b s2c s1c s1d s2d
+permutation s1a s2a s1b s1c s1d s2b s2c s2d
+permutation s1a s2a s1b s1c s2b s1d s2c s2d
+permutation s1a s2a s1b s1c s2b s2c s1d s2d
+permutation s1a s2a s1b s2b s1c s1d s2c s2d
+permutation s1a s2a s1b s2b s1c s2c s1d s2d
+permutation s1a s2a s1b s2b s2c s1c s1d s2d
+permutation s1a s2a s2b s1b s1c s1d s2c s2d
+permutation s1a s2a s2b s1b s1c s2c s1d s2d
+permutation s1a s2a s2b s1b s2c s1c s1d s2d
+permutation s1a s2a s2b s2c s1b s1c s1d s2d
+permutation s1a s2a s2b s2c s1b s1c s2d s1d
+permutation s1a s2a s2b s2c s1b s2d s1c s1d
+permutation s1a s2a s2b s2c s2d s1b s1c s1d
+permutation s2a s1a s1b s1c s1d s2b s2c s2d
+permutation s2a s1a s1b s1c s2b s1d s2c s2d
+permutation s2a s1a s1b s1c s2b s2c s1d s2d
+permutation s2a s1a s1b s2b s1c s1d s2c s2d
+permutation s2a s1a s1b s2b s1c s2c s1d s2d
+permutation s2a s1a s1b s2b s2c s1c s1d s2d
+permutation s2a s1a s2b s1b s1c s1d s2c s2d
+permutation s2a s1a s2b s1b s1c s2c s1d s2d
+permutation s2a s1a s2b s1b s2c s1c s1d s2d
+permutation s2a s1a s2b s2c s1b s1c s1d s2d
+permutation s2a s1a s2b s2c s1b s1c s2d s1d
+permutation s2a s1a s2b s2c s1b s2d s1c s1d
+permutation s2a s1a s2b s2c s2d s1b s1c s1d
+permutation s2a s2b s1a s1b s1c s1d s2c s2d
+permutation s2a s2b s1a s1b s1c s2c s1d s2d
+permutation s2a s2b s1a s1b s2c s1c s1d s2d
+permutation s2a s2b s1a s2c s1b s1c s1d s2d
+permutation s2a s2b s1a s2c s1b s1c s2d s1d
+permutation s2a s2b s1a s2c s1b s2d s1c s1d
+permutation s2a s2b s1a s2c s2d s1b s1c s1d
+permutation s2a s2b s2c s1a s1b s1c s1d s2d
+permutation s2a s2b s2c s1a s1b s1c s2d s1d
+permutation s2a s2b s2c s1a s1b s2d s1c s1d
+permutation s2a s2b s2c s1a s2d s1b s1c s1d
+permutation s2a s2b s2c s2d s1a s1b s1c s1d
diff --git a/src/test/isolation/specs/alter-table-4.spec b/src/test/isolation/specs/alter-table-4.spec
new file mode 100644
index 0000000..f143b79
--- /dev/null
+++ b/src/test/isolation/specs/alter-table-4.spec
@@ -0,0 +1,37 @@
+# ALTER TABLE - Add and remove inheritance with concurrent reads
+
+setup
+{
+ CREATE TABLE p (a integer);
+ INSERT INTO p VALUES(1);
+ CREATE TABLE c1 () INHERITS (p);
+ INSERT INTO c1 VALUES(10);
+ CREATE TABLE c2 (a integer);
+ INSERT INTO c2 VALUES(100);
+}
+
+teardown
+{
+ DROP TABLE IF EXISTS c1, c2, p;
+}
+
+session s1
+step s1b { BEGIN; }
+step s1delc1 { ALTER TABLE c1 NO INHERIT p; }
+step s1modc1a { ALTER TABLE c1 ALTER COLUMN a TYPE float; }
+step s1addc2 { ALTER TABLE c2 INHERIT p; }
+step s1dropc1 { DROP TABLE c1; }
+step s1c { COMMIT; }
+
+session s2
+step s2sel { SELECT SUM(a) FROM p; }
+
+# NO INHERIT will not be visible to concurrent select,
+# since we identify children before locking them
+permutation s1b s1delc1 s2sel s1c s2sel
+# adding inheritance likewise is not seen if s1 commits after s2 locks p
+permutation s1b s1delc1 s1addc2 s2sel s1c s2sel
+# but we do cope with DROP on a child table
+permutation s1b s1dropc1 s2sel s1c s2sel
+# this case currently results in an error; doesn't seem worth preventing
+permutation s1b s1delc1 s1modc1a s2sel s1c s2sel
diff --git a/src/test/isolation/specs/async-notify.spec b/src/test/isolation/specs/async-notify.spec
new file mode 100644
index 0000000..0b8cfd9
--- /dev/null
+++ b/src/test/isolation/specs/async-notify.spec
@@ -0,0 +1,84 @@
+# Tests for LISTEN/NOTIFY
+
+# Most of these tests use only the "notifier" session and hence exercise only
+# self-notifies, which are convenient because they minimize timing concerns.
+# Note we assume that each step is delivered to the backend as a single Query
+# message so it will run as one transaction.
+
+session notifier
+step listenc { LISTEN c1; LISTEN c2; }
+step notify1 { NOTIFY c1; }
+step notify2 { NOTIFY c2, 'payload'; }
+step notify3 { NOTIFY c3, 'payload3'; } # not listening to c3
+step notifyf { SELECT pg_notify('c2', NULL); }
+step notifyd1 { NOTIFY c2, 'payload'; NOTIFY c1; NOTIFY "c2", 'payload'; }
+step notifyd2 { NOTIFY c1; NOTIFY c1; NOTIFY c1, 'p1'; NOTIFY c1, 'p2'; }
+step notifys1 {
+ BEGIN;
+ NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
+ NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
+ SAVEPOINT s1;
+ NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
+ NOTIFY c1, 'payloads'; NOTIFY "c2", 'payloads';
+ NOTIFY c1, 'payload'; NOTIFY "c2", 'payload';
+ NOTIFY c1, 'payloads'; NOTIFY "c2", 'payloads';
+ RELEASE SAVEPOINT s1;
+ SAVEPOINT s2;
+ NOTIFY c1, 'rpayload'; NOTIFY "c2", 'rpayload';
+ NOTIFY c1, 'rpayloads'; NOTIFY "c2", 'rpayloads';
+ NOTIFY c1, 'rpayload'; NOTIFY "c2", 'rpayload';
+ NOTIFY c1, 'rpayloads'; NOTIFY "c2", 'rpayloads';
+ ROLLBACK TO SAVEPOINT s2;
+ COMMIT;
+}
+step usage { SELECT pg_notification_queue_usage() > 0 AS nonzero; }
+step bignotify { SELECT count(pg_notify('c1', s::text)) FROM generate_series(1, 1000) s; }
+teardown { UNLISTEN *; }
+
+# The listener session is used for cross-backend notify checks.
+
+session listener
+step llisten { LISTEN c1; LISTEN c2; }
+step lcheck { SELECT 1 AS x; }
+step lbegin { BEGIN; }
+step lbegins { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step lcommit { COMMIT; }
+teardown { UNLISTEN *; }
+
+# In some tests we need a second listener, just to block the queue.
+
+session listener2
+step l2listen { LISTEN c1; }
+step l2begin { BEGIN; }
+step l2commit { COMMIT; }
+step l2stop { UNLISTEN *; }
+
+
+# Trivial cases.
+permutation listenc notify1 notify2 notify3 notifyf
+
+# Check simple and less-simple deduplication.
+permutation listenc notifyd1 notifyd2 notifys1
+
+# Cross-backend notification delivery. We use a "select 1" to force the
+# listener session to check for notifies. In principle we could just wait
+# for delivery, but that would require extra support in isolationtester
+# and might have portability-of-timing issues.
+permutation llisten notify1 notify2 notify3 notifyf lcheck
+
+# Again, with local delivery too.
+permutation listenc llisten notify1 notify2 notify3 notifyf lcheck
+
+# Check for bug when initial listen is only action in a serializable xact,
+# and notify queue is not empty
+permutation l2listen l2begin notify1 lbegins llisten lcommit l2commit l2stop
+
+# Verify that pg_notification_queue_usage correctly reports a non-zero result,
+# after submitting notifications while another connection is listening for
+# those notifications and waiting inside an active transaction. We have to
+# fill a page of the notify SLRU to make this happen, which is a good deal
+# of traffic. To not bloat the expected output, we intentionally don't
+# commit the listener's transaction, so that it never reports these events.
+# Hence, this should be the last test in this script.
+
+permutation llisten lbegin usage bignotify usage
diff --git a/src/test/isolation/specs/classroom-scheduling.spec b/src/test/isolation/specs/classroom-scheduling.spec
new file mode 100644
index 0000000..770715b
--- /dev/null
+++ b/src/test/isolation/specs/classroom-scheduling.spec
@@ -0,0 +1,29 @@
+# Classroom Scheduling test
+#
+# Ensure that the classroom is not scheduled more than once
+# for any moment in time.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE room_reservation (room_id text NOT NULL, start_time timestamp with time zone NOT NULL, end_time timestamp with time zone NOT NULL, description text NOT NULL, CONSTRAINT room_reservation_pkey PRIMARY KEY (room_id, start_time));
+ INSERT INTO room_reservation VALUES ('101', TIMESTAMP WITH TIME ZONE '2010-04-01 10:00', TIMESTAMP WITH TIME ZONE '2010-04-01 11:00', 'Bob');
+}
+
+teardown
+{
+ DROP TABLE room_reservation;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rx1 { SELECT count(*) FROM room_reservation WHERE room_id = '101' AND start_time < TIMESTAMP WITH TIME ZONE '2010-04-01 14:00' AND end_time > TIMESTAMP WITH TIME ZONE '2010-04-01 13:00'; }
+step wy1 { INSERT INTO room_reservation VALUES ('101', TIMESTAMP WITH TIME ZONE '2010-04-01 13:00', TIMESTAMP WITH TIME ZONE '2010-04-01 14:00', 'Carol'); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step ry2 { SELECT count(*) FROM room_reservation WHERE room_id = '101' AND start_time < TIMESTAMP WITH TIME ZONE '2010-04-01 14:30' AND end_time > TIMESTAMP WITH TIME ZONE '2010-04-01 13:30'; }
+step wx2 { UPDATE room_reservation SET start_time = TIMESTAMP WITH TIME ZONE '2010-04-01 13:30', end_time = TIMESTAMP WITH TIME ZONE '2010-04-01 14:30' WHERE room_id = '101' AND start_time = TIMESTAMP WITH TIME ZONE '2010-04-01 10:00'; }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/create-trigger.spec b/src/test/isolation/specs/create-trigger.spec
new file mode 100644
index 0000000..9d4710c
--- /dev/null
+++ b/src/test/isolation/specs/create-trigger.spec
@@ -0,0 +1,54 @@
+# CREATE TRIGGER - Add trigger with concurrent reads
+#
+# CREATE TRIGGER uses ShareRowExclusiveLock so we mix writes with it
+# to see what works or waits.
+
+setup
+{
+ CREATE TABLE a (i int);
+ CREATE FUNCTION f() RETURNS TRIGGER LANGUAGE plpgsql AS 'BEGIN RETURN NULL; END;';
+ INSERT INTO a VALUES (0), (1), (2), (3);
+}
+
+teardown
+{
+ DROP TABLE a;
+ DROP FUNCTION f();
+}
+
+session s1
+step s1a { BEGIN; }
+step s1b { CREATE TRIGGER t AFTER UPDATE ON a EXECUTE PROCEDURE f(); }
+step s1c { COMMIT; }
+
+session s2
+step s2a { BEGIN; }
+step s2b { SELECT * FROM a WHERE i = 1 FOR UPDATE; }
+step s2c { UPDATE a SET i = 4 WHERE i = 3; }
+step s2d { COMMIT; }
+
+permutation s1a s1b s1c s2a s2b s2c s2d
+permutation s1a s1b s2a s1c s2b s2c s2d
+permutation s1a s1b s2a s2b s1c s2c s2d
+permutation s1a s1b s2a s2b s2c s1c s2d
+permutation s1a s2a s1b s1c s2b s2c s2d
+permutation s1a s2a s1b s2b s1c s2c s2d
+permutation s1a s2a s1b s2b s2c s1c s2d
+permutation s1a s2a s2b s1b s1c s2c s2d
+permutation s1a s2a s2b s1b s2c s1c s2d
+permutation s1a s2a s2b s2c s1b s2d s1c
+permutation s1a s2a s2b s2c s2d s1b s1c
+permutation s2a s1a s1b s1c s2b s2c s2d
+permutation s2a s1a s1b s2b s1c s2c s2d
+permutation s2a s1a s1b s2b s2c s1c s2d
+permutation s2a s1a s2b s1b s1c s2c s2d
+permutation s2a s1a s2b s1b s2c s1c s2d
+permutation s2a s1a s2b s2c s1b s2d s1c
+permutation s2a s1a s2b s2c s2d s1b s1c
+permutation s2a s2b s1a s1b s1c s2c s2d
+permutation s2a s2b s1a s1b s2c s1c s2d
+permutation s2a s2b s1a s2c s1b s2d s1c
+permutation s2a s2b s1a s2c s2d s1b s1c
+permutation s2a s2b s2c s1a s1b s2d s1c
+permutation s2a s2b s2c s1a s2d s1b s1c
+permutation s2a s2b s2c s2d s1a s1b s1c
diff --git a/src/test/isolation/specs/deadlock-hard.spec b/src/test/isolation/specs/deadlock-hard.spec
new file mode 100644
index 0000000..60bedca
--- /dev/null
+++ b/src/test/isolation/specs/deadlock-hard.spec
@@ -0,0 +1,79 @@
+# This is a straightforward deadlock scenario. Since it involves more than
+# two processes, the main lock detector will find the problem and rollback
+# the session that first discovers it. Set deadlock_timeout in each session
+# so that it's predictable which session fails.
+
+setup
+{
+ CREATE TABLE a1 ();
+ CREATE TABLE a2 ();
+ CREATE TABLE a3 ();
+ CREATE TABLE a4 ();
+ CREATE TABLE a5 ();
+ CREATE TABLE a6 ();
+ CREATE TABLE a7 ();
+ CREATE TABLE a8 ();
+}
+
+teardown
+{
+ DROP TABLE a1, a2, a3, a4, a5, a6, a7, a8;
+}
+
+session s1
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s1a1 { LOCK TABLE a1; }
+step s1a2 { LOCK TABLE a2; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s2a2 { LOCK TABLE a2; }
+step s2a3 { LOCK TABLE a3; }
+step s2c { COMMIT; }
+
+session s3
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s3a3 { LOCK TABLE a3; }
+step s3a4 { LOCK TABLE a4; }
+step s3c { COMMIT; }
+
+session s4
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s4a4 { LOCK TABLE a4; }
+step s4a5 { LOCK TABLE a5; }
+step s4c { COMMIT; }
+
+session s5
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s5a5 { LOCK TABLE a5; }
+step s5a6 { LOCK TABLE a6; }
+step s5c { COMMIT; }
+
+session s6
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s6a6 { LOCK TABLE a6; }
+step s6a7 { LOCK TABLE a7; }
+step s6c { COMMIT; }
+
+session s7
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s7a7 { LOCK TABLE a7; }
+step s7a8 { LOCK TABLE a8; }
+step s7c { COMMIT; }
+
+session s8
+setup { BEGIN; SET deadlock_timeout = '10ms'; }
+step s8a8 { LOCK TABLE a8; }
+step s8a1 { LOCK TABLE a1; }
+step s8c { COMMIT; }
+
+# Note: when s8a1 detects the deadlock and fails, s7a8 is released, making
+# it timing-dependent which query completion is received first by the tester.
+# To ensure output stability, add a blocking mark to force s8a1's completion
+# to be reported first. There is a second timing dependency, too: the tester
+# might or might not observe s8a1 during its short lock wait state. Apply a
+# dummy blocking mark to s8a1 to ensure it will be reported as "waiting"
+# regardless of that.
+
+permutation s1a1 s2a2 s3a3 s4a4 s5a5 s6a6 s7a7 s8a8 s1a2 s2a3 s3a4 s4a5 s5a6 s6a7 s7a8(s8a1) s8a1(*) s8c s7c s6c s5c s4c s3c s2c s1c
diff --git a/src/test/isolation/specs/deadlock-parallel.spec b/src/test/isolation/specs/deadlock-parallel.spec
new file mode 100644
index 0000000..a050a49
--- /dev/null
+++ b/src/test/isolation/specs/deadlock-parallel.spec
@@ -0,0 +1,113 @@
+# Test deadlock resolution with parallel process groups.
+
+# It's fairly hard to get parallel worker processes to block on locks,
+# since generally they don't want any locks their leader didn't already
+# take. We cheat like mad here by making a function that takes a lock,
+# and is incorrectly marked parallel-safe so that it can execute in a worker.
+
+# Note that we explicitly override any global settings of isolation level
+# or force_parallel_mode, to ensure we're testing what we intend to.
+
+# Otherwise, this is morally equivalent to deadlock-soft.spec:
+# Four-process deadlock with two hard edges and two soft edges.
+# d2 waits for e1 (soft edge), e1 waits for d1 (hard edge),
+# d1 waits for e2 (soft edge), e2 waits for d2 (hard edge).
+# The deadlock detector resolves the deadlock by reversing the d1-e2 edge,
+# unblocking d1.
+
+# However ... it's not actually that well-defined whether the deadlock
+# detector will prefer to unblock d1 or d2. It depends on which backend
+# is first to run DeadLockCheck after the deadlock condition is created:
+# that backend will search outwards from its own wait condition, and will
+# first find a loop involving the *other* lock. We encourage that to be
+# one of the d2a1 parallel workers, which will therefore unblock d1a2
+# workers, by setting a shorter deadlock_timeout in session d2. But on
+# slow machines, one or more d1a2 workers may not yet have reached their
+# lock waits, so that they're not unblocked by the first DeadLockCheck.
+# The next DeadLockCheck may choose to unblock the d2a1 workers instead,
+# which would allow d2a1 to complete before d1a2, causing the test to
+# freeze up because isolationtester isn't expecting that completion order.
+# (In effect, we have an undetectable deadlock because d2 is waiting for
+# d1's completion, but on the client side.) To fix this, introduce an
+# additional lock (advisory lock 3), which is initially taken by d1 and
+# then d2a1 will wait for it after completing the main part of the test.
+# In this way, the deadlock detector can see that d1 must be completed
+# first, regardless of timing.
+
+setup
+{
+ create function lock_share(int,int) returns int language sql as
+ 'select pg_advisory_xact_lock_shared($1); select 1;' parallel safe;
+
+ create function lock_excl(int,int) returns int language sql as
+ 'select pg_advisory_xact_lock($1); select 1;' parallel safe;
+
+ create table bigt as select x from generate_series(1, 10000) x;
+ analyze bigt;
+}
+
+teardown
+{
+ drop function lock_share(int,int);
+ drop function lock_excl(int,int);
+ drop table bigt;
+}
+
+session d1
+setup { BEGIN isolation level repeatable read;
+ SET force_parallel_mode = off;
+ SET deadlock_timeout = '10s';
+}
+# these locks will be taken in the leader, so they will persist:
+step d1a1 { SELECT lock_share(1,x), lock_excl(3,x) FROM bigt LIMIT 1; }
+# this causes all the parallel workers to take locks:
+step d1a2 { SET force_parallel_mode = on;
+ SET parallel_setup_cost = 0;
+ SET parallel_tuple_cost = 0;
+ SET min_parallel_table_scan_size = 0;
+ SET parallel_leader_participation = off;
+ SET max_parallel_workers_per_gather = 3;
+ SELECT sum(lock_share(2,x)) FROM bigt; }
+step d1c { COMMIT; }
+
+session d2
+setup { BEGIN isolation level repeatable read;
+ SET force_parallel_mode = off;
+ SET deadlock_timeout = '10ms';
+}
+# this lock will be taken in the leader, so it will persist:
+step d2a2 { select lock_share(2,x) FROM bigt LIMIT 1; }
+# this causes all the parallel workers to take locks;
+# after which, make the leader take lock 3 to prevent client-driven deadlock
+step d2a1 { SET force_parallel_mode = on;
+ SET parallel_setup_cost = 0;
+ SET parallel_tuple_cost = 0;
+ SET min_parallel_table_scan_size = 0;
+ SET parallel_leader_participation = off;
+ SET max_parallel_workers_per_gather = 3;
+ SELECT sum(lock_share(1,x)) FROM bigt;
+ SET force_parallel_mode = off;
+ RESET parallel_setup_cost;
+ RESET parallel_tuple_cost;
+ SELECT lock_share(3,x) FROM bigt LIMIT 1; }
+step d2c { COMMIT; }
+
+session e1
+setup { BEGIN isolation level repeatable read;
+ SET force_parallel_mode = on;
+ SET deadlock_timeout = '10s';
+}
+# this lock will be taken in a parallel worker, but we don't need it to persist
+step e1l { SELECT lock_excl(1,x) FROM bigt LIMIT 1; }
+step e1c { COMMIT; }
+
+session e2
+setup { BEGIN isolation level repeatable read;
+ SET force_parallel_mode = on;
+ SET deadlock_timeout = '10s';
+}
+# this lock will be taken in a parallel worker, but we don't need it to persist
+step e2l { SELECT lock_excl(2,x) FROM bigt LIMIT 1; }
+step e2c { COMMIT; }
+
+permutation d1a1 d2a2 e1l e2l d1a2 d2a1 d1c e1c d2c e2c
diff --git a/src/test/isolation/specs/deadlock-simple.spec b/src/test/isolation/specs/deadlock-simple.spec
new file mode 100644
index 0000000..3086dc7
--- /dev/null
+++ b/src/test/isolation/specs/deadlock-simple.spec
@@ -0,0 +1,29 @@
+# The deadlock detector has a special case for "simple" deadlocks. A simple
+# deadlock occurs when we attempt a lock upgrade while another process waits
+# for a lock upgrade on the same object; and the sought locks conflict with
+# those already held, so that neither process can complete its upgrade until
+# the other releases locks. Test this scenario.
+
+setup
+{
+ CREATE TABLE a1 ();
+}
+
+teardown
+{
+ DROP TABLE a1;
+}
+
+session s1
+setup { BEGIN; }
+step s1as { LOCK TABLE a1 IN ACCESS SHARE MODE; }
+step s1ae { LOCK TABLE a1 IN ACCESS EXCLUSIVE MODE; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2as { LOCK TABLE a1 IN ACCESS SHARE MODE; }
+step s2ae { LOCK TABLE a1 IN ACCESS EXCLUSIVE MODE; }
+step s2c { COMMIT; }
+
+permutation s1as s2as s1ae s2ae s1c s2c
diff --git a/src/test/isolation/specs/deadlock-soft-2.spec b/src/test/isolation/specs/deadlock-soft-2.spec
new file mode 100644
index 0000000..5b7d3db
--- /dev/null
+++ b/src/test/isolation/specs/deadlock-soft-2.spec
@@ -0,0 +1,43 @@
+# Soft deadlock requiring reversal of multiple wait-edges. s1 must
+# jump over both s3 and s4 and acquire the lock on a2 immediately,
+# since s3 and s4 are hard-blocked on a1.
+
+setup
+{
+ CREATE TABLE a1 ();
+ CREATE TABLE a2 ();
+}
+
+teardown
+{
+ DROP TABLE a1, a2;
+}
+
+session s1
+setup { BEGIN; SET deadlock_timeout = '10ms'; }
+step s1a { LOCK TABLE a1 IN SHARE UPDATE EXCLUSIVE MODE; }
+step s1b { LOCK TABLE a2 IN SHARE UPDATE EXCLUSIVE MODE; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s2a { LOCK TABLE a2 IN ACCESS SHARE MODE; }
+step s2b { LOCK TABLE a1 IN SHARE UPDATE EXCLUSIVE MODE; }
+step s2c { COMMIT; }
+
+session s3
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s3a { LOCK TABLE a2 IN ACCESS EXCLUSIVE MODE; }
+step s3c { COMMIT; }
+
+session s4
+setup { BEGIN; SET deadlock_timeout = '100s'; }
+step s4a { LOCK TABLE a2 IN ACCESS EXCLUSIVE MODE; }
+step s4c { COMMIT; }
+
+# The expected output for this test assumes that isolationtester will
+# detect step s1b as waiting before the deadlock detector runs and
+# releases s1 from its blocked state. To ensure that happens even in
+# very slow (CLOBBER_CACHE_ALWAYS) cases, apply a (*) annotation.
+
+permutation s1a s2a s2b s3a s4a s1b(*) s1c s2c s3c s4c
diff --git a/src/test/isolation/specs/deadlock-soft.spec b/src/test/isolation/specs/deadlock-soft.spec
new file mode 100644
index 0000000..bc9c6a7
--- /dev/null
+++ b/src/test/isolation/specs/deadlock-soft.spec
@@ -0,0 +1,40 @@
+# Four-process deadlock with two hard edges and two soft edges.
+# d2 waits for e1 (soft edge), e1 waits for d1 (hard edge),
+# d1 waits for e2 (soft edge), e2 waits for d2 (hard edge).
+# The deadlock detector resolves the deadlock by reversing the d1-e2 edge,
+# unblocking d1.
+
+setup
+{
+ CREATE TABLE a1 ();
+ CREATE TABLE a2 ();
+}
+
+teardown
+{
+ DROP TABLE a1, a2;
+}
+
+session d1
+setup { BEGIN; SET deadlock_timeout = '10s'; }
+step d1a1 { LOCK TABLE a1 IN ACCESS SHARE MODE; }
+step d1a2 { LOCK TABLE a2 IN ACCESS SHARE MODE; }
+step d1c { COMMIT; }
+
+session d2
+setup { BEGIN; SET deadlock_timeout = '10ms'; }
+step d2a2 { LOCK TABLE a2 IN ACCESS SHARE MODE; }
+step d2a1 { LOCK TABLE a1 IN ACCESS SHARE MODE; }
+step d2c { COMMIT; }
+
+session e1
+setup { BEGIN; SET deadlock_timeout = '10s'; }
+step e1l { LOCK TABLE a1 IN ACCESS EXCLUSIVE MODE; }
+step e1c { COMMIT; }
+
+session e2
+setup { BEGIN; SET deadlock_timeout = '10s'; }
+step e2l { LOCK TABLE a2 IN ACCESS EXCLUSIVE MODE; }
+step e2c { COMMIT; }
+
+permutation d1a1 d2a2 e1l e2l d1a2 d2a1 d1c e1c d2c e2c
diff --git a/src/test/isolation/specs/delete-abort-savept-2.spec b/src/test/isolation/specs/delete-abort-savept-2.spec
new file mode 100644
index 0000000..65bd936
--- /dev/null
+++ b/src/test/isolation/specs/delete-abort-savept-2.spec
@@ -0,0 +1,34 @@
+# A funkier version of delete-abort-savept
+setup
+{
+ CREATE TABLE foo (
+ key INT PRIMARY KEY,
+ value INT
+ );
+
+ INSERT INTO foo VALUES (1, 1);
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1l { SELECT * FROM foo FOR KEY SHARE; }
+step s1svp { SAVEPOINT f; }
+step s1d { SELECT * FROM foo FOR NO KEY UPDATE; }
+step s1r { ROLLBACK TO f; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2l { SELECT * FROM foo FOR UPDATE; }
+step s2l2 { SELECT * FROM foo FOR NO KEY UPDATE; }
+step s2c { COMMIT; }
+
+permutation s1l s1svp s1d s1r s2l s1c s2c
+permutation s1l s1svp s1d s2l s1r s1c s2c
+permutation s1l s1svp s1d s1r s2l2 s1c s2c
+permutation s1l s1svp s1d s2l2 s1r s1c s2c
diff --git a/src/test/isolation/specs/delete-abort-savept.spec b/src/test/isolation/specs/delete-abort-savept.spec
new file mode 100644
index 0000000..498ffed
--- /dev/null
+++ b/src/test/isolation/specs/delete-abort-savept.spec
@@ -0,0 +1,37 @@
+# After rolling back a subtransaction that upgraded a lock, the previously
+# held lock should still be held.
+setup
+{
+ CREATE TABLE foo (
+ key INT PRIMARY KEY,
+ value INT
+ );
+
+ INSERT INTO foo VALUES (1, 1);
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1l { SELECT * FROM foo FOR KEY SHARE; }
+step s1svp { SAVEPOINT f; }
+step s1d { DELETE FROM foo; }
+step s1r { ROLLBACK TO f; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2l { SELECT * FROM foo FOR UPDATE; }
+step s2c { COMMIT; }
+
+permutation s1l s1svp s1d s1r s1c s2l s2c
+permutation s1l s1svp s1d s1r s2l s1c s2c
+permutation s1l s1svp s1d s2l s1r s1c s2c
+permutation s1l s1svp s2l s1d s1r s1c s2c
+permutation s1l s2l s1svp s1d s1r s1c s2c
+permutation s2l s1l s2c s1svp s1d s1r s1c
+permutation s2l s2c s1l s1svp s1d s1r s1c
diff --git a/src/test/isolation/specs/drop-index-concurrently-1.spec b/src/test/isolation/specs/drop-index-concurrently-1.spec
new file mode 100644
index 0000000..812b5de
--- /dev/null
+++ b/src/test/isolation/specs/drop-index-concurrently-1.spec
@@ -0,0 +1,41 @@
+# DROP INDEX CONCURRENTLY
+#
+# This test shows that the concurrent write behaviour works correctly
+# with the expected output being 2 rows at the READ COMMITTED and READ
+# UNCOMMITTED transaction isolation levels, and 1 row at the other
+# transaction isolation levels.
+#
+setup
+{
+ CREATE TABLE test_dc(id serial primary key, data int);
+ INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100);
+ CREATE INDEX test_dc_data ON test_dc(data);
+}
+
+teardown
+{
+ DROP TABLE test_dc;
+}
+
+session s1
+step noseq { SET enable_seqscan = false; }
+step chkiso { SELECT (setting in ('read committed','read uncommitted')) AS is_read_committed FROM pg_settings WHERE name = 'default_transaction_isolation'; }
+step prepi { PREPARE getrow_idx AS SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; }
+step preps { PREPARE getrow_seq AS SELECT * FROM test_dc WHERE data::text=34::text ORDER BY id,data; }
+step begin { BEGIN; }
+step explaini { EXPLAIN (COSTS OFF) EXECUTE getrow_idx; }
+step explains { EXPLAIN (COSTS OFF) EXECUTE getrow_seq; }
+step selecti { EXECUTE getrow_idx; }
+step selects { EXECUTE getrow_seq; }
+step end { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step select2 { SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; }
+step insert2 { INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100); }
+step end2 { COMMIT; }
+
+session s3
+step drop { DROP INDEX CONCURRENTLY test_dc_data; }
+
+permutation noseq chkiso prepi preps begin explaini explains select2 drop insert2 end2 selecti selects end
diff --git a/src/test/isolation/specs/eval-plan-qual-trigger.spec b/src/test/isolation/specs/eval-plan-qual-trigger.spec
new file mode 100644
index 0000000..b512edd
--- /dev/null
+++ b/src/test/isolation/specs/eval-plan-qual-trigger.spec
@@ -0,0 +1,410 @@
+setup
+{
+ CREATE TABLE trigtest(key text primary key, data text);
+
+ CREATE FUNCTION noisy_oper(p_comment text, p_a anynonarray, p_op text, p_b anynonarray)
+ RETURNS bool LANGUAGE plpgsql AS $body$
+ DECLARE
+ r bool;
+ BEGIN
+ EXECUTE format('SELECT $1 %s $2', p_op) INTO r USING p_a, p_b;
+ RAISE NOTICE '%: % % % % %: %', p_comment, pg_typeof(p_a), p_a, p_op, pg_typeof(p_b), p_b, r;
+ RETURN r;
+ END;$body$;
+
+ CREATE FUNCTION trig_report() RETURNS TRIGGER LANGUAGE plpgsql AS $body$
+ DECLARE
+ r_new text;
+ r_old text;
+ r_ret record;
+ BEGIN
+ -- In older releases it wasn't allowed to reference OLD/NEW
+ -- when not applicable for TG_WHEN
+ IF TG_OP = 'INSERT' THEN
+ r_old = NULL;
+ r_new = NEW;
+ r_ret = NEW;
+ ELSIF TG_OP = 'DELETE' THEN
+ r_old = OLD;
+ r_new = NULL;
+ r_ret = OLD;
+ ELSIF TG_OP = 'UPDATE' THEN
+ r_old = OLD;
+ r_new = NEW;
+ r_ret = NEW;
+ END IF;
+
+ IF TG_WHEN = 'AFTER' THEN
+ r_ret = NULL;
+ END IF;
+
+ RAISE NOTICE 'trigger: name %; when: %; lev: %s; op: %; old: % new: %',
+ TG_NAME, TG_WHEN, TG_LEVEL, TG_OP, r_old, r_new;
+
+ RETURN r_ret;
+ END;
+ $body$;
+}
+
+teardown
+{
+ DROP TABLE trigtest;
+ DROP FUNCTION noisy_oper(text, anynonarray, text, anynonarray);
+ DROP FUNCTION trig_report();
+}
+
+
+session s0
+step s0_rep { SELECT * FROM trigtest ORDER BY key, data }
+
+session s1
+#setup { }
+step s1_b_rc { BEGIN ISOLATION LEVEL READ COMMITTED; SELECT 1; }
+step s1_b_rr { BEGIN ISOLATION LEVEL REPEATABLE READ; SELECT 1; }
+step s1_c { COMMIT; }
+step s1_r { ROLLBACK; }
+step s1_trig_rep_b_i { CREATE TRIGGER rep_b_i BEFORE INSERT ON trigtest FOR EACH ROW EXECUTE PROCEDURE trig_report(); }
+step s1_trig_rep_a_i { CREATE TRIGGER rep_a_i AFTER INSERT ON trigtest FOR EACH ROW EXECUTE PROCEDURE trig_report(); }
+step s1_trig_rep_b_u { CREATE TRIGGER rep_b_u BEFORE UPDATE ON trigtest FOR EACH ROW EXECUTE PROCEDURE trig_report(); }
+step s1_trig_rep_a_u { CREATE TRIGGER rep_a_u AFTER UPDATE ON trigtest FOR EACH ROW EXECUTE PROCEDURE trig_report(); }
+step s1_trig_rep_b_d { CREATE TRIGGER rep_b_d BEFORE DELETE ON trigtest FOR EACH ROW EXECUTE PROCEDURE trig_report(); }
+step s1_trig_rep_a_d { CREATE TRIGGER rep_a_d AFTER DELETE ON trigtest FOR EACH ROW EXECUTE PROCEDURE trig_report(); }
+step s1_ins_a { INSERT INTO trigtest VALUES ('key-a', 'val-a-s1') RETURNING *; }
+step s1_ins_b { INSERT INTO trigtest VALUES ('key-b', 'val-b-s1') RETURNING *; }
+step s1_ins_c { INSERT INTO trigtest VALUES ('key-c', 'val-c-s1') RETURNING *; }
+step s1_del_a {
+ DELETE FROM trigtest
+ WHERE
+ noisy_oper('upd', key, '=', 'key-a') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *
+}
+step s1_del_b {
+ DELETE FROM trigtest
+ WHERE
+ noisy_oper('upd', key, '=', 'key-b') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *
+}
+step s1_upd_a_data {
+ UPDATE trigtest SET data = data || '-ups1'
+ WHERE
+ noisy_oper('upd', key, '=', 'key-a') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *;
+}
+step s1_upd_b_data {
+ UPDATE trigtest SET data = data || '-ups1'
+ WHERE
+ noisy_oper('upd', key, '=', 'key-b') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *;
+}
+step s1_upd_a_tob {
+ UPDATE trigtest SET key = 'key-b', data = data || '-tobs1'
+ WHERE
+ noisy_oper('upk', key, '=', 'key-a') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *;
+}
+
+session s2
+#setup { }
+step s2_b_rc { BEGIN ISOLATION LEVEL READ COMMITTED; SELECT 1; }
+step s2_b_rr { BEGIN ISOLATION LEVEL REPEATABLE READ; SELECT 1; }
+step s2_c { COMMIT; }
+step s2_r { ROLLBACK; }
+step s2_ins_a { INSERT INTO trigtest VALUES ('key-a', 'val-a-s2') RETURNING *; }
+step s2_del_a {
+ DELETE FROM trigtest
+ WHERE
+ noisy_oper('upd', key, '=', 'key-a') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *
+}
+step s2_upd_a_data {
+ UPDATE trigtest SET data = data || '-ups2'
+ WHERE
+ noisy_oper('upd', key, '=', 'key-a') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *;
+}
+step s2_upd_b_data {
+ UPDATE trigtest SET data = data || '-ups2'
+ WHERE
+ noisy_oper('upd', key, '=', 'key-b') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *;
+}
+step s2_upd_all_data {
+ UPDATE trigtest SET data = data || '-ups2'
+ WHERE
+ noisy_oper('upd', key, '<>', 'mismatch') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *;
+}
+step s2_upsert_a_data {
+ INSERT INTO trigtest VALUES ('key-a', 'val-a-upss2')
+ ON CONFLICT (key)
+ DO UPDATE SET data = trigtest.data || '-upserts2'
+ WHERE
+ noisy_oper('upd', trigtest.key, '=', 'key-a') AND
+ noisy_oper('upk', trigtest.data, '<>', 'mismatch')
+ RETURNING *;
+}
+
+session s3
+#setup { }
+step s3_b_rc { BEGIN ISOLATION LEVEL READ COMMITTED; SELECT 1; }
+step s3_c { COMMIT; }
+step s3_r { ROLLBACK; }
+step s3_del_a {
+ DELETE FROM trigtest
+ WHERE
+ noisy_oper('upd', key, '=', 'key-a') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *
+}
+step s3_upd_a_data {
+ UPDATE trigtest SET data = data || '-ups3'
+ WHERE
+ noisy_oper('upd', key, '=', 'key-a') AND
+ noisy_oper('upk', data, '<>', 'mismatch')
+ RETURNING *;
+}
+
+### base case verifying that triggers see performed modifications
+# s1 updates, s1 commits, s2 updates
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s1_c s2_upd_a_data s2_c
+ s0_rep
+# s1 updates, s1 rolls back, s2 updates
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s1_r s2_upd_a_data s2_c
+ s0_rep
+# s1 updates, s1 commits back, s2 deletes
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s1_c s2_del_a s2_c
+ s0_rep
+# s1 updates, s1 rolls back back, s2 deletes
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s1_r s2_del_a s2_c
+ s0_rep
+
+### Verify EPQ is performed if necessary, and skipped if transaction rolled back
+# s1 updates, s2 updates, s1 commits, EPQ
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 updates, s2 updates, s1 rolls back, no EPQ
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 updates, s2 deletes, s1 commits, EPQ
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 updates, s2 deletes, s1 rolls back, no EPQ
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 commits, EPQ
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_del_a s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 rolls back, no EPQ
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_del_a s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 inserts, s2 inserts, s1 commits, s2 inserts, unique conflict
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_a_i s1_trig_rep_a_d
+ s1_b_rc s2_b_rc
+ s1_ins_a s2_ins_a s1_c s2_c
+ s0_rep
+# s1 inserts, s2 inserts, s1 rolls back, s2 inserts, no unique conflict
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_a_i s1_trig_rep_a_d
+ s1_b_rc s2_b_rc
+ s1_ins_a s2_ins_a s1_r s2_c
+ s0_rep
+# s1 updates, s2 upserts, s1 commits, EPQ
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upsert_a_data s1_c s2_c
+ s0_rep
+# s1 updates, s2 upserts, s1 rolls back, no EPQ
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upsert_a_data s1_c s2_c
+ s0_rep
+# s1 inserts, s2 upserts, s1 commits
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_b_rc s2_b_rc
+ s1_ins_a s2_upsert_a_data s1_c s2_c
+ s0_rep
+# s1 inserts, s2 upserts, s1 rolls back
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_b_rc s2_b_rc
+ s1_ins_a s2_upsert_a_data s1_r s2_c
+ s0_rep
+# s1 inserts, s2 upserts, s1 updates, s1 commits, EPQ
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_b_rc s2_b_rc
+ s1_ins_a s1_upd_a_data s2_upsert_a_data s1_c s2_c
+ s0_rep
+# s1 inserts, s2 upserts, s1 updates, s1 rolls back, no EPQ
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_b_rc s2_b_rc
+ s1_ins_a s1_upd_a_data s2_upsert_a_data s1_r s2_c
+ s0_rep
+
+### Verify EPQ is performed if necessary, and skipped if transaction rolled back,
+### just without before triggers (for comparison, no additional row locks)
+# s1 updates, s2 updates, s1 commits, EPQ
+permutation s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 updates, s2 updates, s1 rolls back, no EPQ
+permutation s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 updates, s2 deletes, s1 commits, EPQ
+permutation s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_del_a s1_c s2_c
+ s0_rep
+# s1 updates, s2 deletes, s1 rolls back, no EPQ
+permutation s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_upd_a_data s2_del_a s1_r s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 commits, EPQ
+permutation s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_del_a s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 rolls back, no EPQ
+permutation s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_del_a s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 deletes, s2 deletes, s1 commits, EPQ
+permutation s1_trig_rep_a_d
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_del_a s2_del_a s1_c s2_c
+ s0_rep
+# s1 deletes, s2 deletes, s1 rolls back, no EPQ
+permutation s1_trig_rep_a_d
+ s1_ins_a s1_ins_b s1_b_rc s2_b_rc
+ s1_del_a s2_del_a s1_r s2_c
+ s0_rep
+
+### Verify that an update affecting a row that has been
+### updated/deleted to not match the where clause anymore works
+### correctly
+# s1 updates to different key, s2 updates old key, s1 commits, EPQ failure should lead to no update
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_upd_a_tob s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 updates to different key, s2 updates old key, s1 rolls back, no EPQ failure
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_upd_a_tob s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 updates to different key, s2 updates new key, s1 commits, s2 will
+# not see tuple with new key and not block
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_upd_a_tob s2_upd_b_data s1_c s2_c
+ s0_rep
+# s1 updates to different key, s2 updates all keys, s1 commits, s2,
+# will not see tuple with old key, but block on old, and then follow
+# the chain
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_upd_a_tob s2_upd_all_data s1_c s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 committs, EPQ failure should lead to no update
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_del_a s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 rolls back, no EPQ failure
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_del_a s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 deletes, s2 deletes, s1 committs, EPQ failure should lead to no delete
+permutation s1_trig_rep_b_d s1_trig_rep_a_d
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_del_a s2_del_a s1_c s2_c
+ s0_rep
+# s1 deletes, s2 deletes, s1 rolls back, no EPQ failure
+permutation s1_trig_rep_b_d s1_trig_rep_a_d
+ s1_ins_a s1_ins_c s1_b_rc s2_b_rc
+ s1_del_a s2_del_a s1_r s2_c
+ s0_rep
+
+### Verify EPQ with more than two participants works
+## XXX: Disable tests, there is some potential for instability here that's not yet fully understood
+## s1 updates, s2 updates, s3 updates, s1 commits, s2 EPQ, s2 commits, s3 EPQ
+#permutation s1_trig_rep_b_u s1_trig_rep_a_u
+# s1_ins_a s1_ins_b s1_b_rc s2_b_rc s3_b_rc
+# s1_upd_a_data s2_upd_a_data s3_upd_a_data s1_c s2_c s3_c
+# s0_rep
+## s1 updates, s2 updates, s3 updates, s1 commits, s2 EPQ, s2 rolls back, s3 EPQ
+#permutation s1_trig_rep_b_u s1_trig_rep_a_u
+# s1_ins_a s1_ins_b s1_b_rc s2_b_rc s3_b_rc
+# s1_upd_a_data s2_upd_a_data s3_upd_a_data s1_c s2_r s3_c
+# s0_rep
+## s1 updates, s3 updates, s2 upserts, s1 updates, s1 commits, s3 EPQ, s3 deletes, s3 commits, s2 inserts without EPQ recheck
+#permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+# s1_ins_a s1_b_rc s2_b_rc s3_b_rc
+# s1_upd_a_data s3_upd_a_data s2_upsert_a_data s1_upd_a_data s1_c s3_del_a s3_c s2_c
+# s0_rep
+## s1 updates, s3 updates, s2 upserts, s1 updates, s1 commits, s3 EPQ, s3 deletes, s3 rolls back, s2 EPQ
+#permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+# s1_ins_a s1_b_rc s2_b_rc s3_b_rc
+# s1_upd_a_data s3_upd_a_data s2_upsert_a_data s1_upd_a_data s1_c s3_del_a s3_r s2_c
+# s0_rep
+
+### Document that EPQ doesn't "leap" onto a tuple that would match after blocking
+# s1 inserts a, s1 updates b, s2 updates b, s1 deletes b, s1 updates a to b, s1 commits, s2 EPQ finds tuple deleted
+permutation s1_trig_rep_b_i s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_i s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_b s1_b_rc s2_b_rc
+ s1_ins_a s1_upd_b_data s2_upd_b_data s1_del_b s1_upd_a_tob s1_c s2_c
+ s0_rep
+
+### Triggers for EPQ detect serialization failures
+# s1 updates, s2 updates, s1 commits, serialization failure
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rr s2_b_rr
+ s1_upd_a_data s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 updates, s2 updates, s1 rolls back, s2 succeeds
+permutation s1_trig_rep_b_u s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rr s2_b_rr
+ s1_upd_a_data s2_upd_a_data s1_r s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 commits, serialization failure
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rr s2_b_rr
+ s1_del_a s2_upd_a_data s1_c s2_c
+ s0_rep
+# s1 deletes, s2 updates, s1 rolls back, s2 succeeds
+permutation s1_trig_rep_b_d s1_trig_rep_b_u s1_trig_rep_a_d s1_trig_rep_a_u
+ s1_ins_a s1_ins_b s1_b_rr s2_b_rr
+ s1_del_a s2_upd_a_data s1_r s2_c
+ s0_rep
diff --git a/src/test/isolation/specs/eval-plan-qual.spec b/src/test/isolation/specs/eval-plan-qual.spec
new file mode 100644
index 0000000..4bb9595
--- /dev/null
+++ b/src/test/isolation/specs/eval-plan-qual.spec
@@ -0,0 +1,359 @@
+# Tests for the EvalPlanQual mechanism
+#
+# EvalPlanQual is used in READ COMMITTED isolation level to attempt to
+# re-execute UPDATE and DELETE operations against rows that were updated
+# by some concurrent transaction.
+
+setup
+{
+ CREATE TABLE accounts (accountid text PRIMARY KEY, balance numeric not null);
+ INSERT INTO accounts VALUES ('checking', 600), ('savings', 600);
+
+ CREATE FUNCTION update_checking(int) RETURNS bool LANGUAGE sql AS $$
+ UPDATE accounts SET balance = balance + 1 WHERE accountid = 'checking'; SELECT true;$$;
+
+ CREATE TABLE accounts_ext (accountid text PRIMARY KEY, balance numeric not null, other text);
+ INSERT INTO accounts_ext VALUES ('checking', 600, 'other'), ('savings', 700, null);
+ ALTER TABLE accounts_ext ADD COLUMN newcol int DEFAULT 42;
+ ALTER TABLE accounts_ext ADD COLUMN newcol2 text DEFAULT NULL;
+
+ CREATE TABLE p (a int, b int, c int);
+ CREATE TABLE c1 () INHERITS (p);
+ CREATE TABLE c2 () INHERITS (p);
+ CREATE TABLE c3 () INHERITS (p);
+ INSERT INTO c1 SELECT 0, a / 3, a % 3 FROM generate_series(0, 9) a;
+ INSERT INTO c2 SELECT 1, a / 3, a % 3 FROM generate_series(0, 9) a;
+ INSERT INTO c3 SELECT 2, a / 3, a % 3 FROM generate_series(0, 9) a;
+
+ CREATE TABLE table_a (id integer, value text);
+ CREATE TABLE table_b (id integer, value text);
+ INSERT INTO table_a VALUES (1, 'tableAValue');
+ INSERT INTO table_b VALUES (1, 'tableBValue');
+
+ CREATE TABLE jointest AS SELECT generate_series(1,10) AS id, 0 AS data;
+ CREATE INDEX ON jointest(id);
+
+ CREATE TABLE parttbl (a int, b int, c int) PARTITION BY LIST (a);
+ CREATE TABLE parttbl1 PARTITION OF parttbl FOR VALUES IN (1);
+ CREATE TABLE parttbl2 PARTITION OF parttbl FOR VALUES IN (2);
+ INSERT INTO parttbl VALUES (1, 1, 1);
+
+ CREATE TABLE another_parttbl (a int, b int, c int) PARTITION BY LIST (a);
+ CREATE TABLE another_parttbl1 PARTITION OF another_parttbl FOR VALUES IN (1);
+ CREATE TABLE another_parttbl2 PARTITION OF another_parttbl FOR VALUES IN (2);
+ INSERT INTO another_parttbl VALUES (1, 1, 1);
+
+ CREATE FUNCTION noisy_oper(p_comment text, p_a anynonarray, p_op text, p_b anynonarray)
+ RETURNS bool LANGUAGE plpgsql AS $$
+ DECLARE
+ r bool;
+ BEGIN
+ EXECUTE format('SELECT $1 %s $2', p_op) INTO r USING p_a, p_b;
+ RAISE NOTICE '%: % % % % %: %', p_comment, pg_typeof(p_a), p_a, p_op, pg_typeof(p_b), p_b, r;
+ RETURN r;
+ END;$$;
+}
+
+teardown
+{
+ DROP TABLE accounts;
+ DROP FUNCTION update_checking(int);
+ DROP TABLE accounts_ext;
+ DROP TABLE p CASCADE;
+ DROP TABLE table_a, table_b, jointest;
+ DROP TABLE parttbl;
+ DROP TABLE another_parttbl;
+ DROP FUNCTION noisy_oper(text, anynonarray, text, anynonarray)
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+# wx1 then wx2 checks the basic case of re-fetching up-to-date values
+step wx1 { UPDATE accounts SET balance = balance - 200 WHERE accountid = 'checking' RETURNING balance; }
+# wy1 then wy2 checks the case where quals pass then fail
+step wy1 { UPDATE accounts SET balance = balance + 500 WHERE accountid = 'checking' RETURNING balance; }
+
+step wxext1 { UPDATE accounts_ext SET balance = balance - 200 WHERE accountid = 'checking' RETURNING balance; }
+step tocds1 { UPDATE accounts SET accountid = 'cds' WHERE accountid = 'checking'; }
+step tocdsext1 { UPDATE accounts_ext SET accountid = 'cds' WHERE accountid = 'checking'; }
+
+# d1 then wx1 checks that update can deal with the updated row vanishing
+# wx2 then d1 checks that the delete affects the updated row
+# wx2, wx2 then d1 checks that the delete checks the quals correctly (balance too high)
+# wx2, d2, then d1 checks that delete handles a vanishing row correctly
+step d1 { DELETE FROM accounts WHERE accountid = 'checking' AND balance < 1500 RETURNING balance; }
+
+# upsert tests are to check writable-CTE cases
+step upsert1 {
+ WITH upsert AS
+ (UPDATE accounts SET balance = balance + 500
+ WHERE accountid = 'savings'
+ RETURNING accountid)
+ INSERT INTO accounts SELECT 'savings', 500
+ WHERE NOT EXISTS (SELECT 1 FROM upsert);
+}
+
+# tests with table p check inheritance cases:
+# readp1/writep1/readp2 tests a bug where nodeLockRows did the wrong thing
+# when the first updated tuple was in a non-first child table.
+# writep2/returningp1 tests a memory allocation issue
+# writep3a/writep3b tests updates touching more than one table
+
+step readp1 { SELECT tableoid::regclass, ctid, * FROM p WHERE b IN (0, 1) AND c = 0 FOR UPDATE; }
+step writep1 { UPDATE p SET b = -1 WHERE a = 1 AND b = 1 AND c = 0; }
+step writep2 { UPDATE p SET b = -b WHERE a = 1 AND c = 0; }
+step writep3a { UPDATE p SET b = -b WHERE c = 0; }
+step c1 { COMMIT; }
+step r1 { ROLLBACK; }
+
+# these tests are meant to exercise EvalPlanQualFetchRowMark,
+# ie, handling non-locked tables in an EvalPlanQual recheck
+
+step partiallock {
+ SELECT * FROM accounts a1, accounts a2
+ WHERE a1.accountid = a2.accountid
+ FOR UPDATE OF a1;
+}
+step lockwithvalues {
+ -- Reference rowmark column that differs in type from targetlist at some attno.
+ -- See CAHU7rYZo_C4ULsAx_LAj8az9zqgrD8WDd4hTegDTMM1LMqrBsg@mail.gmail.com
+ SELECT a1.*, v.id FROM accounts a1, (values('checking'::text, 'nan'::text),('savings', 'nan')) v(id, notnumeric)
+ WHERE a1.accountid = v.id AND v.notnumeric != 'einszwei'
+ FOR UPDATE OF a1;
+}
+step partiallock_ext {
+ SELECT * FROM accounts_ext a1, accounts_ext a2
+ WHERE a1.accountid = a2.accountid
+ FOR UPDATE OF a1;
+}
+
+# these tests exercise EvalPlanQual with a SubLink sub-select (which should be
+# unaffected by any EPQ recheck behavior in the outer query); cf bug #14034
+
+step updateforss {
+ UPDATE table_a SET value = 'newTableAValue' WHERE id = 1;
+ UPDATE table_b SET value = 'newTableBValue' WHERE id = 1;
+}
+
+# these tests exercise EvalPlanQual with conditional InitPlans which
+# have not been executed prior to the EPQ
+
+step updateforcip {
+ UPDATE table_a SET value = NULL WHERE id = 1;
+}
+
+# these tests exercise mark/restore during EPQ recheck, cf bug #15032
+
+step selectjoinforupdate {
+ set local enable_nestloop to 0;
+ set local enable_hashjoin to 0;
+ set local enable_seqscan to 0;
+ explain (costs off)
+ select * from jointest a join jointest b on a.id=b.id for update;
+ select * from jointest a join jointest b on a.id=b.id for update;
+}
+
+# these tests exercise Result plan nodes participating in EPQ
+
+step selectresultforupdate {
+ select * from (select 1 as x) ss1 join (select 7 as y) ss2 on true
+ left join table_a a on a.id = x, jointest jt
+ where jt.id = y;
+ explain (verbose, costs off)
+ select * from (select 1 as x) ss1 join (select 7 as y) ss2 on true
+ left join table_a a on a.id = x, jointest jt
+ where jt.id = y for update of jt, ss1, ss2;
+ select * from (select 1 as x) ss1 join (select 7 as y) ss2 on true
+ left join table_a a on a.id = x, jointest jt
+ where jt.id = y for update of jt, ss1, ss2;
+}
+
+# test for EPQ on a partitioned result table
+
+step simplepartupdate {
+ update parttbl set a = a;
+}
+
+# test scenarios where update may cause row movement
+
+step simplepartupdate_route1to2 {
+ update parttbl set a = 2 where c = 1 returning *;
+}
+
+step simplepartupdate_noroute {
+ update parttbl set b = 2 where c = 1 returning *;
+}
+
+
+session s2
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step wx2 { UPDATE accounts SET balance = balance + 450 WHERE accountid = 'checking' RETURNING balance; }
+step wy2 { UPDATE accounts SET balance = balance + 1000 WHERE accountid = 'checking' AND balance < 1000 RETURNING balance; }
+step d2 { DELETE FROM accounts WHERE accountid = 'checking'; }
+
+step upsert2 {
+ WITH upsert AS
+ (UPDATE accounts SET balance = balance + 1234
+ WHERE accountid = 'savings'
+ RETURNING accountid)
+ INSERT INTO accounts SELECT 'savings', 1234
+ WHERE NOT EXISTS (SELECT 1 FROM upsert);
+}
+step wx2_ext { UPDATE accounts_ext SET balance = balance + 450; }
+step readp2 { SELECT tableoid::regclass, ctid, * FROM p WHERE b IN (0, 1) AND c = 0 FOR UPDATE; }
+step returningp1 {
+ WITH u AS ( UPDATE p SET b = b WHERE a > 0 RETURNING * )
+ SELECT * FROM u;
+}
+step writep3b { UPDATE p SET b = -b WHERE c = 0; }
+step readforss {
+ SELECT ta.id AS ta_id, ta.value AS ta_value,
+ (SELECT ROW(tb.id, tb.value)
+ FROM table_b tb WHERE ta.id = tb.id) AS tb_row
+ FROM table_a ta
+ WHERE ta.id = 1 FOR UPDATE OF ta;
+}
+step updateforcip2 {
+ UPDATE table_a SET value = COALESCE(value, (SELECT text 'newValue')) WHERE id = 1;
+}
+step updateforcip3 {
+ WITH d(val) AS (SELECT text 'newValue' FROM generate_series(1,1))
+ UPDATE table_a SET value = COALESCE(value, (SELECT val FROM d)) WHERE id = 1;
+}
+step wrtwcte { UPDATE table_a SET value = 'tableAValue2' WHERE id = 1; }
+step wrjt { UPDATE jointest SET data = 42 WHERE id = 7; }
+step complexpartupdate {
+ with u as (update parttbl set a = a returning parttbl.*)
+ update parttbl set a = u.a from u;
+}
+
+step complexpartupdate_route_err1 {
+ with u as (update another_parttbl set a = 1 returning another_parttbl.*)
+ update parttbl p set a = u.a from u where p.a = u.a and p.c = 1 returning p.*;
+}
+
+step complexpartupdate_route {
+ with u as (update another_parttbl set a = 1 returning another_parttbl.*)
+ update parttbl p set a = p.b from u where p.a = u.a and p.c = 1 returning p.*;
+}
+
+step complexpartupdate_doesnt_route {
+ with u as (update another_parttbl set a = 1 returning another_parttbl.*)
+ update parttbl p set a = 3 - p.b from u where p.a = u.a and p.c = 1 returning p.*;
+}
+
+# Use writable CTEs to create self-updated rows, that then are
+# (updated|deleted). The *fail versions of the tests additionally
+# perform an update, via a function, in a different command, to test
+# behaviour relating to that.
+step updwcte { WITH doup AS (UPDATE accounts SET balance = balance + 1100 WHERE accountid = 'checking' RETURNING *) UPDATE accounts a SET balance = doup.balance + 100 FROM doup RETURNING *; }
+step updwctefail { WITH doup AS (UPDATE accounts SET balance = balance + 1100 WHERE accountid = 'checking' RETURNING *, update_checking(999)) UPDATE accounts a SET balance = doup.balance + 100 FROM doup RETURNING *; }
+step delwcte { WITH doup AS (UPDATE accounts SET balance = balance + 1100 WHERE accountid = 'checking' RETURNING *) DELETE FROM accounts a USING doup RETURNING *; }
+step delwctefail { WITH doup AS (UPDATE accounts SET balance = balance + 1100 WHERE accountid = 'checking' RETURNING *, update_checking(999)) DELETE FROM accounts a USING doup RETURNING *; }
+
+# Check that nested EPQ works correctly
+step wnested2 {
+ UPDATE accounts SET balance = balance - 1200
+ WHERE noisy_oper('upid', accountid, '=', 'checking')
+ AND noisy_oper('up', balance, '>', 200.0)
+ AND EXISTS (
+ SELECT accountid
+ FROM accounts_ext ae
+ WHERE noisy_oper('lock_id', ae.accountid, '=', accounts.accountid)
+ AND noisy_oper('lock_bal', ae.balance, '>', 200.0)
+ FOR UPDATE
+ );
+}
+
+step c2 { COMMIT; }
+step r2 { ROLLBACK; }
+
+session s3
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step read { SELECT * FROM accounts ORDER BY accountid; }
+step read_ext { SELECT * FROM accounts_ext ORDER BY accountid; }
+step read_a { SELECT * FROM table_a ORDER BY id; }
+
+# this test exercises EvalPlanQual with a CTE, cf bug #14328
+step readwcte {
+ WITH
+ cte1 AS (
+ SELECT id FROM table_b WHERE value = 'tableBValue'
+ ),
+ cte2 AS (
+ SELECT * FROM table_a
+ WHERE id = (SELECT id FROM cte1)
+ FOR UPDATE
+ )
+ SELECT * FROM cte2;
+}
+
+# this test exercises a different CTE misbehavior, cf bug #14870
+step multireadwcte {
+ WITH updated AS (
+ UPDATE table_a SET value = 'tableAValue3' WHERE id = 1 RETURNING id
+ )
+ SELECT (SELECT id FROM updated) AS subid, * FROM updated;
+}
+
+teardown { COMMIT; }
+
+# test that normal update follows update chains, and reverifies quals
+permutation wx1 wx2 c1 c2 read
+permutation wy1 wy2 c1 c2 read
+permutation wx1 wx2 r1 c2 read
+permutation wy1 wy2 r1 c2 read
+
+# test that deletes follow chains, and if necessary reverifies quals
+permutation wx1 d1 wx2 c1 c2 read
+permutation wx2 d1 c2 c1 read
+permutation wx2 wx2 d1 c2 c1 read
+permutation wx2 d2 d1 c2 c1 read
+permutation wx1 d1 wx2 r1 c2 read
+permutation wx2 d1 r2 c1 read
+permutation wx2 wx2 d1 r2 c1 read
+permutation wx2 d2 d1 r2 c1 read
+permutation d1 wx2 c1 c2 read
+permutation d1 wx2 r1 c2 read
+
+# Check that nested EPQ works correctly
+permutation wnested2 c1 c2 read
+permutation wx1 wxext1 wnested2 c1 c2 read
+permutation wx1 wx1 wxext1 wnested2 c1 c2 read
+permutation wx1 wx1 wxext1 wxext1 wnested2 c1 c2 read
+permutation wx1 wxext1 wxext1 wnested2 c1 c2 read
+permutation wx1 tocds1 wnested2 c1 c2 read
+permutation wx1 tocdsext1 wnested2 c1 c2 read
+
+# test that an update to a self-modified row is ignored when
+# previously updated by the same cid
+permutation wx1 updwcte c1 c2 read
+# test that an update to a self-modified row throws error when
+# previously updated by a different cid
+permutation wx1 updwctefail c1 c2 read
+# test that a delete to a self-modified row is ignored when
+# previously updated by the same cid
+permutation wx1 delwcte c1 c2 read
+# test that a delete to a self-modified row throws error when
+# previously updated by a different cid
+permutation wx1 delwctefail c1 c2 read
+
+permutation upsert1 upsert2 c1 c2 read
+permutation readp1 writep1 readp2 c1 c2
+permutation writep2 returningp1 c1 c2
+permutation writep3a writep3b c1 c2
+permutation wx2 partiallock c2 c1 read
+permutation wx2 lockwithvalues c2 c1 read
+permutation wx2_ext partiallock_ext c2 c1 read_ext
+permutation updateforss readforss c1 c2
+permutation updateforcip updateforcip2 c1 c2 read_a
+permutation updateforcip updateforcip3 c1 c2 read_a
+permutation wrtwcte readwcte c1 c2
+permutation wrjt selectjoinforupdate c2 c1
+permutation wrjt selectresultforupdate c2 c1
+permutation wrtwcte multireadwcte c1 c2
+
+permutation simplepartupdate complexpartupdate c1 c2
+permutation simplepartupdate_route1to2 complexpartupdate_route_err1 c1 c2
+permutation simplepartupdate_noroute complexpartupdate_route c1 c2
+permutation simplepartupdate_noroute complexpartupdate_doesnt_route c1 c2
diff --git a/src/test/isolation/specs/fk-contention.spec b/src/test/isolation/specs/fk-contention.spec
new file mode 100644
index 0000000..f11a1d8
--- /dev/null
+++ b/src/test/isolation/specs/fk-contention.spec
@@ -0,0 +1,19 @@
+setup
+{
+ CREATE TABLE foo (a int PRIMARY KEY, b text);
+ CREATE TABLE bar (a int NOT NULL REFERENCES foo);
+ INSERT INTO foo VALUES (42);
+}
+
+teardown
+{
+ DROP TABLE foo, bar;
+}
+
+session s1
+setup { BEGIN; }
+step ins { INSERT INTO bar VALUES (42); }
+step com { COMMIT; }
+
+session s2
+step upd { UPDATE foo SET b = 'Hello World'; }
diff --git a/src/test/isolation/specs/fk-deadlock.spec b/src/test/isolation/specs/fk-deadlock.spec
new file mode 100644
index 0000000..b4970dd
--- /dev/null
+++ b/src/test/isolation/specs/fk-deadlock.spec
@@ -0,0 +1,46 @@
+setup
+{
+ CREATE TABLE parent (
+ parent_key int PRIMARY KEY,
+ aux text NOT NULL
+ );
+
+ CREATE TABLE child (
+ child_key int PRIMARY KEY,
+ parent_key int NOT NULL REFERENCES parent
+ );
+
+ INSERT INTO parent VALUES (1, 'foo');
+}
+
+teardown
+{
+ DROP TABLE parent, child;
+}
+
+session s1
+setup { BEGIN; SET deadlock_timeout = '100ms'; }
+step s1i { INSERT INTO child VALUES (1, 1); }
+step s1u { UPDATE parent SET aux = 'bar'; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; SET deadlock_timeout = '10s'; }
+step s2i { INSERT INTO child VALUES (2, 1); }
+step s2u { UPDATE parent SET aux = 'baz'; }
+step s2c { COMMIT; }
+
+permutation s1i s1u s1c s2i s2u s2c
+permutation s1i s1u s2i s1c s2u s2c
+permutation s1i s1u s2i s2u s1c s2c
+permutation s1i s2i s1u s1c s2u s2c
+permutation s1i s2i s1u s2u s1c s2c
+permutation s1i s2i s2u s1u s2c s1c
+permutation s1i s2i s2u s2c s1u s1c
+permutation s2i s1i s1u s1c s2u s2c
+permutation s2i s1i s1u s2u s1c s2c
+permutation s2i s1i s2u s1u s2c s1c
+permutation s2i s1i s2u s2c s1u s1c
+permutation s2i s2u s1i s1u s2c s1c
+permutation s2i s2u s1i s2c s1u s1c
+permutation s2i s2u s2c s1i s1u s1c
diff --git a/src/test/isolation/specs/fk-deadlock2.spec b/src/test/isolation/specs/fk-deadlock2.spec
new file mode 100644
index 0000000..c8e0e4e
--- /dev/null
+++ b/src/test/isolation/specs/fk-deadlock2.spec
@@ -0,0 +1,48 @@
+setup
+{
+ CREATE TABLE A (
+ AID integer not null,
+ Col1 integer,
+ PRIMARY KEY (AID)
+ );
+
+ CREATE TABLE B (
+ BID integer not null,
+ AID integer not null,
+ Col2 integer,
+ PRIMARY KEY (BID),
+ FOREIGN KEY (AID) REFERENCES A(AID)
+ );
+
+ INSERT INTO A (AID) VALUES (1);
+ INSERT INTO B (BID,AID) VALUES (2,1);
+}
+
+teardown
+{
+ DROP TABLE a, b;
+}
+
+session s1
+setup { BEGIN; SET deadlock_timeout = '100ms'; }
+step s1u1 { UPDATE A SET Col1 = 1 WHERE AID = 1; }
+step s1u2 { UPDATE B SET Col2 = 1 WHERE BID = 2; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; SET deadlock_timeout = '10s'; }
+step s2u1 { UPDATE B SET Col2 = 1 WHERE BID = 2; }
+step s2u2 { UPDATE B SET Col2 = 1 WHERE BID = 2; }
+step s2c { COMMIT; }
+
+permutation s1u1 s1u2 s1c s2u1 s2u2 s2c
+permutation s1u1 s1u2 s2u1 s1c s2u2 s2c
+permutation s1u1 s2u1 s1u2 s2u2 s2c s1c
+permutation s1u1 s2u1 s2u2 s1u2 s2c s1c
+permutation s1u1 s2u1 s2u2 s2c s1u2 s1c
+permutation s2u1 s1u1 s1u2 s2u2 s2c s1c
+permutation s2u1 s1u1 s2u2 s1u2 s2c s1c
+permutation s2u1 s1u1 s2u2 s2c s1u2 s1c
+permutation s2u1 s2u2 s1u1 s1u2 s2c s1c
+permutation s2u1 s2u2 s1u1 s2c s1u2 s1c
+permutation s2u1 s2u2 s2c s1u1 s1u2 s1c
diff --git a/src/test/isolation/specs/fk-partitioned-1.spec b/src/test/isolation/specs/fk-partitioned-1.spec
new file mode 100644
index 0000000..f71ee5c
--- /dev/null
+++ b/src/test/isolation/specs/fk-partitioned-1.spec
@@ -0,0 +1,45 @@
+# Verify that cloning a foreign key constraint to a partition ensures
+# that referenced values exist, even if they're being concurrently
+# deleted.
+setup {
+drop table if exists ppk, pfk, pfk1;
+ create table ppk (a int primary key) partition by list (a);
+ create table ppk1 partition of ppk for values in (1);
+ insert into ppk values (1);
+ create table pfk (a int references ppk) partition by list (a);
+ create table pfk1 (a int not null);
+ insert into pfk1 values (1);
+}
+
+session s1
+step s1b { begin; }
+step s1d { delete from ppk1 where a = 1; }
+step s1c { commit; }
+
+session s2
+step s2b { begin; }
+step s2a { alter table pfk attach partition pfk1 for values in (1); }
+step s2c { commit; }
+
+teardown { drop table ppk, pfk, pfk1; }
+
+permutation s1b s1d s1c s2b s2a s2c
+permutation s1b s1d s2b s1c s2a s2c
+permutation s1b s1d s2b s2a s1c s2c
+#permutation s1b s1d s2b s2a s2c s1c
+permutation s1b s2b s1d s1c s2a s2c
+permutation s1b s2b s1d s2a s1c s2c
+#permutation s1b s2b s1d s2a s2c s1c
+#permutation s1b s2b s2a s1d s1c s2c
+permutation s1b s2b s2a s1d s2c s1c
+permutation s1b s2b s2a s2c s1d s1c
+permutation s2b s1b s1d s1c s2a s2c
+permutation s2b s1b s1d s2a s1c s2c
+#permutation s2b s1b s1d s2a s2c s1c
+#permutation s2b s1b s2a s1d s1c s2c
+permutation s2b s1b s2a s1d s2c s1c
+permutation s2b s1b s2a s2c s1d s1c
+#permutation s2b s2a s1b s1d s1c s2c
+permutation s2b s2a s1b s1d s2c s1c
+permutation s2b s2a s1b s2c s1d s1c
+permutation s2b s2a s2c s1b s1d s1c
diff --git a/src/test/isolation/specs/fk-partitioned-2.spec b/src/test/isolation/specs/fk-partitioned-2.spec
new file mode 100644
index 0000000..209ad59
--- /dev/null
+++ b/src/test/isolation/specs/fk-partitioned-2.spec
@@ -0,0 +1,29 @@
+# Make sure that FKs referencing partitioned tables actually work.
+setup {
+ drop table if exists ppk, pfk, pfk1;
+ create table ppk (a int primary key) partition by list (a);
+ create table ppk1 partition of ppk for values in (1);
+ insert into ppk values (1);
+ create table pfk (a int references ppk) partition by list (a);
+ create table pfk1 partition of pfk for values in (1);
+}
+
+session s1
+step s1b { begin; }
+step s1d { delete from ppk where a = 1; }
+step s1c { commit; }
+
+session s2
+step s2b { begin; }
+step s2bs { begin isolation level serializable; select 1; }
+step s2i { insert into pfk values (1); }
+step s2c { commit; }
+
+teardown { drop table ppk, pfk, pfk1; }
+
+permutation s1b s1d s2b s2i s1c s2c
+permutation s1b s1d s2bs s2i s1c s2c
+permutation s1b s2b s1d s2i s1c s2c
+permutation s1b s2bs s1d s2i s1c s2c
+permutation s1b s2b s2i s1d s2c s1c
+permutation s1b s2bs s2i s1d s2c s1c
diff --git a/src/test/isolation/specs/freeze-the-dead.spec b/src/test/isolation/specs/freeze-the-dead.spec
new file mode 100644
index 0000000..6c34904
--- /dev/null
+++ b/src/test/isolation/specs/freeze-the-dead.spec
@@ -0,0 +1,56 @@
+# Test for interactions of tuple freezing with dead, as well as recently-dead
+# tuples using multixacts via FOR KEY SHARE.
+setup
+{
+ CREATE TABLE tab_freeze (
+ id int PRIMARY KEY,
+ name char(3),
+ x int);
+ INSERT INTO tab_freeze VALUES (1, '111', 0);
+ INSERT INTO tab_freeze VALUES (3, '333', 0);
+}
+
+teardown
+{
+ DROP TABLE tab_freeze;
+}
+
+session s1
+step s1_begin { BEGIN; }
+step s1_update { UPDATE tab_freeze SET x = x + 1 WHERE id = 3; }
+step s1_commit { COMMIT; }
+step s1_selectone {
+ BEGIN;
+ SET LOCAL enable_seqscan = false;
+ SET LOCAL enable_bitmapscan = false;
+ SELECT * FROM tab_freeze WHERE id = 3;
+ COMMIT;
+}
+step s1_selectall { SELECT * FROM tab_freeze ORDER BY name, id; }
+
+session s2
+step s2_begin { BEGIN; }
+step s2_key_share { SELECT id FROM tab_freeze WHERE id = 3 FOR KEY SHARE; }
+step s2_commit { COMMIT; }
+step s2_vacuum { VACUUM FREEZE tab_freeze; }
+
+session s3
+step s3_begin { BEGIN; }
+step s3_key_share { SELECT id FROM tab_freeze WHERE id = 3 FOR KEY SHARE; }
+step s3_commit { COMMIT; }
+
+# This permutation verifies that a previous bug
+# https://postgr.es/m/E5711E62-8FDF-4DCA-A888-C200BF6B5742@amazon.com
+# https://postgr.es/m/20171102112019.33wb7g5wp4zpjelu@alap3.anarazel.de
+# is not reintroduced. We used to make wrong pruning / freezing
+# decision for multixacts, which could lead to a) broken hot chains b)
+# dead rows being revived.
+permutation s1_begin s2_begin s3_begin # start transactions
+ s1_update s2_key_share s3_key_share # have xmax be a multi with an updater, updater being oldest xid
+ s1_update # create additional row version that has multis
+ s1_commit s2_commit # commit both updater and share locker
+ s2_vacuum # due to bug in freezing logic, we used to *not* prune updated row, and then froze it
+ s1_selectone # if hot chain is broken, the row can't be found via index scan
+ s3_commit # commit remaining open xact
+ s2_vacuum # pruning / freezing in broken hot chains would unset xmax, reviving rows
+ s1_selectall # show borkedness
diff --git a/src/test/isolation/specs/index-only-scan.spec b/src/test/isolation/specs/index-only-scan.spec
new file mode 100644
index 0000000..4e4171c
--- /dev/null
+++ b/src/test/isolation/specs/index-only-scan.spec
@@ -0,0 +1,46 @@
+# index-only scan test
+#
+# This test tries to expose problems with the interaction between index-only
+# scans and SSI.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE tabx (id int NOT NULL);
+ INSERT INTO tabx SELECT generate_series(1,10000);
+ ALTER TABLE tabx ADD PRIMARY KEY (id);
+ CREATE TABLE taby (id int NOT NULL);
+ INSERT INTO taby SELECT generate_series(1,10000);
+ ALTER TABLE taby ADD PRIMARY KEY (id);
+}
+setup { VACUUM FREEZE ANALYZE tabx; }
+setup { VACUUM FREEZE ANALYZE taby; }
+
+teardown
+{
+ DROP TABLE tabx;
+ DROP TABLE taby;
+}
+
+session s1
+setup
+{
+ BEGIN ISOLATION LEVEL SERIALIZABLE;
+ SET LOCAL seq_page_cost = 0.1;
+ SET LOCAL random_page_cost = 0.1;
+ SET LOCAL cpu_tuple_cost = 0.03;
+}
+step rxwy1 { DELETE FROM taby WHERE id = (SELECT min(id) FROM tabx); }
+step c1 { COMMIT; }
+
+session s2
+setup
+{
+ BEGIN ISOLATION LEVEL SERIALIZABLE;
+ SET LOCAL seq_page_cost = 0.1;
+ SET LOCAL random_page_cost = 0.1;
+ SET LOCAL cpu_tuple_cost = 0.03;
+}
+step rywx2 { DELETE FROM tabx WHERE id = (SELECT min(id) FROM taby); }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/inherit-temp.spec b/src/test/isolation/specs/inherit-temp.spec
new file mode 100644
index 0000000..644f919
--- /dev/null
+++ b/src/test/isolation/specs/inherit-temp.spec
@@ -0,0 +1,78 @@
+# Tests for inheritance trees with temporary relations
+#
+# Inheritance trees are allowed to mix relations with different persistence
+# as long as a persistent child relation does not try to inherit from a
+# temporary parent. This checks several scenarios with SELECT, INSERT, UPDATE,
+# DELETE and TRUNCATE. Any temporary relation inheriting from the same
+# persistent parent should be isolated and handled only in its own session.
+
+setup
+{
+ CREATE TABLE inh_parent (a int);
+}
+
+teardown
+{
+ DROP TABLE inh_parent;
+}
+
+# Session 1 executes actions which act directly on both the parent and
+# its child. Abbreviation "c" is used for queries working on the child
+# and "p" on the parent.
+session s1
+setup
+{
+ CREATE TEMPORARY TABLE inh_temp_child_s1 () INHERITS (inh_parent);
+}
+step s1_begin { BEGIN; }
+step s1_truncate_p { TRUNCATE inh_parent; }
+step s1_select_p { SELECT a FROM inh_parent; }
+step s1_select_c { SELECT a FROM inh_temp_child_s1; }
+step s1_insert_p { INSERT INTO inh_parent VALUES (1), (2); }
+step s1_insert_c { INSERT INTO inh_temp_child_s1 VALUES (3), (4); }
+step s1_update_p { UPDATE inh_parent SET a = 11 WHERE a = 1; }
+step s1_update_c { UPDATE inh_parent SET a = 13 WHERE a IN (3, 5); }
+step s1_delete_p { DELETE FROM inh_parent WHERE a = 2; }
+step s1_delete_c { DELETE FROM inh_parent WHERE a IN (4, 6); }
+step s1_commit { COMMIT; }
+teardown
+{
+ DROP TABLE inh_temp_child_s1;
+}
+
+# Session 2 executes actions on the parent which act only on the child.
+session s2
+setup
+{
+ CREATE TEMPORARY TABLE inh_temp_child_s2 () INHERITS (inh_parent);
+}
+step s2_truncate_p { TRUNCATE inh_parent; }
+step s2_select_p { SELECT a FROM inh_parent; }
+step s2_select_c { SELECT a FROM inh_temp_child_s2; }
+step s2_insert_c { INSERT INTO inh_temp_child_s2 VALUES (5), (6); }
+step s2_update_c { UPDATE inh_parent SET a = 15 WHERE a IN (3, 5); }
+step s2_delete_c { DELETE FROM inh_parent WHERE a IN (4, 6); }
+teardown
+{
+ DROP TABLE inh_temp_child_s2;
+}
+
+# Check INSERT behavior across sessions
+permutation s1_insert_p s1_insert_c s2_insert_c s1_select_p s1_select_c s2_select_p s2_select_c
+
+# Check UPDATE behavior across sessions
+permutation s1_insert_p s1_insert_c s2_insert_c s1_update_p s1_update_c s1_select_p s1_select_c s2_select_p s2_select_c
+permutation s1_insert_p s1_insert_c s2_insert_c s2_update_c s1_select_p s1_select_c s2_select_p s2_select_c
+
+# Check DELETE behavior across sessions
+permutation s1_insert_p s1_insert_c s2_insert_c s1_delete_p s1_delete_c s1_select_p s1_select_c s2_select_p s2_select_c
+permutation s1_insert_p s1_insert_c s2_insert_c s2_delete_c s1_select_p s1_select_c s2_select_p s2_select_c
+
+# Check TRUNCATE behavior across sessions
+permutation s1_insert_p s1_insert_c s2_insert_c s1_truncate_p s1_select_p s1_select_c s2_select_p s2_select_c
+permutation s1_insert_p s1_insert_c s2_insert_c s2_truncate_p s1_select_p s1_select_c s2_select_p s2_select_c
+
+# TRUNCATE on a parent tree does not block access to temporary child relation
+# of another session, and blocks when scanning the parent.
+permutation s1_insert_p s1_insert_c s2_insert_c s1_begin s1_truncate_p s2_select_p s1_commit
+permutation s1_insert_p s1_insert_c s2_insert_c s1_begin s1_truncate_p s2_select_c s1_commit
diff --git a/src/test/isolation/specs/insert-conflict-do-nothing-2.spec b/src/test/isolation/specs/insert-conflict-do-nothing-2.spec
new file mode 100644
index 0000000..825b7d6
--- /dev/null
+++ b/src/test/isolation/specs/insert-conflict-do-nothing-2.spec
@@ -0,0 +1,34 @@
+# INSERT...ON CONFLICT DO NOTHING test with multiple rows
+# in higher isolation levels
+
+setup
+{
+ CREATE TABLE ints (key int, val text, PRIMARY KEY (key) INCLUDE (val));
+}
+
+teardown
+{
+ DROP TABLE ints;
+}
+
+session s1
+step beginrr1 { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step begins1 { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step donothing1 { INSERT INTO ints(key, val) VALUES(1, 'donothing1') ON CONFLICT DO NOTHING; }
+step c1 { COMMIT; }
+step show { SELECT * FROM ints; }
+
+session s2
+step beginrr2 { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step begins2 { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step donothing2 { INSERT INTO ints(key, val) VALUES(1, 'donothing2'), (1, 'donothing3') ON CONFLICT DO NOTHING; }
+step c2 { COMMIT; }
+
+permutation beginrr1 beginrr2 donothing1 c1 donothing2 c2 show
+permutation beginrr1 beginrr2 donothing2 c2 donothing1 c1 show
+permutation beginrr1 beginrr2 donothing1 donothing2 c1 c2 show
+permutation beginrr1 beginrr2 donothing2 donothing1 c2 c1 show
+permutation begins1 begins2 donothing1 c1 donothing2 c2 show
+permutation begins1 begins2 donothing2 c2 donothing1 c1 show
+permutation begins1 begins2 donothing1 donothing2 c1 c2 show
+permutation begins1 begins2 donothing2 donothing1 c2 c1 show
diff --git a/src/test/isolation/specs/insert-conflict-do-nothing.spec b/src/test/isolation/specs/insert-conflict-do-nothing.spec
new file mode 100644
index 0000000..b0e6a37
--- /dev/null
+++ b/src/test/isolation/specs/insert-conflict-do-nothing.spec
@@ -0,0 +1,40 @@
+# INSERT...ON CONFLICT DO NOTHING test
+#
+# This test tries to expose problems with the interaction between concurrent
+# sessions during INSERT...ON CONFLICT DO NOTHING.
+#
+# The convention here is that session 1 always ends up inserting, and session 2
+# always ends up doing nothing.
+
+setup
+{
+ CREATE TABLE ints (key int primary key, val text);
+}
+
+teardown
+{
+ DROP TABLE ints;
+}
+
+session s1
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step donothing1 { INSERT INTO ints(key, val) VALUES(1, 'donothing1') ON CONFLICT DO NOTHING; }
+step c1 { COMMIT; }
+step a1 { ABORT; }
+
+session s2
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step donothing2 { INSERT INTO ints(key, val) VALUES(1, 'donothing2') ON CONFLICT DO NOTHING; }
+step select2 { SELECT * FROM ints; }
+step c2 { COMMIT; }
+
+# Regular case where one session block-waits on another to determine if it
+# should proceed with an insert or do nothing.
+permutation donothing1 donothing2 c1 select2 c2
+permutation donothing1 donothing2 a1 select2 c2
diff --git a/src/test/isolation/specs/insert-conflict-do-update-2.spec b/src/test/isolation/specs/insert-conflict-do-update-2.spec
new file mode 100644
index 0000000..8a7c546
--- /dev/null
+++ b/src/test/isolation/specs/insert-conflict-do-update-2.spec
@@ -0,0 +1,40 @@
+# INSERT...ON CONFLICT DO UPDATE test
+#
+# This test shows a plausible scenario in which the user might wish to UPDATE a
+# value that is also constrained by the unique index that is the arbiter of
+# whether the alternative path should be taken.
+
+setup
+{
+ CREATE TABLE upsert (key text not null, payload text);
+ CREATE UNIQUE INDEX ON upsert(lower(key)) INCLUDE (payload);
+}
+
+teardown
+{
+ DROP TABLE upsert;
+}
+
+session s1
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step insert1 { INSERT INTO upsert(key, payload) VALUES('FooFoo', 'insert1') ON CONFLICT (lower(key)) DO UPDATE set key = EXCLUDED.key, payload = upsert.payload || ' updated by insert1'; }
+step c1 { COMMIT; }
+step a1 { ABORT; }
+
+session s2
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step insert2 { INSERT INTO upsert(key, payload) VALUES('FOOFOO', 'insert2') ON CONFLICT (lower(key)) DO UPDATE set key = EXCLUDED.key, payload = upsert.payload || ' updated by insert2'; }
+step select2 { SELECT * FROM upsert; }
+step c2 { COMMIT; }
+
+# One session (session 2) block-waits on another (session 1) to determine if it
+# should proceed with an insert or update. The user can still usefully UPDATE
+# a column constrained by a unique index, as the example illustrates.
+permutation insert1 insert2 c1 select2 c2
+permutation insert1 insert2 a1 select2 c2
diff --git a/src/test/isolation/specs/insert-conflict-do-update-3.spec b/src/test/isolation/specs/insert-conflict-do-update-3.spec
new file mode 100644
index 0000000..df67954
--- /dev/null
+++ b/src/test/isolation/specs/insert-conflict-do-update-3.spec
@@ -0,0 +1,69 @@
+# INSERT...ON CONFLICT DO UPDATE test
+#
+# Other INSERT...ON CONFLICT DO UPDATE isolation tests illustrate the "MVCC
+# violation" added to facilitate the feature, whereby a
+# not-visible-to-our-snapshot tuple can be updated by our command all the same.
+# This is generally needed to provide a guarantee of a successful INSERT or
+# UPDATE in READ COMMITTED mode. This MVCC violation is quite distinct from
+# the putative "MVCC violation" that has existed in PostgreSQL for many years,
+# the EvalPlanQual() mechanism, because that mechanism always starts from a
+# tuple that is visible to the command's MVCC snapshot. This test illustrates
+# a slightly distinct user-visible consequence of the same MVCC violation
+# generally associated with INSERT...ON CONFLICT DO UPDATE. The impact of the
+# MVCC violation goes a little beyond updating MVCC-invisible tuples.
+#
+# With INSERT...ON CONFLICT DO UPDATE, the UPDATE predicate is only evaluated
+# once, on this conclusively-locked tuple, and not any other version of the
+# same tuple. It is therefore possible (in READ COMMITTED mode) that the
+# predicate "fail to be satisfied" according to the command's MVCC snapshot.
+# It might simply be that there is no row version visible, but it's also
+# possible that there is some row version visible, but only as a version that
+# doesn't satisfy the predicate. If, however, the conclusively-locked version
+# satisfies the predicate, that's good enough, and the tuple is updated. The
+# MVCC-snapshot-visible row version is denied the opportunity to prevent the
+# UPDATE from taking place, because we don't walk the UPDATE chain in the usual
+# way.
+
+setup
+{
+ CREATE TABLE colors (key int4 PRIMARY KEY, color text, is_active boolean);
+ INSERT INTO colors (key, color, is_active) VALUES(1, 'Red', false);
+ INSERT INTO colors (key, color, is_active) VALUES(2, 'Green', false);
+ INSERT INTO colors (key, color, is_active) VALUES(3, 'Blue', false);
+}
+
+teardown
+{
+ DROP TABLE colors;
+}
+
+session s1
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step insert1 {
+ WITH t AS (
+ INSERT INTO colors(key, color, is_active)
+ VALUES(1, 'Brown', true), (2, 'Gray', true)
+ ON CONFLICT (key) DO UPDATE
+ SET color = EXCLUDED.color
+ WHERE colors.is_active)
+ SELECT * FROM colors ORDER BY key;}
+step select1surprise { SELECT * FROM colors ORDER BY key; }
+step c1 { COMMIT; }
+
+session s2
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step update2 { UPDATE colors SET is_active = true WHERE key = 1; }
+step c2 { COMMIT; }
+
+# Perhaps surprisingly, the session 1 MVCC-snapshot-visible tuple (the tuple
+# with the pre-populated color 'Red') is denied the opportunity to prevent the
+# UPDATE from taking place -- only the conclusively-locked tuple version
+# matters, and so the tuple with key value 1 was updated to 'Brown' (but not
+# tuple with key value 2, since nothing changed there):
+permutation update2 insert1 c2 select1surprise c1
diff --git a/src/test/isolation/specs/insert-conflict-do-update.spec b/src/test/isolation/specs/insert-conflict-do-update.spec
new file mode 100644
index 0000000..62cdafd
--- /dev/null
+++ b/src/test/isolation/specs/insert-conflict-do-update.spec
@@ -0,0 +1,39 @@
+# INSERT...ON CONFLICT DO UPDATE test
+#
+# This test tries to expose problems with the interaction between concurrent
+# sessions.
+
+setup
+{
+ CREATE TABLE upsert (key int primary key, val text);
+}
+
+teardown
+{
+ DROP TABLE upsert;
+}
+
+session s1
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step insert1 { INSERT INTO upsert(key, val) VALUES(1, 'insert1') ON CONFLICT (key) DO UPDATE set val = upsert.val || ' updated by insert1'; }
+step c1 { COMMIT; }
+step a1 { ABORT; }
+
+session s2
+setup
+{
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+}
+step insert2 { INSERT INTO upsert(key, val) VALUES(1, 'insert2') ON CONFLICT (key) DO UPDATE set val = upsert.val || ' updated by insert2'; }
+step select2 { SELECT * FROM upsert; }
+step c2 { COMMIT; }
+
+# One session (session 2) block-waits on another (session 1) to determine if it
+# should proceed with an insert or update. Notably, this entails updating a
+# tuple while there is no version of that tuple visible to the updating
+# session's snapshot. This is permitted only in READ COMMITTED mode.
+permutation insert1 insert2 c1 select2 c2
+permutation insert1 insert2 a1 select2 c2
diff --git a/src/test/isolation/specs/insert-conflict-specconflict.spec b/src/test/isolation/specs/insert-conflict-specconflict.spec
new file mode 100644
index 0000000..55b8bb1
--- /dev/null
+++ b/src/test/isolation/specs/insert-conflict-specconflict.spec
@@ -0,0 +1,262 @@
+# INSERT ... ON CONFLICT test verifying that speculative insertion
+# failures are handled
+#
+# Does this by using advisory locks controlling progress of
+# insertions. By waiting when building the index keys, it's possible
+# to schedule concurrent INSERT ON CONFLICTs so that there will always
+# be a speculative conflict.
+
+setup
+{
+ CREATE OR REPLACE FUNCTION blurt_and_lock_123(text) RETURNS text IMMUTABLE LANGUAGE plpgsql AS $$
+ BEGIN
+ RAISE NOTICE 'blurt_and_lock_123() called for % in session %', $1, current_setting('spec.session')::int;
+
+ -- depending on lock state, wait for lock 2 or 3
+ IF pg_try_advisory_xact_lock(current_setting('spec.session')::int, 1) THEN
+ RAISE NOTICE 'acquiring advisory lock on 2';
+ PERFORM pg_advisory_xact_lock(current_setting('spec.session')::int, 2);
+ ELSE
+ RAISE NOTICE 'acquiring advisory lock on 3';
+ PERFORM pg_advisory_xact_lock(current_setting('spec.session')::int, 3);
+ END IF;
+ RETURN $1;
+ END;$$;
+
+ CREATE OR REPLACE FUNCTION blurt_and_lock_4(text) RETURNS text IMMUTABLE LANGUAGE plpgsql AS $$
+ BEGIN
+ RAISE NOTICE 'blurt_and_lock_4() called for % in session %', $1, current_setting('spec.session')::int;
+ RAISE NOTICE 'acquiring advisory lock on 4';
+ PERFORM pg_advisory_xact_lock(current_setting('spec.session')::int, 4);
+ RETURN $1;
+ END;$$;
+
+ CREATE OR REPLACE FUNCTION ctoast_large_val() RETURNS TEXT LANGUAGE SQL AS 'select array_agg(md5(g::text))::text from generate_series(1, 256) g';
+
+ CREATE TABLE upserttest(key text, data text);
+
+ CREATE UNIQUE INDEX upserttest_key_uniq_idx ON upserttest((blurt_and_lock_123(key)));
+}
+
+teardown
+{
+ DROP TABLE upserttest;
+}
+
+session controller
+setup
+{
+ SET default_transaction_isolation = 'read committed';
+ SET application_name = 'isolation/insert-conflict-specconflict-controller';
+}
+step controller_locks {SELECT pg_advisory_lock(sess, lock), sess, lock FROM generate_series(1, 2) a(sess), generate_series(1,3) b(lock);}
+step controller_unlock_1_1 { SELECT pg_advisory_unlock(1, 1); }
+step controller_unlock_2_1 { SELECT pg_advisory_unlock(2, 1); }
+step controller_unlock_1_2 { SELECT pg_advisory_unlock(1, 2); }
+step controller_unlock_2_2 { SELECT pg_advisory_unlock(2, 2); }
+step controller_unlock_1_3 { SELECT pg_advisory_unlock(1, 3); }
+step controller_unlock_2_3 { SELECT pg_advisory_unlock(2, 3); }
+step controller_lock_2_4 { SELECT pg_advisory_lock(2, 4); }
+step controller_unlock_2_4 { SELECT pg_advisory_unlock(2, 4); }
+step controller_show {SELECT * FROM upserttest; }
+step controller_show_count {SELECT COUNT(*) FROM upserttest; }
+step controller_print_speculative_locks {
+ SELECT pa.application_name, locktype, mode, granted
+ FROM pg_locks pl JOIN pg_stat_activity pa USING (pid)
+ WHERE
+ locktype IN ('spectoken', 'transactionid')
+ AND pa.datname = current_database()
+ AND pa.application_name LIKE 'isolation/insert-conflict-specconflict-s%'
+ ORDER BY 1, 2, 3, 4;
+}
+
+session s1
+setup
+{
+ SET default_transaction_isolation = 'read committed';
+ SET spec.session = 1;
+ SET application_name = 'isolation/insert-conflict-specconflict-s1';
+}
+step s1_begin { BEGIN; }
+step s1_create_non_unique_index { CREATE INDEX upserttest_key_idx ON upserttest((blurt_and_lock_4(key))); }
+step s1_confirm_index_order { SELECT 'upserttest_key_uniq_idx'::regclass::int8 < 'upserttest_key_idx'::regclass::int8; }
+step s1_upsert { INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; }
+step s1_insert_toast { INSERT INTO upserttest VALUES('k2', ctoast_large_val()) ON CONFLICT DO NOTHING; }
+step s1_commit { COMMIT; }
+step s1_noop { }
+
+session s2
+setup
+{
+ SET default_transaction_isolation = 'read committed';
+ SET spec.session = 2;
+ SET application_name = 'isolation/insert-conflict-specconflict-s2';
+}
+step s2_begin { BEGIN; }
+step s2_upsert { INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; }
+step s2_insert_toast { INSERT INTO upserttest VALUES('k2', ctoast_large_val()) ON CONFLICT DO NOTHING; }
+step s2_commit { COMMIT; }
+step s2_noop { }
+
+# Test that speculative locks are correctly acquired and released, s2
+# inserts, s1 updates.
+permutation
+ # acquire a number of locks, to control execution flow - the
+ # blurt_and_lock_123 function acquires advisory locks that allow us to
+ # continue after a) the optimistic conflict probe b) after the
+ # insertion of the speculative tuple.
+ controller_locks
+ controller_show
+ s1_upsert s2_upsert
+ controller_show
+ # Switch both sessions to wait on the other lock next time (the speculative insertion)
+ controller_unlock_1_1 controller_unlock_2_1
+ # Allow both sessions to continue
+ controller_unlock_1_3 controller_unlock_2_3
+ controller_show
+ # Allow the second session to finish insertion
+ controller_unlock_2_2
+ # This should now show a successful insertion
+ controller_show
+ # Allow the first session to finish insertion
+ controller_unlock_1_2
+ # This should now show a successful UPSERT
+ controller_show
+
+# Test that speculative locks are correctly acquired and released, s1
+# inserts, s2 updates.
+permutation
+ # acquire a number of locks, to control execution flow - the
+ # blurt_and_lock_123 function acquires advisory locks that allow us to
+ # continue after a) the optimistic conflict probe b) after the
+ # insertion of the speculative tuple.
+ controller_locks
+ controller_show
+ s1_upsert s2_upsert
+ controller_show
+ # Switch both sessions to wait on the other lock next time (the speculative insertion)
+ controller_unlock_1_1 controller_unlock_2_1
+ # Allow both sessions to continue
+ controller_unlock_1_3 controller_unlock_2_3
+ controller_show
+ # Allow the first session to finish insertion
+ controller_unlock_1_2
+ # This should now show a successful insertion
+ controller_show
+ # Allow the second session to finish insertion
+ controller_unlock_2_2
+ # This should now show a successful UPSERT
+ controller_show
+
+# Test that speculatively inserted toast rows do not cause conflicts.
+# s1 inserts successfully, s2 does not.
+permutation
+ # acquire a number of locks, to control execution flow - the
+ # blurt_and_lock_123 function acquires advisory locks that allow us to
+ # continue after a) the optimistic conflict probe b) after the
+ # insertion of the speculative tuple.
+ controller_locks
+ controller_show
+ s1_insert_toast s2_insert_toast
+ controller_show
+ # Switch both sessions to wait on the other lock next time (the speculative insertion)
+ controller_unlock_1_1 controller_unlock_2_1
+ # Allow both sessions to continue
+ controller_unlock_1_3 controller_unlock_2_3
+ controller_show
+ # Allow the first session to finish insertion
+ controller_unlock_1_2
+ # This should now show that 1 additional tuple was inserted successfully
+ controller_show_count
+ # Allow the second session to finish insertion and kill the speculatively inserted tuple
+ controller_unlock_2_2
+ # This should show the same number of tuples as before s2 inserted
+ controller_show_count
+
+# Test that speculative locks are correctly acquired and released, s2
+# inserts, s1 updates. With the added complication that transactions
+# don't immediately commit.
+permutation
+ # acquire a number of locks, to control execution flow - the
+ # blurt_and_lock_123 function acquires advisory locks that allow us to
+ # continue after a) the optimistic conflict probe b) after the
+ # insertion of the speculative tuple.
+ controller_locks
+ controller_show
+ s1_begin s2_begin
+ s1_upsert s2_upsert
+ controller_show
+ # Switch both sessions to wait on the other lock next time (the speculative insertion)
+ controller_unlock_1_1 controller_unlock_2_1
+ # Allow both sessions to continue
+ controller_unlock_1_3 controller_unlock_2_3
+ controller_show
+ # Allow the first session to finish insertion
+ controller_unlock_1_2
+ # But the change isn't visible yet, nor should the second session continue
+ controller_show
+ # Allow the second session to finish insertion, but it's blocked
+ controller_unlock_2_2
+ controller_show
+ # But committing should unblock
+ s1_commit
+ controller_show
+ s2_commit
+ controller_show
+
+# Test that speculative wait is performed if a session sees a speculatively
+# inserted tuple. A speculatively inserted tuple is one which has been inserted
+# both into the table and the unique index but has yet to *complete* the
+# speculative insertion
+permutation
+ # acquire a number of advisory locks to control execution flow - the
+ # blurt_and_lock_123 function acquires advisory locks that allow us to
+ # continue after a) the optimistic conflict probe and b) after the
+ # insertion of the speculative tuple.
+ # blurt_and_lock_4 acquires an advisory lock which allows us to pause
+ # execution c) before completing the speculative insertion
+
+ # create the second index here to avoid affecting the other
+ # permutations.
+ s1_create_non_unique_index
+ # confirm that the insertion into the unique index will happen first
+ s1_confirm_index_order
+ controller_locks
+ controller_show
+ s2_begin
+ # Both sessions wait on advisory locks
+ # (but don't show s2_upsert as complete till we've seen all of s1's notices)
+ s1_upsert s2_upsert (s1_upsert notices 10)
+ controller_show
+ # Switch both sessions to wait on the other lock next time (the speculative insertion)
+ controller_unlock_1_1 controller_unlock_2_1
+ # Allow both sessions to do the optimistic conflict probe and do the
+ # speculative insertion into the table
+ # They will then be waiting on another advisory lock when they attempt to
+ # update the index
+ controller_unlock_1_3 controller_unlock_2_3
+ controller_show
+ # take lock to block second session after inserting in unique index but
+ # before completing the speculative insert
+ controller_lock_2_4
+ # Allow the second session to move forward
+ controller_unlock_2_2
+ # This should still not show a successful insertion
+ controller_show
+ # Allow the first session to continue, it should perform speculative wait
+ controller_unlock_1_2
+ # Should report s1 is waiting on speculative lock
+ controller_print_speculative_locks
+ # Allow s2 to insert into the non-unique index and complete. s1 will
+ # no longer wait on speculative lock, but proceed to wait on the
+ # transaction to finish. The no-op step is needed to ensure that
+ # we don't advance to the reporting step until s2_upsert has completed.
+ controller_unlock_2_4 s2_noop
+ # Should report that s1 is now waiting for s2 to commit
+ controller_print_speculative_locks
+ # Once s2 commits, s1 is finally free to continue to update
+ s2_commit s1_noop
+ # This should now show a successful UPSERT
+ controller_show
+ # Ensure no unexpected locks survive
+ controller_print_speculative_locks
diff --git a/src/test/isolation/specs/lock-committed-keyupdate.spec b/src/test/isolation/specs/lock-committed-keyupdate.spec
new file mode 100644
index 0000000..487f0e0
--- /dev/null
+++ b/src/test/isolation/specs/lock-committed-keyupdate.spec
@@ -0,0 +1,66 @@
+# Test locking of a tuple with a committed key-update. In this case,
+# the update conflicts with the lock, so failures are expected, except
+# in READ COMMITTED isolation mode.
+#
+# Some of the permutations are commented out that work fine in the
+# lock-committed-update test, because in this case the update blocks.
+
+setup
+{
+ DROP TABLE IF EXISTS lcku_table;
+ CREATE TABLE lcku_table (id INTEGER, value TEXT, PRIMARY KEY (id) INCLUDE (value));
+ INSERT INTO lcku_table VALUES (1, 'one');
+ INSERT INTO lcku_table VALUES (3, 'two');
+}
+
+teardown
+{
+ DROP TABLE lcku_table;
+}
+
+session s1
+step s1b { BEGIN; }
+step s1l { SELECT pg_advisory_lock(578902068); }
+step s1u { UPDATE lcku_table SET id = 2 WHERE id = 3; }
+step s1hint { SELECT * FROM lcku_table; }
+step s1ul { SELECT pg_advisory_unlock(578902068); }
+step s1c { COMMIT; }
+teardown { SELECT pg_advisory_unlock_all(); }
+
+session s2
+step s2b1 { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s2b2 { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step s2b3 { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step s2l { SELECT * FROM lcku_table WHERE pg_advisory_lock(578902068) IS NOT NULL FOR KEY SHARE; }
+step s2c { COMMIT; }
+teardown { SELECT pg_advisory_unlock_all(); }
+
+permutation s1b s2b1 s1l s2l s1u s1c s1ul s2c
+permutation s1b s2b1 s1l s1u s2l s1c s1ul s2c
+#permutation s1b s2b1 s1l s2l s1ul s1u s1c s2c
+permutation s1b s2b1 s1l s1u s1ul s2l s1c s2c
+
+permutation s1b s2b1 s1l s2l s1u s1c s1hint s1ul s2c
+permutation s1b s2b1 s1l s1u s2l s1c s1hint s1ul s2c
+#permutation s1b s2b1 s1l s2l s1ul s1u s1c s1hint s2c
+permutation s1b s2b1 s1l s1u s1ul s2l s1c s1hint s2c
+
+permutation s1b s2b2 s1l s2l s1u s1c s1ul s2c
+permutation s1b s2b2 s1l s1u s2l s1c s1ul s2c
+#permutation s1b s2b2 s1l s2l s1ul s1u s1c s2c
+permutation s1b s2b2 s1l s1u s1ul s2l s1c s2c
+
+permutation s1b s2b2 s1l s2l s1u s1c s1hint s1ul s2c
+permutation s1b s2b2 s1l s1u s2l s1c s1hint s1ul s2c
+#permutation s1b s2b2 s1l s2l s1ul s1u s1c s1hint s2c
+permutation s1b s2b2 s1l s1u s1ul s2l s1c s1hint s2c
+
+permutation s1b s2b3 s1l s2l s1u s1c s1ul s2c
+permutation s1b s2b3 s1l s1u s2l s1c s1ul s2c
+#permutation s1b s2b3 s1l s2l s1ul s1u s1c s2c
+permutation s1b s2b3 s1l s1u s1ul s2l s1c s2c
+
+permutation s1b s2b3 s1l s2l s1u s1c s1hint s1ul s2c
+permutation s1b s2b3 s1l s1u s2l s1c s1hint s1ul s2c
+#permutation s1b s2b3 s1l s2l s1ul s1u s1c s1hint s2c
+permutation s1b s2b3 s1l s1u s1ul s2l s1c s1hint s2c
diff --git a/src/test/isolation/specs/lock-committed-update.spec b/src/test/isolation/specs/lock-committed-update.spec
new file mode 100644
index 0000000..74d80d5
--- /dev/null
+++ b/src/test/isolation/specs/lock-committed-update.spec
@@ -0,0 +1,62 @@
+# Test locking of a tuple with a committed update. When the lock does not
+# conflict with the update, no blocking and no serializability errors should
+# occur.
+
+setup
+{
+ DROP TABLE IF EXISTS lcu_table;
+ CREATE TABLE lcu_table (id INTEGER PRIMARY KEY, value TEXT);
+ INSERT INTO lcu_table VALUES (1, 'one');
+}
+
+teardown
+{
+ DROP TABLE lcu_table;
+}
+
+session s1
+step s1b { BEGIN; }
+step s1l { SELECT pg_advisory_lock(380170116); }
+step s1u { UPDATE lcu_table SET value = 'two' WHERE id = 1; }
+step s1hint { SELECT * FROM lcu_table; }
+step s1ul { SELECT pg_advisory_unlock(380170116); }
+step s1c { COMMIT; }
+teardown { SELECT pg_advisory_unlock_all(); }
+
+session s2
+step s2b1 { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s2b2 { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step s2b3 { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step s2l { SELECT * FROM lcu_table WHERE pg_advisory_lock(380170116) IS NOT NULL FOR KEY SHARE; }
+step s2c { COMMIT; }
+teardown { SELECT pg_advisory_unlock_all(); }
+
+permutation s1b s2b1 s1l s2l s1u s1c s1ul s2c
+permutation s1b s2b1 s1l s1u s2l s1c s1ul s2c
+permutation s1b s2b1 s1l s2l s1ul s1u s1c s2c
+permutation s1b s2b1 s1l s1u s1ul s2l s1c s2c
+
+permutation s1b s2b1 s1l s2l s1u s1c s1hint s1ul s2c
+permutation s1b s2b1 s1l s1u s2l s1c s1hint s1ul s2c
+permutation s1b s2b1 s1l s2l s1ul s1u s1c s1hint s2c
+permutation s1b s2b1 s1l s1u s1ul s2l s1c s1hint s2c
+
+permutation s1b s2b2 s1l s2l s1u s1c s1ul s2c
+permutation s1b s2b2 s1l s1u s2l s1c s1ul s2c
+permutation s1b s2b2 s1l s2l s1ul s1u s1c s2c
+permutation s1b s2b2 s1l s1u s1ul s2l s1c s2c
+
+permutation s1b s2b2 s1l s2l s1u s1c s1hint s1ul s2c
+permutation s1b s2b2 s1l s1u s2l s1c s1hint s1ul s2c
+permutation s1b s2b2 s1l s2l s1ul s1u s1c s1hint s2c
+permutation s1b s2b2 s1l s1u s1ul s2l s1c s1hint s2c
+
+permutation s1b s2b3 s1l s2l s1u s1c s1ul s2c
+permutation s1b s2b3 s1l s1u s2l s1c s1ul s2c
+permutation s1b s2b3 s1l s2l s1ul s1u s1c s2c
+permutation s1b s2b3 s1l s1u s1ul s2l s1c s2c
+
+permutation s1b s2b3 s1l s2l s1u s1c s1hint s1ul s2c
+permutation s1b s2b3 s1l s1u s2l s1c s1hint s1ul s2c
+permutation s1b s2b3 s1l s2l s1ul s1u s1c s1hint s2c
+permutation s1b s2b3 s1l s1u s1ul s2l s1c s1hint s2c
diff --git a/src/test/isolation/specs/lock-update-delete.spec b/src/test/isolation/specs/lock-update-delete.spec
new file mode 100644
index 0000000..b9dd7d1
--- /dev/null
+++ b/src/test/isolation/specs/lock-update-delete.spec
@@ -0,0 +1,61 @@
+# This test verifies behavior when traversing an update chain during
+# locking an old version of the tuple. There are three tests here:
+# 1. update the tuple, then delete it; a second transaction locks the
+# first version. This should raise an error if the DELETE succeeds,
+# but be allowed to continue if it aborts.
+# 2. Same as (1), except that instead of deleting the tuple, we merely
+# update its key. The behavior should be the same as for (1).
+# 3. Same as (2), except that we update the tuple without modifying its
+# key. In this case, no error should be raised.
+# When run in REPEATABLE READ or SERIALIZABLE transaction isolation levels, all
+# permutations that commit s2 cause a serializability error; all permutations
+# that rollback s2 can get through.
+#
+# We use an advisory lock (which is locked during s1's setup) to let s2 obtain
+# its snapshot early and only allow it to actually traverse the update chain
+# when s1 is done creating it.
+
+setup
+{
+ DROP TABLE IF EXISTS foo;
+ CREATE TABLE foo (
+ key int PRIMARY KEY,
+ value int
+ );
+
+ INSERT INTO foo VALUES (1, 1);
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+# obtain lock on the tuple, traversing its update chain
+step s1l { SELECT * FROM foo WHERE pg_advisory_xact_lock(0) IS NOT NULL AND key = 1 FOR KEY SHARE; }
+
+session s2
+setup { SELECT pg_advisory_lock(0); }
+step s2b { BEGIN; }
+step s2u { UPDATE foo SET value = 2 WHERE key = 1; }
+step s2_blocker1 { DELETE FROM foo; }
+step s2_blocker2 { UPDATE foo SET key = 2 WHERE key = 1; }
+step s2_blocker3 { UPDATE foo SET value = 2 WHERE key = 1; }
+step s2_unlock { SELECT pg_advisory_unlock(0); }
+step s2c { COMMIT; }
+step s2r { ROLLBACK; }
+
+permutation s2b s1l s2u s2_blocker1 s2_unlock s2c
+permutation s2b s1l s2u s2_blocker2 s2_unlock s2c
+permutation s2b s1l s2u s2_blocker3 s2_unlock s2c
+permutation s2b s1l s2u s2_blocker1 s2_unlock s2r
+permutation s2b s1l s2u s2_blocker2 s2_unlock s2r
+permutation s2b s1l s2u s2_blocker3 s2_unlock s2r
+
+permutation s2b s1l s2u s2_blocker1 s2c s2_unlock
+permutation s2b s1l s2u s2_blocker2 s2c s2_unlock
+permutation s2b s1l s2u s2_blocker3 s2c s2_unlock
+permutation s2b s1l s2u s2_blocker1 s2r s2_unlock
+permutation s2b s1l s2u s2_blocker2 s2r s2_unlock
+permutation s2b s1l s2u s2_blocker3 s2r s2_unlock
diff --git a/src/test/isolation/specs/lock-update-traversal.spec b/src/test/isolation/specs/lock-update-traversal.spec
new file mode 100644
index 0000000..9d3d32d
--- /dev/null
+++ b/src/test/isolation/specs/lock-update-traversal.spec
@@ -0,0 +1,39 @@
+# When a tuple that has been updated is locked, the locking command must
+# traverse the update chain; thus, a DELETE (on the newer version of the tuple)
+# should not be able to proceed until the lock has been released. An UPDATE
+# that changes the key should not be allowed to continue either; but an UPDATE
+# that doesn't modify the key should be able to continue immediately.
+
+setup
+{
+ CREATE TABLE foo (
+ key int,
+ value int,
+ PRIMARY KEY (key) INCLUDE (value)
+ );
+
+ INSERT INTO foo VALUES (1, 1);
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+step s1b { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step s1s { SELECT * FROM foo; } # obtain snapshot
+step s1l { SELECT * FROM foo FOR KEY SHARE; } # obtain lock
+step s1c { COMMIT; }
+
+session s2
+step s2b { BEGIN; }
+step s2u { UPDATE foo SET value = 2 WHERE key = 1; }
+step s2c { COMMIT; }
+step s2d1 { DELETE FROM foo WHERE key = 1; }
+step s2d2 { UPDATE foo SET key = 3 WHERE key = 1; }
+step s2d3 { UPDATE foo SET value = 3 WHERE key = 1; }
+
+permutation s1b s2b s1s s2u s1l s2c s2d1 s1c
+permutation s1b s2b s1s s2u s1l s2c s2d2 s1c
+permutation s1b s2b s1s s2u s1l s2c s2d3 s1c
diff --git a/src/test/isolation/specs/multiple-cic.spec b/src/test/isolation/specs/multiple-cic.spec
new file mode 100644
index 0000000..e34a6b0
--- /dev/null
+++ b/src/test/isolation/specs/multiple-cic.spec
@@ -0,0 +1,43 @@
+# Test multiple CREATE INDEX CONCURRENTLY working simultaneously
+
+setup
+{
+ CREATE TABLE mcic_one (
+ id int
+ );
+ CREATE TABLE mcic_two (
+ id int
+ );
+ CREATE FUNCTION lck_shr(bigint) RETURNS bool IMMUTABLE LANGUAGE plpgsql AS $$
+ BEGIN PERFORM pg_advisory_lock_shared($1); RETURN true; END;
+ $$;
+ CREATE FUNCTION unlck() RETURNS bool IMMUTABLE LANGUAGE plpgsql AS $$
+ BEGIN PERFORM pg_advisory_unlock_all(); RETURN true; END;
+ $$;
+}
+teardown
+{
+ DROP TABLE mcic_one, mcic_two;
+ DROP FUNCTION lck_shr(bigint);
+ DROP FUNCTION unlck();
+}
+
+session s1
+step s1i {
+ CREATE INDEX CONCURRENTLY mcic_one_pkey ON mcic_one (id)
+ WHERE lck_shr(281457);
+ }
+teardown { SELECT unlck(); }
+
+
+session s2
+step s2l { SELECT pg_advisory_lock(281457); }
+step s2i {
+ CREATE INDEX CONCURRENTLY mcic_two_pkey ON mcic_two (id)
+ WHERE unlck();
+ }
+
+# (*) marker ensures that s2i is reported as "waiting", even if it
+# completes very quickly
+
+permutation s2l s1i s2i(*)
diff --git a/src/test/isolation/specs/multiple-row-versions.spec b/src/test/isolation/specs/multiple-row-versions.spec
new file mode 100644
index 0000000..0779ea0
--- /dev/null
+++ b/src/test/isolation/specs/multiple-row-versions.spec
@@ -0,0 +1,47 @@
+# Multiple Row Versions test
+#
+# This test is designed to cover some code paths which only occur with
+# four or more transactions interacting with particular timings.
+#
+# Due to long permutation setup time, we are only testing one specific
+# permutation, which should get a serialization error.
+
+setup
+{
+ CREATE TABLE t (id int NOT NULL, txt text) WITH (fillfactor=50);
+ INSERT INTO t (id)
+ SELECT x FROM (SELECT * FROM generate_series(1, 1000000)) a(x);
+ ALTER TABLE t ADD PRIMARY KEY (id);
+}
+
+teardown
+{
+ DROP TABLE t;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rx1 { SELECT * FROM t WHERE id = 1000000; }
+# delay until after T3 commits
+step wz1 { UPDATE t SET txt = 'a' WHERE id = 1; }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wx2 { UPDATE t SET txt = 'b' WHERE id = 1000000; }
+step c2 { COMMIT; }
+
+session s3
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wx3 { UPDATE t SET txt = 'c' WHERE id = 1000000; }
+step ry3 { SELECT * FROM t WHERE id = 500000; }
+# delay until after T4 commits
+step c3 { COMMIT; }
+
+session s4
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wy4 { UPDATE t SET txt = 'd' WHERE id = 500000; }
+step rz4 { SELECT * FROM t WHERE id = 1; }
+step c4 { COMMIT; }
+
+permutation rx1 wx2 c2 wx3 ry3 wy4 rz4 c4 c3 wz1 c1
diff --git a/src/test/isolation/specs/multixact-no-deadlock.spec b/src/test/isolation/specs/multixact-no-deadlock.spec
new file mode 100644
index 0000000..a8af724
--- /dev/null
+++ b/src/test/isolation/specs/multixact-no-deadlock.spec
@@ -0,0 +1,35 @@
+# If we already hold a lock of a given strength, do not deadlock when
+# some other transaction is waiting for a conflicting lock and we try
+# to acquire the same lock we already held.
+setup
+{
+ CREATE TABLE justthis (
+ value int
+ );
+
+ INSERT INTO justthis VALUES (1);
+}
+
+teardown
+{
+ DROP TABLE justthis;
+}
+
+session s1
+setup { BEGIN; }
+step s1lock { SELECT * FROM justthis FOR SHARE; }
+step s1svpt { SAVEPOINT foo; }
+step s1lock2 { SELECT * FROM justthis FOR SHARE; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2lock { SELECT * FROM justthis FOR SHARE; } # ensure it's a multi
+step s2c { COMMIT; }
+
+session s3
+setup { BEGIN; }
+step s3lock { SELECT * FROM justthis FOR UPDATE; }
+step s3c { COMMIT; }
+
+permutation s1lock s2lock s1svpt s3lock s1lock2 s2c s1c s3c
diff --git a/src/test/isolation/specs/multixact-no-forget.spec b/src/test/isolation/specs/multixact-no-forget.spec
new file mode 100644
index 0000000..7f8a38b
--- /dev/null
+++ b/src/test/isolation/specs/multixact-no-forget.spec
@@ -0,0 +1,44 @@
+# If transaction A holds a lock, and transaction B does an update,
+# make sure we don't forget the lock if B aborts.
+setup
+{
+ CREATE TABLE dont_forget (
+ value int
+ );
+
+ INSERT INTO dont_forget VALUES (1);
+}
+
+teardown
+{
+ DROP TABLE dont_forget;
+}
+
+session s1
+setup { BEGIN; }
+step s1_show { SELECT current_setting('default_transaction_isolation') <> 'read committed'; }
+step s1_lock { SELECT * FROM dont_forget FOR KEY SHARE; }
+step s1_commit { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2_update { UPDATE dont_forget SET value = 2; }
+step s2_abort { ROLLBACK; }
+step s2_commit { COMMIT; }
+
+session s3
+# try cases with both a non-conflicting lock with s1's and a conflicting one
+step s3_forkeyshr { SELECT * FROM dont_forget FOR KEY SHARE; }
+step s3_fornokeyupd { SELECT * FROM dont_forget FOR NO KEY UPDATE; }
+step s3_forupd { SELECT * FROM dont_forget FOR UPDATE; }
+
+permutation s1_show s1_commit s2_commit
+permutation s1_lock s2_update s2_abort s3_forkeyshr s1_commit
+permutation s1_lock s2_update s2_commit s3_forkeyshr s1_commit
+permutation s1_lock s2_update s1_commit s3_forkeyshr s2_commit
+permutation s1_lock s2_update s2_abort s3_fornokeyupd s1_commit
+permutation s1_lock s2_update s2_commit s3_fornokeyupd s1_commit
+permutation s1_lock s2_update s1_commit s3_fornokeyupd s2_commit
+permutation s1_lock s2_update s2_abort s3_forupd s1_commit
+permutation s1_lock s2_update s2_commit s3_forupd s1_commit
+permutation s1_lock s2_update s1_commit s3_forupd s2_commit
diff --git a/src/test/isolation/specs/nowait-2.spec b/src/test/isolation/specs/nowait-2.spec
new file mode 100644
index 0000000..cf892f2
--- /dev/null
+++ b/src/test/isolation/specs/nowait-2.spec
@@ -0,0 +1,37 @@
+# Test NOWAIT with multixact locks.
+
+setup
+{
+ CREATE TABLE foo (
+ id int PRIMARY KEY,
+ data text NOT NULL
+ );
+ INSERT INTO foo VALUES (1, 'x');
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM foo FOR SHARE NOWAIT; }
+step s1b { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2a { SELECT * FROM foo FOR SHARE NOWAIT; }
+step s2b { SELECT * FROM foo FOR UPDATE NOWAIT; }
+step s2c { COMMIT; }
+
+# s1 and s2 both get SHARE lock, creating a multixact lock, then s2
+# tries to upgrade to UPDATE but aborts because it cannot acquire a
+# multi-xact lock
+permutation s1a s2a s2b s1b s2c
+# the same but with the SHARE locks acquired in a different order, so
+# s2 again aborts because it can't acquired a multi-xact lock
+permutation s2a s1a s2b s1b s2c
+# s2 acquires SHARE then UPDATE, then s1 tries to acquire SHARE but
+# can't so aborts because it can't acquire a regular lock
+permutation s2a s2b s1a s1b s2c
diff --git a/src/test/isolation/specs/nowait-3.spec b/src/test/isolation/specs/nowait-3.spec
new file mode 100644
index 0000000..06fb762
--- /dev/null
+++ b/src/test/isolation/specs/nowait-3.spec
@@ -0,0 +1,33 @@
+# Test NOWAIT with tuple locks.
+
+setup
+{
+ CREATE TABLE foo (
+ id int PRIMARY KEY,
+ data text NOT NULL
+ );
+ INSERT INTO foo VALUES (1, 'x');
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM foo FOR UPDATE; }
+step s1b { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2a { SELECT * FROM foo FOR UPDATE; }
+step s2b { COMMIT; }
+
+session s3
+setup { BEGIN; }
+step s3a { SELECT * FROM foo FOR UPDATE NOWAIT; }
+step s3b { COMMIT; }
+
+# s3 skips to second record due to tuple lock held by s2
+permutation s1a s2a s3a s1b s2b s3b
diff --git a/src/test/isolation/specs/nowait-4.spec b/src/test/isolation/specs/nowait-4.spec
new file mode 100644
index 0000000..da80330
--- /dev/null
+++ b/src/test/isolation/specs/nowait-4.spec
@@ -0,0 +1,35 @@
+# Test NOWAIT with an updated tuple chain.
+
+setup
+{
+ CREATE TABLE foo (
+ id int PRIMARY KEY,
+ data text NOT NULL
+ );
+ INSERT INTO foo VALUES (1, 'x');
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM foo WHERE pg_advisory_lock(0) IS NOT NULL FOR UPDATE NOWAIT; }
+step s1b { COMMIT; }
+
+session s2
+step s2a { SELECT pg_advisory_lock(0); }
+step s2b { UPDATE foo SET data = data; }
+step s2c { BEGIN; }
+step s2d { UPDATE foo SET data = data; }
+step s2e { SELECT pg_advisory_unlock(0); }
+step s2f { COMMIT; }
+
+# s1 takes a snapshot but then waits on an advisory lock, then s2
+# updates the row in one transaction, then again in another without
+# committing, before allowing s1 to proceed to try to lock a row;
+# because it has a snapshot that sees the older version, we reach the
+# waiting code in EvalPlanQualFetch which ereports when in NOWAIT mode.
+permutation s2a s1a s2b s2c s2d s2e s1b s2f
diff --git a/src/test/isolation/specs/nowait-5.spec b/src/test/isolation/specs/nowait-5.spec
new file mode 100644
index 0000000..46108de
--- /dev/null
+++ b/src/test/isolation/specs/nowait-5.spec
@@ -0,0 +1,57 @@
+# Test NOWAIT on an updated tuple chain
+
+setup
+{
+
+ DROP TABLE IF EXISTS test_nowait;
+ CREATE TABLE test_nowait (
+ id integer PRIMARY KEY,
+ value integer not null
+ );
+
+ INSERT INTO test_nowait
+ SELECT x,x FROM generate_series(1,2) x;
+}
+
+teardown
+{
+ DROP TABLE test_nowait;
+}
+
+session sl1
+step sl1_prep {
+ PREPARE sl1_run AS SELECT id FROM test_nowait WHERE pg_advisory_lock(0) is not null FOR UPDATE NOWAIT;
+}
+step sl1_exec {
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+ EXECUTE sl1_run;
+ SELECT xmin, xmax, ctid, * FROM test_nowait;
+}
+teardown { COMMIT; }
+
+# A session that's used for an UPDATE of the rows to be locked, for when we're testing ctid
+# chain following.
+session upd
+step upd_getlock {
+ SELECT pg_advisory_lock(0);
+}
+step upd_doupdate {
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+ UPDATE test_nowait SET value = value WHERE id % 2 = 0;
+ COMMIT;
+}
+step upd_releaselock {
+ SELECT pg_advisory_unlock(0);
+}
+
+# A session that acquires locks that sl1 is supposed to avoid blocking on
+session lk1
+step lk1_doforshare {
+ BEGIN ISOLATION LEVEL READ COMMITTED;
+ SELECT id FROM test_nowait WHERE id % 2 = 0 FOR SHARE;
+}
+teardown {
+ COMMIT;
+}
+
+permutation sl1_prep upd_getlock sl1_exec upd_doupdate lk1_doforshare upd_releaselock
diff --git a/src/test/isolation/specs/nowait.spec b/src/test/isolation/specs/nowait.spec
new file mode 100644
index 0000000..a75e54c
--- /dev/null
+++ b/src/test/isolation/specs/nowait.spec
@@ -0,0 +1,25 @@
+# Test NOWAIT when regular row locks can't be acquired.
+
+setup
+{
+ CREATE TABLE foo (
+ id int PRIMARY KEY,
+ data text NOT NULL
+ );
+ INSERT INTO foo VALUES (1, 'x');
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM foo FOR UPDATE NOWAIT; }
+step s1b { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2a { SELECT * FROM foo FOR UPDATE NOWAIT; }
+step s2b { COMMIT; }
diff --git a/src/test/isolation/specs/partial-index.spec b/src/test/isolation/specs/partial-index.spec
new file mode 100644
index 0000000..c033841
--- /dev/null
+++ b/src/test/isolation/specs/partial-index.spec
@@ -0,0 +1,32 @@
+# Partial Index test
+#
+# Make sure that an update which moves a row out of a partial index
+# is handled correctly. In early versions, an attempt at optimization
+# broke this behavior, allowing anomalies.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ create table test_t (id integer, val1 text, val2 integer);
+ create index test_idx on test_t(id) where val2 = 1;
+ insert into test_t (select generate_series(0, 10000), 'a', 2);
+ insert into test_t (select generate_series(0, 10), 'a', 1);
+}
+
+teardown
+{
+ DROP TABLE test_t;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rxy1 { select * from test_t where val2 = 1; }
+step wx1 { update test_t set val2 = 2 where val2 = 1 and id = 10; }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wy2 { update test_t set val2 = 2 where val2 = 1 and id = 9; }
+step rxy2 { select * from test_t where val2 = 1; }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/partition-concurrent-attach.spec b/src/test/isolation/specs/partition-concurrent-attach.spec
new file mode 100644
index 0000000..fcd4dce
--- /dev/null
+++ b/src/test/isolation/specs/partition-concurrent-attach.spec
@@ -0,0 +1,43 @@
+# Verify that default partition constraint is enforced correctly
+# in light of partitions being added concurrently to its parent
+setup {
+ drop table if exists tpart;
+ create table tpart(i int, j text) partition by range(i);
+ create table tpart_1(like tpart);
+ create table tpart_2(like tpart);
+ create table tpart_default (a int, j text, i int) partition by list (j);
+ create table tpart_default_default (a int, i int, b int, j text);
+ alter table tpart_default_default drop b;
+ alter table tpart_default attach partition tpart_default_default default;
+ alter table tpart_default drop a;
+ alter table tpart attach partition tpart_default default;
+ alter table tpart attach partition tpart_1 for values from(0) to (100);
+ insert into tpart_2 values (110,'xxx'), (120, 'yyy'), (150, 'zzz');
+}
+
+session s1
+step s1b { begin; }
+step s1a { alter table tpart attach partition tpart_2 for values from (100) to (200); }
+step s1c { commit; }
+
+session s2
+step s2b { begin; }
+step s2i { insert into tpart values (110,'xxx'), (120, 'yyy'), (150, 'zzz'); }
+step s2i2 { insert into tpart_default (i, j) values (110, 'xxx'), (120, 'yyy'), (150, 'zzz'); }
+step s2c { commit; }
+step s2s { select tableoid::regclass, * from tpart; }
+
+teardown { drop table tpart; }
+
+# insert into tpart by s2 which routes to tpart_default due to not seeing
+# concurrently added tpart_2 should fail, because the partition constraint
+# of tpart_default would have changed due to tpart_2 having been added
+permutation s1b s1a s2b s2i s1c s2c s2s
+
+# similar to above, but now insert into sub-partitioned tpart_default
+permutation s1b s1a s2b s2i2 s1c s2c s2s
+
+# reverse: now the insert into tpart_default by s2 occurs first followed by
+# attach in s1, which should fail when it scans the leaf default partition
+# find the violating rows
+permutation s1b s2b s2i s1a s2c s1c s2s
diff --git a/src/test/isolation/specs/partition-key-update-1.spec b/src/test/isolation/specs/partition-key-update-1.spec
new file mode 100644
index 0000000..6b5f422
--- /dev/null
+++ b/src/test/isolation/specs/partition-key-update-1.spec
@@ -0,0 +1,86 @@
+# Test that an error if thrown if the target row has been moved to a
+# different partition by a concurrent session.
+
+setup
+{
+ --
+ -- Setup to test an error from ExecUpdate and ExecDelete.
+ --
+ CREATE TABLE foo (a int, b text) PARTITION BY LIST(a);
+ CREATE TABLE foo1 PARTITION OF foo FOR VALUES IN (1);
+ CREATE TABLE foo2 PARTITION OF foo FOR VALUES IN (2);
+ INSERT INTO foo VALUES (1, 'ABC');
+
+ --
+ -- Setup to test an error from GetTupleForTrigger
+ --
+ CREATE TABLE footrg (a int, b text) PARTITION BY LIST(a);
+ CREATE TABLE footrg1 PARTITION OF footrg FOR VALUES IN (1);
+ CREATE TABLE footrg2 PARTITION OF footrg FOR VALUES IN (2);
+ INSERT INTO footrg VALUES (1, 'ABC');
+ CREATE FUNCTION func_footrg_mod_a() RETURNS TRIGGER AS $$
+ BEGIN
+ NEW.a = 2; -- This is changing partition key column.
+ RETURN NEW;
+ END $$ LANGUAGE PLPGSQL;
+ CREATE TRIGGER footrg_mod_a BEFORE UPDATE ON footrg1
+ FOR EACH ROW EXECUTE PROCEDURE func_footrg_mod_a();
+
+ --
+ -- Setup to test an error from ExecLockRows
+ --
+ CREATE TABLE foo_range_parted (a int, b text) PARTITION BY RANGE(a);
+ CREATE TABLE foo_range_parted1 PARTITION OF foo_range_parted FOR VALUES FROM (1) TO (10);
+ CREATE TABLE foo_range_parted2 PARTITION OF foo_range_parted FOR VALUES FROM (10) TO (20);
+ INSERT INTO foo_range_parted VALUES(7, 'ABC');
+ CREATE UNIQUE INDEX foo_range_parted1_a_unique ON foo_range_parted1 (a);
+ CREATE TABLE bar (a int REFERENCES foo_range_parted1(a));
+}
+
+teardown
+{
+ DROP TABLE foo;
+ DROP TRIGGER footrg_mod_a ON footrg1;
+ DROP FUNCTION func_footrg_mod_a();
+ DROP TABLE footrg;
+ DROP TABLE bar, foo_range_parted;
+}
+
+session s1
+step s1b { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s1u { UPDATE foo SET a=2 WHERE a=1; }
+step s1u2 { UPDATE footrg SET b='EFG' WHERE a=1; }
+step s1u3pc { UPDATE foo_range_parted SET a=11 WHERE a=7; }
+step s1u3npc { UPDATE foo_range_parted SET b='XYZ' WHERE a=7; }
+step s1c { COMMIT; }
+step s1r { ROLLBACK; }
+
+session s2
+step s2b { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s2u { UPDATE foo SET b='EFG' WHERE a=1; }
+step s2u2 { UPDATE footrg SET b='XYZ' WHERE a=1; }
+step s2i { INSERT INTO bar VALUES(7); }
+step s2d { DELETE FROM foo WHERE a=1; }
+step s2c { COMMIT; }
+
+# Concurrency error from ExecUpdate and ExecDelete.
+permutation s1b s2b s1u s1c s2d s2c
+permutation s1b s2b s1u s2d s1c s2c
+permutation s1b s2b s1u s2u s1c s2c
+permutation s1b s2b s2d s1u s2c s1c
+
+# Concurrency error from GetTupleForTrigger
+permutation s1b s2b s1u2 s1c s2u2 s2c
+permutation s1b s2b s1u2 s2u2 s1c s2c
+permutation s1b s2b s2u2 s1u2 s2c s1c
+
+# Concurrency error from ExecLockRows
+# test waiting for moved row itself
+permutation s1b s2b s1u3pc s2i s1c s2c
+permutation s1b s2b s1u3pc s2i s1r s2c
+# test waiting for in-partition update, followed by cross-partition move
+permutation s1b s2b s1u3npc s1u3pc s2i s1c s2c
+permutation s1b s2b s1u3npc s1u3pc s2i s1r s2c
+# test waiting for in-partition update, followed by cross-partition move
+permutation s1b s2b s1u3npc s1u3pc s1u3pc s2i s1c s2c
+permutation s1b s2b s1u3npc s1u3pc s1u3pc s2i s1r s2c
diff --git a/src/test/isolation/specs/partition-key-update-2.spec b/src/test/isolation/specs/partition-key-update-2.spec
new file mode 100644
index 0000000..d4cd09b
--- /dev/null
+++ b/src/test/isolation/specs/partition-key-update-2.spec
@@ -0,0 +1,45 @@
+# Concurrent update of a partition key and INSERT...ON CONFLICT DO NOTHING test
+#
+# This test tries to expose problems with the interaction between concurrent
+# sessions during an update of the partition key and INSERT...ON CONFLICT DO
+# NOTHING on a partitioned table.
+#
+# The convention here is that session 1 moves row from one partition to
+# another due update of the partition key and session 2 always ends up
+# inserting, and session 3 always ends up doing nothing.
+#
+# Note: This test is slightly resemble to insert-conflict-do-nothing test.
+
+setup
+{
+ CREATE TABLE foo (a int primary key, b text) PARTITION BY LIST(a);
+ CREATE TABLE foo1 PARTITION OF foo FOR VALUES IN (1);
+ CREATE TABLE foo2 PARTITION OF foo FOR VALUES IN (2);
+ INSERT INTO foo VALUES (1, 'initial tuple');
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s1u { UPDATE foo SET a=2, b=b || ' -> moved by session-1' WHERE a=1; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s2donothing { INSERT INTO foo VALUES(1, 'session-2 donothing') ON CONFLICT DO NOTHING; }
+step s2c { COMMIT; }
+
+session s3
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s3donothing { INSERT INTO foo VALUES(2, 'session-3 donothing') ON CONFLICT DO NOTHING; }
+step s3select { SELECT * FROM foo ORDER BY a; }
+step s3c { COMMIT; }
+
+# Regular case where one session block-waits on another to determine if it
+# should proceed with an insert or do nothing.
+permutation s1u s2donothing s3donothing s1c s2c s3select s3c
+permutation s2donothing s1u s3donothing s1c s2c s3select s3c
diff --git a/src/test/isolation/specs/partition-key-update-3.spec b/src/test/isolation/specs/partition-key-update-3.spec
new file mode 100644
index 0000000..d2883e3
--- /dev/null
+++ b/src/test/isolation/specs/partition-key-update-3.spec
@@ -0,0 +1,44 @@
+# Concurrent update of a partition key and INSERT...ON CONFLICT DO NOTHING
+# test on partitioned table with multiple rows in higher isolation levels.
+#
+# Note: This test is resemble to insert-conflict-do-nothing-2 test
+
+setup
+{
+ CREATE TABLE foo (a int primary key, b text) PARTITION BY LIST(a);
+ CREATE TABLE foo1 PARTITION OF foo FOR VALUES IN (1);
+ CREATE TABLE foo2 PARTITION OF foo FOR VALUES IN (2);
+ INSERT INTO foo VALUES (1, 'initial tuple');
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s1u { UPDATE foo SET a=2, b=b || ' -> moved by session-1' WHERE a=1; }
+step s1c { COMMIT; }
+
+session s2
+step s2beginrr { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step s2begins { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step s2donothing { INSERT INTO foo VALUES(1, 'session-2 donothing') ON CONFLICT DO NOTHING; }
+step s2c { COMMIT; }
+step s2select { SELECT * FROM foo ORDER BY a; }
+
+session s3
+step s3beginrr { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step s3begins { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step s3donothing { INSERT INTO foo VALUES(2, 'session-3 donothing'), (2, 'session-3 donothing2') ON CONFLICT DO NOTHING; }
+step s3c { COMMIT; }
+
+permutation s2beginrr s3beginrr s1u s2donothing s1c s2c s3donothing s3c s2select
+permutation s2beginrr s3beginrr s1u s3donothing s1c s3c s2donothing s2c s2select
+permutation s2beginrr s3beginrr s1u s2donothing s3donothing s1c s2c s3c s2select
+permutation s2beginrr s3beginrr s1u s3donothing s2donothing s1c s3c s2c s2select
+permutation s2begins s3begins s1u s2donothing s1c s2c s3donothing s3c s2select
+permutation s2begins s3begins s1u s3donothing s1c s3c s2donothing s2c s2select
+permutation s2begins s3begins s1u s2donothing s3donothing s1c s2c s3c s2select
+permutation s2begins s3begins s1u s3donothing s2donothing s1c s3c s2c s2select
diff --git a/src/test/isolation/specs/partition-key-update-4.spec b/src/test/isolation/specs/partition-key-update-4.spec
new file mode 100644
index 0000000..6c70816
--- /dev/null
+++ b/src/test/isolation/specs/partition-key-update-4.spec
@@ -0,0 +1,76 @@
+# Test that a row that ends up in a new partition contains changes made by
+# a concurrent transaction.
+
+setup
+{
+ --
+ -- Setup to test concurrent handling of ExecDelete().
+ --
+ CREATE TABLE foo (a int, b text) PARTITION BY LIST(a);
+ CREATE TABLE foo1 PARTITION OF foo FOR VALUES IN (1);
+ CREATE TABLE foo2 PARTITION OF foo FOR VALUES IN (2);
+ INSERT INTO foo VALUES (1, 'ABC');
+
+ --
+ -- Setup to test concurrent handling of GetTupleForTrigger().
+ --
+ CREATE TABLE footrg (a int, b text) PARTITION BY LIST(a);
+ CREATE TABLE triglog as select * from footrg;
+ CREATE TABLE footrg1 PARTITION OF footrg FOR VALUES IN (1);
+ CREATE TABLE footrg2 PARTITION OF footrg FOR VALUES IN (2);
+ INSERT INTO footrg VALUES (1, 'ABC');
+ CREATE FUNCTION func_footrg() RETURNS TRIGGER AS $$
+ BEGIN
+ OLD.b = OLD.b || ' trigger';
+
+ -- This will verify that the trigger is not run *before* the row is
+ -- refetched by EvalPlanQual. The OLD row should contain the changes made
+ -- by the concurrent session.
+ INSERT INTO triglog select OLD.*;
+
+ RETURN OLD;
+ END $$ LANGUAGE PLPGSQL;
+ CREATE TRIGGER footrg_ondel BEFORE DELETE ON footrg1
+ FOR EACH ROW EXECUTE PROCEDURE func_footrg();
+
+}
+
+teardown
+{
+ DROP TABLE foo;
+ DROP TRIGGER footrg_ondel ON footrg1;
+ DROP FUNCTION func_footrg();
+ DROP TABLE footrg;
+ DROP TABLE triglog;
+}
+
+session s1
+step s1b { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s1u { UPDATE foo SET a = a + 1, b = b || ' update1' WHERE b like '%ABC%'; }
+step s1ut { UPDATE footrg SET a = a + 1, b = b || ' update1' WHERE b like '%ABC%'; }
+step s1s { SELECT tableoid::regclass, * FROM foo ORDER BY a; }
+step s1st { SELECT tableoid::regclass, * FROM footrg ORDER BY a; }
+step s1stl { SELECT * FROM triglog ORDER BY a; }
+step s1c { COMMIT; }
+
+session s2
+step s2b { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s2u1 { UPDATE foo SET b = b || ' update2' WHERE a = 1; }
+step s2u2 { UPDATE foo SET b = 'EFG' WHERE a = 1; }
+step s2ut1 { UPDATE footrg SET b = b || ' update2' WHERE a = 1; }
+step s2ut2 { UPDATE footrg SET b = 'EFG' WHERE a = 1; }
+step s2c { COMMIT; }
+
+
+# Session s1 is moving a row into another partition, but is waiting for
+# another session s2 that is updating the original row. The row that ends up
+# in the new partition should contain the changes made by session s2.
+permutation s1b s2b s2u1 s1u s2c s1c s1s
+
+# Same as above, except, session s1 is waiting in GetTupleForTrigger().
+permutation s1b s2b s2ut1 s1ut s2c s1c s1st s1stl
+
+# Below two cases are similar to the above two; except that the session s1
+# fails EvalPlanQual() test, so partition key update does not happen.
+permutation s1b s2b s2u2 s1u s2c s1c s1s
+permutation s1b s2b s2ut2 s1ut s2c s1c s1st s1stl
diff --git a/src/test/isolation/specs/plpgsql-toast.spec b/src/test/isolation/specs/plpgsql-toast.spec
new file mode 100644
index 0000000..bb444fc
--- /dev/null
+++ b/src/test/isolation/specs/plpgsql-toast.spec
@@ -0,0 +1,178 @@
+# Test TOAST behavior in PL/pgSQL procedures with transaction control.
+#
+# We need to ensure that values stored in PL/pgSQL variables are free
+# of external TOAST references, because those could disappear after a
+# transaction is committed (leading to errors "missing chunk number
+# ... for toast value ..."). The tests here do this by running VACUUM
+# in a second session. Advisory locks are used to have the VACUUM
+# kick in at the right time. The different "assign" steps test
+# different code paths for variable assignments in PL/pgSQL.
+
+setup
+{
+ CREATE TABLE test1 (a int, b text);
+ ALTER TABLE test1 ALTER COLUMN b SET STORAGE EXTERNAL;
+ INSERT INTO test1 VALUES (1, repeat('foo', 2000));
+ CREATE TYPE test2 AS (a bigint, b text);
+}
+
+teardown
+{
+ DROP TABLE test1;
+ DROP TYPE test2;
+}
+
+session s1
+
+setup
+{
+ SELECT pg_advisory_unlock_all();
+}
+
+# assign_simple_var()
+step assign1
+{
+do $$
+ declare
+ x text;
+ begin
+ select test1.b into x from test1;
+ delete from test1;
+ commit;
+ perform pg_advisory_lock(1);
+ raise notice 'length(x) = %', length(x);
+ end;
+$$;
+}
+
+# assign_simple_var()
+step assign2
+{
+do $$
+ declare
+ x text;
+ begin
+ x := (select test1.b from test1);
+ delete from test1;
+ commit;
+ perform pg_advisory_lock(1);
+ raise notice 'length(x) = %', length(x);
+ end;
+$$;
+}
+
+# expanded_record_set_field()
+step assign3
+{
+do $$
+ declare
+ r record;
+ begin
+ select * into r from test1;
+ r.b := (select test1.b from test1);
+ delete from test1;
+ commit;
+ perform pg_advisory_lock(1);
+ raise notice 'length(r) = %', length(r::text);
+ end;
+$$;
+}
+
+# expanded_record_set_fields()
+step assign4
+{
+do $$
+ declare
+ r test2;
+ begin
+ select * into r from test1;
+ delete from test1;
+ commit;
+ perform pg_advisory_lock(1);
+ raise notice 'length(r) = %', length(r::text);
+ end;
+$$;
+}
+
+# expanded_record_set_tuple()
+step assign5
+{
+do $$
+ declare
+ r record;
+ begin
+ for r in select test1.b from test1 loop
+ null;
+ end loop;
+ delete from test1;
+ commit;
+ perform pg_advisory_lock(1);
+ raise notice 'length(r) = %', length(r::text);
+ end;
+$$;
+}
+
+# FOR loop must not hold any fetched-but-not-detoasted values across commit
+step assign6
+{
+do $$
+ declare
+ r record;
+ begin
+ insert into test1 values (2, repeat('bar', 3000));
+ insert into test1 values (3, repeat('baz', 4000));
+ for r in select test1.b from test1 loop
+ delete from test1;
+ commit;
+ perform pg_advisory_lock(1);
+ raise notice 'length(r) = %', length(r::text);
+ end loop;
+ end;
+$$;
+}
+
+# Check that the results of a query can be detoasted just after committing
+# (there's no interaction with VACUUM here)
+step "fetch-after-commit"
+{
+do $$
+ declare
+ r record;
+ t text;
+ begin
+ insert into test1 values (2, repeat('bar', 3000));
+ insert into test1 values (3, repeat('baz', 4000));
+ for r in select test1.a from test1 loop
+ commit;
+ select b into t from test1 where a = r.a;
+ raise notice 'length(t) = %', length(t);
+ end loop;
+ end;
+$$;
+}
+
+session s2
+setup
+{
+ SELECT pg_advisory_unlock_all();
+}
+step lock
+{
+ SELECT pg_advisory_lock(1);
+}
+step vacuum
+{
+ VACUUM test1;
+}
+step unlock
+{
+ SELECT pg_advisory_unlock(1);
+}
+
+permutation lock assign1 vacuum unlock
+permutation lock assign2 vacuum unlock
+permutation lock assign3 vacuum unlock
+permutation lock assign4 vacuum unlock
+permutation lock assign5 vacuum unlock
+permutation lock assign6 vacuum unlock
+permutation "fetch-after-commit"
diff --git a/src/test/isolation/specs/predicate-gin.spec b/src/test/isolation/specs/predicate-gin.spec
new file mode 100644
index 0000000..e279eaa
--- /dev/null
+++ b/src/test/isolation/specs/predicate-gin.spec
@@ -0,0 +1,115 @@
+# Test for page level predicate locking in gin index
+#
+# Test to verify serialization failures and to check reduced false positives
+#
+# To verify serialization failures, queries and permutations are written in such
+# a way that an index scan (from one transaction) and an index insert (from
+# another transaction) will try to access the same part (sub-tree) of the index
+# whereas to check reduced false positives, they will try to access different
+# parts (sub-tree) of the index.
+
+
+setup
+{
+ create table gin_tbl(p int4[]);
+ insert into gin_tbl select array[1] from generate_series(1, 8192) g;
+ insert into gin_tbl select array[g] from generate_series(2, 800) g;
+ create index ginidx on gin_tbl using gin(p) with (fastupdate = off);
+ create table other_tbl(v int4);
+}
+
+teardown
+{
+ drop table gin_tbl;
+ drop table other_tbl;
+}
+
+session s1
+setup
+{
+ begin isolation level serializable;
+ set enable_seqscan=off;
+}
+
+step ra1 { select * from gin_tbl where p @> array[1] limit 1; }
+step rb1 { select count(*) from gin_tbl where p @> array[2]; }
+step rc1 { select count(*) from gin_tbl where p @> array[800]; }
+step rd1 { select count(*) from gin_tbl where p @> array[2000]; }
+
+step wo1 { insert into other_tbl values (1); }
+
+step c1 { commit; }
+
+session s2
+setup
+{
+ begin isolation level serializable;
+ set enable_seqscan=off;
+}
+
+step ro2 { select count(*) from other_tbl; }
+
+step wa2 { insert into gin_tbl values (array[1]); }
+step wb2 { insert into gin_tbl values (array[2]); }
+step wc2 { insert into gin_tbl values (array[800]); }
+step wd2 { insert into gin_tbl values (array[2000]); }
+
+step c2 { commit; }
+
+session s3
+step fu { alter index ginidx set (fastupdate = on); }
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access the same part of the index. So, there is a
+# r-w conflict.
+
+permutation ra1 ro2 wo1 c1 wa2 c2
+permutation ro2 ra1 wo1 c1 wa2 c2
+permutation ro2 ra1 wo1 wa2 c1 c2
+permutation ra1 ro2 wa2 wo1 c1 c2
+
+permutation rb1 ro2 wo1 c1 wb2 c2
+permutation ro2 rb1 wo1 c1 wb2 c2
+permutation ro2 rb1 wo1 wb2 c1 c2
+permutation rb1 ro2 wb2 wo1 c1 c2
+
+permutation rc1 ro2 wo1 c1 wc2 c2
+permutation ro2 rc1 wo1 c1 wc2 c2
+permutation ro2 rc1 wo1 wc2 c1 c2
+permutation rc1 ro2 wc2 wo1 c1 c2
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access different parts of the index. So, there is no
+# r-w conflict.
+
+permutation ra1 ro2 wo1 c1 wb2 c2
+permutation ro2 ra1 wo1 c1 wc2 c2
+permutation ro2 rb1 wo1 wa2 c1 c2
+permutation rc1 ro2 wa2 wo1 c1 c2
+
+permutation rb1 ro2 wo1 c1 wa2 c2
+permutation ro2 rb1 wo1 c1 wc2 c2
+permutation ro2 ra1 wo1 wb2 c1 c2
+permutation rc1 ro2 wb2 wo1 c1 c2
+
+permutation rc1 ro2 wo1 c1 wa2 c2
+permutation ro2 rc1 wo1 c1 wb2 c2
+permutation ro2 ra1 wo1 wc2 c1 c2
+permutation rb1 ro2 wc2 wo1 c1 c2
+
+# With fastupdate = on all index is under predicate lock. So we can't
+# distinguish particular keys.
+
+permutation fu ra1 ro2 wo1 c1 wa2 c2
+permutation fu ra1 ro2 wo1 c1 wb2 c2
+
+# Check fastupdate turned on concurrently.
+
+permutation ra1 ro2 wo1 c1 fu wa2 c2
+
+# Tests for conflicts with previously non-existing key
+
+permutation rd1 ro2 wo1 c1 wd2 c2
+permutation ro2 rd1 wo1 c1 wd2 c2
+permutation ro2 rd1 wo1 wd2 c1 c2
+permutation rd1 ro2 wd2 wo1 c1 c2
diff --git a/src/test/isolation/specs/predicate-gist.spec b/src/test/isolation/specs/predicate-gist.spec
new file mode 100644
index 0000000..9016c6e
--- /dev/null
+++ b/src/test/isolation/specs/predicate-gist.spec
@@ -0,0 +1,117 @@
+# Test for page level predicate locking in gist
+#
+# Test to verify serialization failures and to check reduced false positives
+#
+# To verify serialization failures, queries and permutations are written in such
+# a way that an index scan (from one transaction) and an index insert (from
+# another transaction) will try to access the same part (sub-tree) of the index
+# whereas to check reduced false positives, they will try to access different
+# parts (sub-tree) of the index.
+
+setup
+{
+ create table gist_point_tbl(id int4, p point);
+ create index gist_pointidx on gist_point_tbl using gist(p);
+ insert into gist_point_tbl (id, p)
+ select g, point(g*10, g*10) from generate_series(1, 1000) g;
+}
+
+teardown
+{
+ drop table gist_point_tbl;
+}
+
+session s1
+setup
+{
+ begin isolation level serializable;
+ set enable_seqscan=off;
+ set enable_bitmapscan=off;
+ set enable_indexonlyscan=on;
+}
+
+step rxy1 { select sum(p[0]) from gist_point_tbl where p << point(2500, 2500); }
+step wx1 { insert into gist_point_tbl (id, p)
+ select g, point(g*500, g*500) from generate_series(15, 20) g; }
+step rxy3 { select sum(p[0]) from gist_point_tbl where p >> point(6000,6000); }
+step wx3 { insert into gist_point_tbl (id, p)
+ select g, point(g*500, g*500) from generate_series(12, 18) g; }
+step c1 { commit; }
+
+
+session s2
+setup
+{
+ begin isolation level serializable;
+ set enable_seqscan=off;
+ set enable_bitmapscan=off;
+ set enable_indexonlyscan=on;
+}
+
+step rxy2 { select sum(p[0]) from gist_point_tbl where p >> point(7500,7500); }
+step wy2 { insert into gist_point_tbl (id, p)
+ select g, point(g*500, g*500) from generate_series(1, 5) g; }
+step rxy4 { select sum(p[0]) from gist_point_tbl where p << point(1000,1000); }
+step wy4 { insert into gist_point_tbl (id, p)
+ select g, point(g*50, g*50) from generate_series(1, 20) g; }
+step c2 { commit; }
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access the same part of the index but one transaction
+# commits before other transaction begins so no r-w conflict.
+
+permutation rxy1 wx1 c1 rxy2 wy2 c2
+permutation rxy2 wy2 c2 rxy1 wx1 c1
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access different parts of the index and also one
+# transaction commits before other transaction begins, so no r-w conflict.
+
+permutation rxy3 wx3 c1 rxy4 wy4 c2
+permutation rxy4 wy4 c2 rxy3 wx3 c1
+
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access the same part of the index and one transaction
+# begins before other transaction commits so there is a r-w conflict.
+
+permutation rxy1 wx1 rxy2 c1 wy2 c2
+permutation rxy1 wx1 rxy2 wy2 c1 c2
+permutation rxy1 wx1 rxy2 wy2 c2 c1
+permutation rxy1 rxy2 wx1 c1 wy2 c2
+permutation rxy1 rxy2 wx1 wy2 c1 c2
+permutation rxy1 rxy2 wx1 wy2 c2 c1
+permutation rxy1 rxy2 wy2 wx1 c1 c2
+permutation rxy1 rxy2 wy2 wx1 c2 c1
+permutation rxy1 rxy2 wy2 c2 wx1 c1
+permutation rxy2 rxy1 wx1 c1 wy2 c2
+permutation rxy2 rxy1 wx1 wy2 c1 c2
+permutation rxy2 rxy1 wx1 wy2 c2 c1
+permutation rxy2 rxy1 wy2 wx1 c1 c2
+permutation rxy2 rxy1 wy2 wx1 c2 c1
+permutation rxy2 rxy1 wy2 c2 wx1 c1
+permutation rxy2 wy2 rxy1 wx1 c1 c2
+permutation rxy2 wy2 rxy1 wx1 c2 c1
+permutation rxy2 wy2 rxy1 c2 wx1 c1
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access different parts of the index so no r-w conflict.
+
+permutation rxy3 wx3 rxy4 c1 wy4 c2
+permutation rxy3 wx3 rxy4 wy4 c1 c2
+permutation rxy3 wx3 rxy4 wy4 c2 c1
+permutation rxy3 rxy4 wx3 c1 wy4 c2
+permutation rxy3 rxy4 wx3 wy4 c1 c2
+permutation rxy3 rxy4 wx3 wy4 c2 c1
+permutation rxy3 rxy4 wy4 wx3 c1 c2
+permutation rxy3 rxy4 wy4 wx3 c2 c1
+permutation rxy3 rxy4 wy4 c2 wx3 c1
+permutation rxy4 rxy3 wx3 c1 wy4 c2
+permutation rxy4 rxy3 wx3 wy4 c1 c2
+permutation rxy4 rxy3 wx3 wy4 c2 c1
+permutation rxy4 rxy3 wy4 wx3 c1 c2
+permutation rxy4 rxy3 wy4 wx3 c2 c1
+permutation rxy4 rxy3 wy4 c2 wx3 c1
+permutation rxy4 wy4 rxy3 wx3 c1 c2
+permutation rxy4 wy4 rxy3 wx3 c2 c1
+permutation rxy4 wy4 rxy3 c2 wx3 c1
diff --git a/src/test/isolation/specs/predicate-hash.spec b/src/test/isolation/specs/predicate-hash.spec
new file mode 100644
index 0000000..7ca193b
--- /dev/null
+++ b/src/test/isolation/specs/predicate-hash.spec
@@ -0,0 +1,122 @@
+# Test for page level predicate locking in hash index
+#
+# Test to verify serialization failures and to check reduced false positives
+#
+# To verify serialization failures, queries and permutations are written in such
+# a way that an index scan (from one transaction) and an index insert (from
+# another transaction) will try to access the same bucket of the index
+# whereas to check reduced false positives, they will try to access different
+# buckets of the index.
+
+setup
+{
+ create table hash_tbl(id int4, p integer);
+ create index hash_idx on hash_tbl using hash(p);
+ insert into hash_tbl (id, p)
+ select g, 10 from generate_series(1, 10) g;
+ insert into hash_tbl (id, p)
+ select g, 20 from generate_series(11, 20) g;
+ insert into hash_tbl (id, p)
+ select g, 30 from generate_series(21, 30) g;
+ insert into hash_tbl (id, p)
+ select g, 40 from generate_series(31, 40) g;
+}
+
+teardown
+{
+ drop table hash_tbl;
+}
+
+session s1
+setup
+{
+ begin isolation level serializable;
+ set enable_seqscan=off;
+ set enable_bitmapscan=off;
+ set enable_indexonlyscan=on;
+}
+step rxy1 { select sum(p) from hash_tbl where p=20; }
+step wx1 { insert into hash_tbl (id, p)
+ select g, 30 from generate_series(41, 50) g; }
+step rxy3 { select sum(p) from hash_tbl where p=20; }
+step wx3 { insert into hash_tbl (id, p)
+ select g, 50 from generate_series(41, 50) g; }
+step c1 { commit; }
+
+
+session s2
+setup
+{
+ begin isolation level serializable;
+ set enable_seqscan=off;
+ set enable_bitmapscan=off;
+ set enable_indexonlyscan=on;
+}
+step rxy2 { select sum(p) from hash_tbl where p=30; }
+step wy2 { insert into hash_tbl (id, p)
+ select g, 20 from generate_series(51, 60) g; }
+step rxy4 { select sum(p) from hash_tbl where p=30; }
+step wy4 { insert into hash_tbl (id, p)
+ select g, 60 from generate_series(51, 60) g; }
+step c2 { commit; }
+
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access the same bucket of the index but one transaction
+# commits before other transaction begins so no r-w conflict.
+
+permutation rxy1 wx1 c1 rxy2 wy2 c2
+permutation rxy2 wy2 c2 rxy1 wx1 c1
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access different buckets of the index and also one
+# transaction commits before other transaction begins, so no r-w conflict.
+
+permutation rxy3 wx3 c1 rxy4 wy4 c2
+permutation rxy4 wy4 c2 rxy3 wx3 c1
+
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access the same bucket of the index and one transaction
+# begins before other transaction commits so there is a r-w conflict.
+
+permutation rxy1 wx1 rxy2 c1 wy2 c2
+permutation rxy1 wx1 rxy2 wy2 c1 c2
+permutation rxy1 wx1 rxy2 wy2 c2 c1
+permutation rxy1 rxy2 wx1 c1 wy2 c2
+permutation rxy1 rxy2 wx1 wy2 c1 c2
+permutation rxy1 rxy2 wx1 wy2 c2 c1
+permutation rxy1 rxy2 wy2 wx1 c1 c2
+permutation rxy1 rxy2 wy2 wx1 c2 c1
+permutation rxy1 rxy2 wy2 c2 wx1 c1
+permutation rxy2 rxy1 wx1 c1 wy2 c2
+permutation rxy2 rxy1 wx1 wy2 c1 c2
+permutation rxy2 rxy1 wx1 wy2 c2 c1
+permutation rxy2 rxy1 wy2 wx1 c1 c2
+permutation rxy2 rxy1 wy2 wx1 c2 c1
+permutation rxy2 rxy1 wy2 c2 wx1 c1
+permutation rxy2 wy2 rxy1 wx1 c1 c2
+permutation rxy2 wy2 rxy1 wx1 c2 c1
+permutation rxy2 wy2 rxy1 c2 wx1 c1
+
+# An index scan (from one transaction) and an index insert (from another
+# transaction) try to access different buckets of the index so no r-w conflict.
+
+permutation rxy3 wx3 rxy4 c1 wy4 c2
+permutation rxy3 wx3 rxy4 wy4 c1 c2
+permutation rxy3 wx3 rxy4 wy4 c2 c1
+permutation rxy3 rxy4 wx3 c1 wy4 c2
+permutation rxy3 rxy4 wx3 wy4 c1 c2
+permutation rxy3 rxy4 wx3 wy4 c2 c1
+permutation rxy3 rxy4 wy4 wx3 c1 c2
+permutation rxy3 rxy4 wy4 wx3 c2 c1
+permutation rxy3 rxy4 wy4 c2 wx3 c1
+permutation rxy4 rxy3 wx3 c1 wy4 c2
+permutation rxy4 rxy3 wx3 wy4 c1 c2
+permutation rxy4 rxy3 wx3 wy4 c2 c1
+permutation rxy4 rxy3 wy4 wx3 c1 c2
+permutation rxy4 rxy3 wy4 wx3 c2 c1
+permutation rxy4 rxy3 wy4 c2 wx3 c1
+permutation rxy4 wy4 rxy3 wx3 c1 c2
+permutation rxy4 wy4 rxy3 wx3 c2 c1
+permutation rxy4 wy4 rxy3 c2 wx3 c1
diff --git a/src/test/isolation/specs/predicate-lock-hot-tuple.spec b/src/test/isolation/specs/predicate-lock-hot-tuple.spec
new file mode 100644
index 0000000..5b8aecc
--- /dev/null
+++ b/src/test/isolation/specs/predicate-lock-hot-tuple.spec
@@ -0,0 +1,37 @@
+# Test predicate locks on HOT updated tuples.
+#
+# This test has two serializable transactions. Both select two rows
+# from the table, and then update one of them.
+# If these were serialized (run one at a time), the transaction that
+# runs later would see one of the rows to be updated.
+#
+# Any overlap between the transactions must cause a serialization failure.
+# We used to have a bug in predicate locking HOT updated tuples, which
+# caused the conflict to be missed, if the row was HOT updated.
+
+setup
+{
+ CREATE TABLE test (i int PRIMARY KEY, t text);
+ INSERT INTO test VALUES (5, 'apple'), (7, 'pear'), (11, 'banana');
+ -- HOT-update 'pear' row.
+ UPDATE test SET t = 'pear_hot_updated' WHERE i = 7;
+}
+
+teardown
+{
+ DROP TABLE test;
+}
+
+session s1
+step b1 { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r1 { SELECT * FROM test WHERE i IN (5, 7) }
+step w1 { UPDATE test SET t = 'pear_xact1' WHERE i = 7 }
+step c1 { COMMIT; }
+
+session s2
+step b2 { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r2 { SELECT * FROM test WHERE i IN (5, 7) }
+step w2 { UPDATE test SET t = 'apple_xact2' WHERE i = 5 }
+step c2 { COMMIT; }
+
+permutation b1 b2 r1 r2 w1 w2 c1 c2
diff --git a/src/test/isolation/specs/prepared-transactions-cic.spec b/src/test/isolation/specs/prepared-transactions-cic.spec
new file mode 100644
index 0000000..626b1b6
--- /dev/null
+++ b/src/test/isolation/specs/prepared-transactions-cic.spec
@@ -0,0 +1,37 @@
+# This test verifies that CREATE INDEX CONCURRENTLY interacts with prepared
+# transactions correctly.
+setup
+{
+ CREATE TABLE cic_test (a int);
+}
+
+teardown
+{
+ DROP TABLE cic_test;
+}
+
+
+# Sessions for CREATE INDEX CONCURRENTLY test
+session s1
+step w1 { BEGIN; INSERT INTO cic_test VALUES (1); }
+step p1 { PREPARE TRANSACTION 's1'; }
+step c1 { COMMIT PREPARED 's1'; }
+
+session s2
+# The isolation tester never recognizes that a lock of s1 blocks s2, because a
+# prepared transaction's locks have no pid associated. While there's a slight
+# chance of timeout while waiting for an autovacuum-held lock, that wouldn't
+# change the output. Hence, no timeout is too short.
+setup { SET lock_timeout = 10; }
+step cic2
+{
+ CREATE INDEX CONCURRENTLY on cic_test(a);
+}
+step r2
+{
+ SET enable_seqscan to off;
+ SET enable_bitmapscan to off;
+ SELECT * FROM cic_test WHERE a = 1;
+}
+
+permutation w1 p1 cic2 c1 r2
diff --git a/src/test/isolation/specs/prepared-transactions.spec b/src/test/isolation/specs/prepared-transactions.spec
new file mode 100644
index 0000000..78b9d2c
--- /dev/null
+++ b/src/test/isolation/specs/prepared-transactions.spec
@@ -0,0 +1,1507 @@
+# This test verifies that if there's a series of rw-conflicts
+# s1 ---> s2 ---> s3, with s3 committing first
+# at least one transaction will be aborted, regardless of the order in
+# which the conflicts are detected and transactions prepare and
+# commit.
+#
+#
+# Tables test2 and test3 are used to create the
+# s1 --> s2 and s2 --> s3 rw-dependencies respectively
+#
+# test1 isn't involved in the anomaly; s1 only inserts a row into it
+# so that there's an easy way to tell (by looking for that row) if s1
+# successfully committed.
+#
+# force_snapshot is used to force s2 and s3 to take their snapshot
+# immediately after BEGIN, so we can be sure the three transactions
+# overlap.
+setup
+{
+ CREATE TABLE test1 (a int);
+ CREATE TABLE test2 (b int);
+ CREATE TABLE test3 (c int);
+ CREATE TABLE force_snapshot (a int);
+}
+
+teardown
+{
+ DROP TABLE test1;
+ DROP TABLE test2;
+ DROP TABLE test3;
+ DROP TABLE force_snapshot;
+}
+
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; INSERT INTO test1 VALUES (1); }
+step r1 { SELECT * FROM test2; }
+step p1 { PREPARE TRANSACTION 's1'; }
+step c1 { COMMIT PREPARED 's1'; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; SELECT * FROM force_snapshot; }
+step r2 { SELECT * FROM test3; }
+step w2 { INSERT INTO test2 VALUES (2); }
+step p2 { PREPARE TRANSACTION 's2'; }
+step c2 { COMMIT PREPARED 's2'; }
+
+session s3
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; SELECT * FROM force_snapshot; }
+step w3 { INSERT INTO test3 VALUES (3); }
+step p3 { PREPARE TRANSACTION 's3'; }
+step c3 { COMMIT PREPARED 's3'; }
+
+# When run at the end of the permutations below, this SELECT statement
+# should never return any tuples, because at least one of the three
+# transactions involved should be aborted.
+session s4
+step check { SELECT * FROM test1,test2,test3; }
+
+# We run on all permutations of the statements above subject to the
+# following constraints:
+# - each transaction's reads/writes must happen before it prepares
+# - each transaction must prepare before committing
+# - s3 must be the first of the three transactions to commit
+# ...which means that each permutation should fail.
+#
+# To bring the number of permutations down a bit, we further require
+# them to satisfy *one* of the following:
+# - r1 < w2 < r2 < w3 (T1-->T2 conflict on write, T2-->T3 on write)
+# - r1 < w2 < w3 < r2 (T1-->T2 conflict on read, T2-->T3 on write)
+# - w2 < r1 < r2 < w3 (T1-->T2 conflict on write, T2-->T3 on read)
+# - w2 < r1 < w3 < r2 (T1-->T2 conflict on read, T2-->T3 on read)
+# This eliminates some redundant combinations. For example, it doesn't
+# matter if w2 happens before w3 as long as both come before the
+# conflicting reads.
+permutation r1 r2 w2 w3 p1 p2 p3 c3 c1 c2 check
+permutation r1 r2 w2 w3 p1 p2 p3 c3 c2 c1 check
+permutation r1 r2 w2 w3 p1 p3 p2 c3 c1 c2 check
+permutation r1 r2 w2 w3 p1 p3 p2 c3 c2 c1 check
+permutation r1 r2 w2 w3 p1 p3 c3 p2 c1 c2 check
+permutation r1 r2 w2 w3 p1 p3 c3 p2 c2 c1 check
+permutation r1 r2 w2 w3 p1 p3 c3 c1 p2 c2 check
+permutation r1 r2 w2 w3 p2 p1 p3 c3 c1 c2 check
+permutation r1 r2 w2 w3 p2 p1 p3 c3 c2 c1 check
+permutation r1 r2 w2 w3 p2 p3 p1 c3 c1 c2 check
+permutation r1 r2 w2 w3 p2 p3 p1 c3 c2 c1 check
+permutation r1 r2 w2 w3 p2 p3 c3 p1 c1 c2 check
+permutation r1 r2 w2 w3 p2 p3 c3 p1 c2 c1 check
+permutation r1 r2 w2 w3 p2 p3 c3 c2 p1 c1 check
+permutation r1 r2 w2 w3 p3 p1 p2 c3 c1 c2 check
+permutation r1 r2 w2 w3 p3 p1 p2 c3 c2 c1 check
+permutation r1 r2 w2 w3 p3 p1 c3 p2 c1 c2 check
+permutation r1 r2 w2 w3 p3 p1 c3 p2 c2 c1 check
+permutation r1 r2 w2 w3 p3 p1 c3 c1 p2 c2 check
+permutation r1 r2 w2 w3 p3 p2 p1 c3 c1 c2 check
+permutation r1 r2 w2 w3 p3 p2 p1 c3 c2 c1 check
+permutation r1 r2 w2 w3 p3 p2 c3 p1 c1 c2 check
+permutation r1 r2 w2 w3 p3 p2 c3 p1 c2 c1 check
+permutation r1 r2 w2 w3 p3 p2 c3 c2 p1 c1 check
+permutation r1 r2 w2 w3 p3 c3 p1 p2 c1 c2 check
+permutation r1 r2 w2 w3 p3 c3 p1 p2 c2 c1 check
+permutation r1 r2 w2 w3 p3 c3 p1 c1 p2 c2 check
+permutation r1 r2 w2 w3 p3 c3 p2 p1 c1 c2 check
+permutation r1 r2 w2 w3 p3 c3 p2 p1 c2 c1 check
+permutation r1 r2 w2 w3 p3 c3 p2 c2 p1 c1 check
+permutation r1 r2 w2 p1 w3 p2 p3 c3 c1 c2 check
+permutation r1 r2 w2 p1 w3 p2 p3 c3 c2 c1 check
+permutation r1 r2 w2 p1 w3 p3 p2 c3 c1 c2 check
+permutation r1 r2 w2 p1 w3 p3 p2 c3 c2 c1 check
+permutation r1 r2 w2 p1 w3 p3 c3 p2 c1 c2 check
+permutation r1 r2 w2 p1 w3 p3 c3 p2 c2 c1 check
+permutation r1 r2 w2 p1 w3 p3 c3 c1 p2 c2 check
+permutation r1 r2 w2 p1 p2 w3 p3 c3 c1 c2 check
+permutation r1 r2 w2 p1 p2 w3 p3 c3 c2 c1 check
+permutation r1 r2 w2 p2 w3 p1 p3 c3 c1 c2 check
+permutation r1 r2 w2 p2 w3 p1 p3 c3 c2 c1 check
+permutation r1 r2 w2 p2 w3 p3 p1 c3 c1 c2 check
+permutation r1 r2 w2 p2 w3 p3 p1 c3 c2 c1 check
+permutation r1 r2 w2 p2 w3 p3 c3 p1 c1 c2 check
+permutation r1 r2 w2 p2 w3 p3 c3 p1 c2 c1 check
+permutation r1 r2 w2 p2 w3 p3 c3 c2 p1 c1 check
+permutation r1 r2 w2 p2 p1 w3 p3 c3 c1 c2 check
+permutation r1 r2 w2 p2 p1 w3 p3 c3 c2 c1 check
+permutation r1 r2 p1 w2 w3 p2 p3 c3 c1 c2 check
+permutation r1 r2 p1 w2 w3 p2 p3 c3 c2 c1 check
+permutation r1 r2 p1 w2 w3 p3 p2 c3 c1 c2 check
+permutation r1 r2 p1 w2 w3 p3 p2 c3 c2 c1 check
+permutation r1 r2 p1 w2 w3 p3 c3 p2 c1 c2 check
+permutation r1 r2 p1 w2 w3 p3 c3 p2 c2 c1 check
+permutation r1 r2 p1 w2 w3 p3 c3 c1 p2 c2 check
+permutation r1 r2 p1 w2 p2 w3 p3 c3 c1 c2 check
+permutation r1 r2 p1 w2 p2 w3 p3 c3 c2 c1 check
+permutation r1 w2 w3 r2 p1 p2 p3 c3 c1 c2 check
+permutation r1 w2 w3 r2 p1 p2 p3 c3 c2 c1 check
+permutation r1 w2 w3 r2 p1 p3 p2 c3 c1 c2 check
+permutation r1 w2 w3 r2 p1 p3 p2 c3 c2 c1 check
+permutation r1 w2 w3 r2 p1 p3 c3 p2 c1 c2 check
+permutation r1 w2 w3 r2 p1 p3 c3 p2 c2 c1 check
+permutation r1 w2 w3 r2 p1 p3 c3 c1 p2 c2 check
+permutation r1 w2 w3 r2 p2 p1 p3 c3 c1 c2 check
+permutation r1 w2 w3 r2 p2 p1 p3 c3 c2 c1 check
+permutation r1 w2 w3 r2 p2 p3 p1 c3 c1 c2 check
+permutation r1 w2 w3 r2 p2 p3 p1 c3 c2 c1 check
+permutation r1 w2 w3 r2 p2 p3 c3 p1 c1 c2 check
+permutation r1 w2 w3 r2 p2 p3 c3 p1 c2 c1 check
+permutation r1 w2 w3 r2 p2 p3 c3 c2 p1 c1 check
+permutation r1 w2 w3 r2 p3 p1 p2 c3 c1 c2 check
+permutation r1 w2 w3 r2 p3 p1 p2 c3 c2 c1 check
+permutation r1 w2 w3 r2 p3 p1 c3 p2 c1 c2 check
+permutation r1 w2 w3 r2 p3 p1 c3 p2 c2 c1 check
+permutation r1 w2 w3 r2 p3 p1 c3 c1 p2 c2 check
+permutation r1 w2 w3 r2 p3 p2 p1 c3 c1 c2 check
+permutation r1 w2 w3 r2 p3 p2 p1 c3 c2 c1 check
+permutation r1 w2 w3 r2 p3 p2 c3 p1 c1 c2 check
+permutation r1 w2 w3 r2 p3 p2 c3 p1 c2 c1 check
+permutation r1 w2 w3 r2 p3 p2 c3 c2 p1 c1 check
+permutation r1 w2 w3 r2 p3 c3 p1 p2 c1 c2 check
+permutation r1 w2 w3 r2 p3 c3 p1 p2 c2 c1 check
+permutation r1 w2 w3 r2 p3 c3 p1 c1 p2 c2 check
+permutation r1 w2 w3 r2 p3 c3 p2 p1 c1 c2 check
+permutation r1 w2 w3 r2 p3 c3 p2 p1 c2 c1 check
+permutation r1 w2 w3 r2 p3 c3 p2 c2 p1 c1 check
+permutation r1 w2 w3 p1 r2 p2 p3 c3 c1 c2 check
+permutation r1 w2 w3 p1 r2 p2 p3 c3 c2 c1 check
+permutation r1 w2 w3 p1 r2 p3 p2 c3 c1 c2 check
+permutation r1 w2 w3 p1 r2 p3 p2 c3 c2 c1 check
+permutation r1 w2 w3 p1 r2 p3 c3 p2 c1 c2 check
+permutation r1 w2 w3 p1 r2 p3 c3 p2 c2 c1 check
+permutation r1 w2 w3 p1 r2 p3 c3 c1 p2 c2 check
+permutation r1 w2 w3 p1 p3 r2 p2 c3 c1 c2 check
+permutation r1 w2 w3 p1 p3 r2 p2 c3 c2 c1 check
+permutation r1 w2 w3 p1 p3 r2 c3 p2 c1 c2 check
+permutation r1 w2 w3 p1 p3 r2 c3 p2 c2 c1 check
+permutation r1 w2 w3 p1 p3 r2 c3 c1 p2 c2 check
+permutation r1 w2 w3 p1 p3 c3 r2 p2 c1 c2 check
+permutation r1 w2 w3 p1 p3 c3 r2 p2 c2 c1 check
+permutation r1 w2 w3 p1 p3 c3 r2 c1 p2 c2 check
+permutation r1 w2 w3 p1 p3 c3 c1 r2 p2 c2 check
+permutation r1 w2 w3 p3 r2 p1 p2 c3 c1 c2 check
+permutation r1 w2 w3 p3 r2 p1 p2 c3 c2 c1 check
+permutation r1 w2 w3 p3 r2 p1 c3 p2 c1 c2 check
+permutation r1 w2 w3 p3 r2 p1 c3 p2 c2 c1 check
+permutation r1 w2 w3 p3 r2 p1 c3 c1 p2 c2 check
+permutation r1 w2 w3 p3 r2 p2 p1 c3 c1 c2 check
+permutation r1 w2 w3 p3 r2 p2 p1 c3 c2 c1 check
+permutation r1 w2 w3 p3 r2 p2 c3 p1 c1 c2 check
+permutation r1 w2 w3 p3 r2 p2 c3 p1 c2 c1 check
+permutation r1 w2 w3 p3 r2 p2 c3 c2 p1 c1 check
+permutation r1 w2 w3 p3 r2 c3 p1 p2 c1 c2 check
+permutation r1 w2 w3 p3 r2 c3 p1 p2 c2 c1 check
+permutation r1 w2 w3 p3 r2 c3 p1 c1 p2 c2 check
+permutation r1 w2 w3 p3 r2 c3 p2 p1 c1 c2 check
+permutation r1 w2 w3 p3 r2 c3 p2 p1 c2 c1 check
+permutation r1 w2 w3 p3 r2 c3 p2 c2 p1 c1 check
+permutation r1 w2 w3 p3 p1 r2 p2 c3 c1 c2 check
+permutation r1 w2 w3 p3 p1 r2 p2 c3 c2 c1 check
+permutation r1 w2 w3 p3 p1 r2 c3 p2 c1 c2 check
+permutation r1 w2 w3 p3 p1 r2 c3 p2 c2 c1 check
+permutation r1 w2 w3 p3 p1 r2 c3 c1 p2 c2 check
+permutation r1 w2 w3 p3 p1 c3 r2 p2 c1 c2 check
+permutation r1 w2 w3 p3 p1 c3 r2 p2 c2 c1 check
+permutation r1 w2 w3 p3 p1 c3 r2 c1 p2 c2 check
+permutation r1 w2 w3 p3 p1 c3 c1 r2 p2 c2 check
+permutation r1 w2 w3 p3 c3 r2 p1 p2 c1 c2 check
+permutation r1 w2 w3 p3 c3 r2 p1 p2 c2 c1 check
+permutation r1 w2 w3 p3 c3 r2 p1 c1 p2 c2 check
+permutation r1 w2 w3 p3 c3 r2 p2 p1 c1 c2 check
+permutation r1 w2 w3 p3 c3 r2 p2 p1 c2 c1 check
+permutation r1 w2 w3 p3 c3 r2 p2 c2 p1 c1 check
+permutation r1 w2 w3 p3 c3 p1 r2 p2 c1 c2 check
+permutation r1 w2 w3 p3 c3 p1 r2 p2 c2 c1 check
+permutation r1 w2 w3 p3 c3 p1 r2 c1 p2 c2 check
+permutation r1 w2 w3 p3 c3 p1 c1 r2 p2 c2 check
+permutation r1 w2 p1 w3 r2 p2 p3 c3 c1 c2 check
+permutation r1 w2 p1 w3 r2 p2 p3 c3 c2 c1 check
+permutation r1 w2 p1 w3 r2 p3 p2 c3 c1 c2 check
+permutation r1 w2 p1 w3 r2 p3 p2 c3 c2 c1 check
+permutation r1 w2 p1 w3 r2 p3 c3 p2 c1 c2 check
+permutation r1 w2 p1 w3 r2 p3 c3 p2 c2 c1 check
+permutation r1 w2 p1 w3 r2 p3 c3 c1 p2 c2 check
+permutation r1 w2 p1 w3 p3 r2 p2 c3 c1 c2 check
+permutation r1 w2 p1 w3 p3 r2 p2 c3 c2 c1 check
+permutation r1 w2 p1 w3 p3 r2 c3 p2 c1 c2 check
+permutation r1 w2 p1 w3 p3 r2 c3 p2 c2 c1 check
+permutation r1 w2 p1 w3 p3 r2 c3 c1 p2 c2 check
+permutation r1 w2 p1 w3 p3 c3 r2 p2 c1 c2 check
+permutation r1 w2 p1 w3 p3 c3 r2 p2 c2 c1 check
+permutation r1 w2 p1 w3 p3 c3 r2 c1 p2 c2 check
+permutation r1 w2 p1 w3 p3 c3 c1 r2 p2 c2 check
+permutation r1 w3 r2 w2 p1 p2 p3 c3 c1 c2 check
+permutation r1 w3 r2 w2 p1 p2 p3 c3 c2 c1 check
+permutation r1 w3 r2 w2 p1 p3 p2 c3 c1 c2 check
+permutation r1 w3 r2 w2 p1 p3 p2 c3 c2 c1 check
+permutation r1 w3 r2 w2 p1 p3 c3 p2 c1 c2 check
+permutation r1 w3 r2 w2 p1 p3 c3 p2 c2 c1 check
+permutation r1 w3 r2 w2 p1 p3 c3 c1 p2 c2 check
+permutation r1 w3 r2 w2 p2 p1 p3 c3 c1 c2 check
+permutation r1 w3 r2 w2 p2 p1 p3 c3 c2 c1 check
+permutation r1 w3 r2 w2 p2 p3 p1 c3 c1 c2 check
+permutation r1 w3 r2 w2 p2 p3 p1 c3 c2 c1 check
+permutation r1 w3 r2 w2 p2 p3 c3 p1 c1 c2 check
+permutation r1 w3 r2 w2 p2 p3 c3 p1 c2 c1 check
+permutation r1 w3 r2 w2 p2 p3 c3 c2 p1 c1 check
+permutation r1 w3 r2 w2 p3 p1 p2 c3 c1 c2 check
+permutation r1 w3 r2 w2 p3 p1 p2 c3 c2 c1 check
+permutation r1 w3 r2 w2 p3 p1 c3 p2 c1 c2 check
+permutation r1 w3 r2 w2 p3 p1 c3 p2 c2 c1 check
+permutation r1 w3 r2 w2 p3 p1 c3 c1 p2 c2 check
+permutation r1 w3 r2 w2 p3 p2 p1 c3 c1 c2 check
+permutation r1 w3 r2 w2 p3 p2 p1 c3 c2 c1 check
+permutation r1 w3 r2 w2 p3 p2 c3 p1 c1 c2 check
+permutation r1 w3 r2 w2 p3 p2 c3 p1 c2 c1 check
+permutation r1 w3 r2 w2 p3 p2 c3 c2 p1 c1 check
+permutation r1 w3 r2 w2 p3 c3 p1 p2 c1 c2 check
+permutation r1 w3 r2 w2 p3 c3 p1 p2 c2 c1 check
+permutation r1 w3 r2 w2 p3 c3 p1 c1 p2 c2 check
+permutation r1 w3 r2 w2 p3 c3 p2 p1 c1 c2 check
+permutation r1 w3 r2 w2 p3 c3 p2 p1 c2 c1 check
+permutation r1 w3 r2 w2 p3 c3 p2 c2 p1 c1 check
+permutation r1 w3 r2 p1 w2 p2 p3 c3 c1 c2 check
+permutation r1 w3 r2 p1 w2 p2 p3 c3 c2 c1 check
+permutation r1 w3 r2 p1 w2 p3 p2 c3 c1 c2 check
+permutation r1 w3 r2 p1 w2 p3 p2 c3 c2 c1 check
+permutation r1 w3 r2 p1 w2 p3 c3 p2 c1 c2 check
+permutation r1 w3 r2 p1 w2 p3 c3 p2 c2 c1 check
+permutation r1 w3 r2 p1 w2 p3 c3 c1 p2 c2 check
+permutation r1 w3 r2 p1 p3 w2 p2 c3 c1 c2 check
+permutation r1 w3 r2 p1 p3 w2 p2 c3 c2 c1 check
+permutation r1 w3 r2 p1 p3 w2 c3 p2 c1 c2 check
+permutation r1 w3 r2 p1 p3 w2 c3 p2 c2 c1 check
+permutation r1 w3 r2 p1 p3 w2 c3 c1 p2 c2 check
+permutation r1 w3 r2 p1 p3 c3 w2 p2 c1 c2 check
+permutation r1 w3 r2 p1 p3 c3 w2 p2 c2 c1 check
+permutation r1 w3 r2 p1 p3 c3 w2 c1 p2 c2 check
+permutation r1 w3 r2 p1 p3 c3 c1 w2 p2 c2 check
+permutation r1 w3 r2 p3 w2 p1 p2 c3 c1 c2 check
+permutation r1 w3 r2 p3 w2 p1 p2 c3 c2 c1 check
+permutation r1 w3 r2 p3 w2 p1 c3 p2 c1 c2 check
+permutation r1 w3 r2 p3 w2 p1 c3 p2 c2 c1 check
+permutation r1 w3 r2 p3 w2 p1 c3 c1 p2 c2 check
+permutation r1 w3 r2 p3 w2 p2 p1 c3 c1 c2 check
+permutation r1 w3 r2 p3 w2 p2 p1 c3 c2 c1 check
+permutation r1 w3 r2 p3 w2 p2 c3 p1 c1 c2 check
+permutation r1 w3 r2 p3 w2 p2 c3 p1 c2 c1 check
+permutation r1 w3 r2 p3 w2 p2 c3 c2 p1 c1 check
+permutation r1 w3 r2 p3 w2 c3 p1 p2 c1 c2 check
+permutation r1 w3 r2 p3 w2 c3 p1 p2 c2 c1 check
+permutation r1 w3 r2 p3 w2 c3 p1 c1 p2 c2 check
+permutation r1 w3 r2 p3 w2 c3 p2 p1 c1 c2 check
+permutation r1 w3 r2 p3 w2 c3 p2 p1 c2 c1 check
+permutation r1 w3 r2 p3 w2 c3 p2 c2 p1 c1 check
+permutation r1 w3 r2 p3 p1 w2 p2 c3 c1 c2 check
+permutation r1 w3 r2 p3 p1 w2 p2 c3 c2 c1 check
+permutation r1 w3 r2 p3 p1 w2 c3 p2 c1 c2 check
+permutation r1 w3 r2 p3 p1 w2 c3 p2 c2 c1 check
+permutation r1 w3 r2 p3 p1 w2 c3 c1 p2 c2 check
+permutation r1 w3 r2 p3 p1 c3 w2 p2 c1 c2 check
+permutation r1 w3 r2 p3 p1 c3 w2 p2 c2 c1 check
+permutation r1 w3 r2 p3 p1 c3 w2 c1 p2 c2 check
+permutation r1 w3 r2 p3 p1 c3 c1 w2 p2 c2 check
+permutation r1 w3 r2 p3 c3 w2 p1 p2 c1 c2 check
+permutation r1 w3 r2 p3 c3 w2 p1 p2 c2 c1 check
+permutation r1 w3 r2 p3 c3 w2 p1 c1 p2 c2 check
+permutation r1 w3 r2 p3 c3 w2 p2 p1 c1 c2 check
+permutation r1 w3 r2 p3 c3 w2 p2 p1 c2 c1 check
+permutation r1 w3 r2 p3 c3 w2 p2 c2 p1 c1 check
+permutation r1 w3 r2 p3 c3 p1 w2 p2 c1 c2 check
+permutation r1 w3 r2 p3 c3 p1 w2 p2 c2 c1 check
+permutation r1 w3 r2 p3 c3 p1 w2 c1 p2 c2 check
+permutation r1 w3 r2 p3 c3 p1 c1 w2 p2 c2 check
+permutation r1 w3 w2 r2 p1 p2 p3 c3 c1 c2 check
+permutation r1 w3 w2 r2 p1 p2 p3 c3 c2 c1 check
+permutation r1 w3 w2 r2 p1 p3 p2 c3 c1 c2 check
+permutation r1 w3 w2 r2 p1 p3 p2 c3 c2 c1 check
+permutation r1 w3 w2 r2 p1 p3 c3 p2 c1 c2 check
+permutation r1 w3 w2 r2 p1 p3 c3 p2 c2 c1 check
+permutation r1 w3 w2 r2 p1 p3 c3 c1 p2 c2 check
+permutation r1 w3 w2 r2 p2 p1 p3 c3 c1 c2 check
+permutation r1 w3 w2 r2 p2 p1 p3 c3 c2 c1 check
+permutation r1 w3 w2 r2 p2 p3 p1 c3 c1 c2 check
+permutation r1 w3 w2 r2 p2 p3 p1 c3 c2 c1 check
+permutation r1 w3 w2 r2 p2 p3 c3 p1 c1 c2 check
+permutation r1 w3 w2 r2 p2 p3 c3 p1 c2 c1 check
+permutation r1 w3 w2 r2 p2 p3 c3 c2 p1 c1 check
+permutation r1 w3 w2 r2 p3 p1 p2 c3 c1 c2 check
+permutation r1 w3 w2 r2 p3 p1 p2 c3 c2 c1 check
+permutation r1 w3 w2 r2 p3 p1 c3 p2 c1 c2 check
+permutation r1 w3 w2 r2 p3 p1 c3 p2 c2 c1 check
+permutation r1 w3 w2 r2 p3 p1 c3 c1 p2 c2 check
+permutation r1 w3 w2 r2 p3 p2 p1 c3 c1 c2 check
+permutation r1 w3 w2 r2 p3 p2 p1 c3 c2 c1 check
+permutation r1 w3 w2 r2 p3 p2 c3 p1 c1 c2 check
+permutation r1 w3 w2 r2 p3 p2 c3 p1 c2 c1 check
+permutation r1 w3 w2 r2 p3 p2 c3 c2 p1 c1 check
+permutation r1 w3 w2 r2 p3 c3 p1 p2 c1 c2 check
+permutation r1 w3 w2 r2 p3 c3 p1 p2 c2 c1 check
+permutation r1 w3 w2 r2 p3 c3 p1 c1 p2 c2 check
+permutation r1 w3 w2 r2 p3 c3 p2 p1 c1 c2 check
+permutation r1 w3 w2 r2 p3 c3 p2 p1 c2 c1 check
+permutation r1 w3 w2 r2 p3 c3 p2 c2 p1 c1 check
+permutation r1 w3 w2 p1 r2 p2 p3 c3 c1 c2 check
+permutation r1 w3 w2 p1 r2 p2 p3 c3 c2 c1 check
+permutation r1 w3 w2 p1 r2 p3 p2 c3 c1 c2 check
+permutation r1 w3 w2 p1 r2 p3 p2 c3 c2 c1 check
+permutation r1 w3 w2 p1 r2 p3 c3 p2 c1 c2 check
+permutation r1 w3 w2 p1 r2 p3 c3 p2 c2 c1 check
+permutation r1 w3 w2 p1 r2 p3 c3 c1 p2 c2 check
+permutation r1 w3 w2 p1 p3 r2 p2 c3 c1 c2 check
+permutation r1 w3 w2 p1 p3 r2 p2 c3 c2 c1 check
+permutation r1 w3 w2 p1 p3 r2 c3 p2 c1 c2 check
+permutation r1 w3 w2 p1 p3 r2 c3 p2 c2 c1 check
+permutation r1 w3 w2 p1 p3 r2 c3 c1 p2 c2 check
+permutation r1 w3 w2 p1 p3 c3 r2 p2 c1 c2 check
+permutation r1 w3 w2 p1 p3 c3 r2 p2 c2 c1 check
+permutation r1 w3 w2 p1 p3 c3 r2 c1 p2 c2 check
+permutation r1 w3 w2 p1 p3 c3 c1 r2 p2 c2 check
+permutation r1 w3 w2 p3 r2 p1 p2 c3 c1 c2 check
+permutation r1 w3 w2 p3 r2 p1 p2 c3 c2 c1 check
+permutation r1 w3 w2 p3 r2 p1 c3 p2 c1 c2 check
+permutation r1 w3 w2 p3 r2 p1 c3 p2 c2 c1 check
+permutation r1 w3 w2 p3 r2 p1 c3 c1 p2 c2 check
+permutation r1 w3 w2 p3 r2 p2 p1 c3 c1 c2 check
+permutation r1 w3 w2 p3 r2 p2 p1 c3 c2 c1 check
+permutation r1 w3 w2 p3 r2 p2 c3 p1 c1 c2 check
+permutation r1 w3 w2 p3 r2 p2 c3 p1 c2 c1 check
+permutation r1 w3 w2 p3 r2 p2 c3 c2 p1 c1 check
+permutation r1 w3 w2 p3 r2 c3 p1 p2 c1 c2 check
+permutation r1 w3 w2 p3 r2 c3 p1 p2 c2 c1 check
+permutation r1 w3 w2 p3 r2 c3 p1 c1 p2 c2 check
+permutation r1 w3 w2 p3 r2 c3 p2 p1 c1 c2 check
+permutation r1 w3 w2 p3 r2 c3 p2 p1 c2 c1 check
+permutation r1 w3 w2 p3 r2 c3 p2 c2 p1 c1 check
+permutation r1 w3 w2 p3 p1 r2 p2 c3 c1 c2 check
+permutation r1 w3 w2 p3 p1 r2 p2 c3 c2 c1 check
+permutation r1 w3 w2 p3 p1 r2 c3 p2 c1 c2 check
+permutation r1 w3 w2 p3 p1 r2 c3 p2 c2 c1 check
+permutation r1 w3 w2 p3 p1 r2 c3 c1 p2 c2 check
+permutation r1 w3 w2 p3 p1 c3 r2 p2 c1 c2 check
+permutation r1 w3 w2 p3 p1 c3 r2 p2 c2 c1 check
+permutation r1 w3 w2 p3 p1 c3 r2 c1 p2 c2 check
+permutation r1 w3 w2 p3 p1 c3 c1 r2 p2 c2 check
+permutation r1 w3 w2 p3 c3 r2 p1 p2 c1 c2 check
+permutation r1 w3 w2 p3 c3 r2 p1 p2 c2 c1 check
+permutation r1 w3 w2 p3 c3 r2 p1 c1 p2 c2 check
+permutation r1 w3 w2 p3 c3 r2 p2 p1 c1 c2 check
+permutation r1 w3 w2 p3 c3 r2 p2 p1 c2 c1 check
+permutation r1 w3 w2 p3 c3 r2 p2 c2 p1 c1 check
+permutation r1 w3 w2 p3 c3 p1 r2 p2 c1 c2 check
+permutation r1 w3 w2 p3 c3 p1 r2 p2 c2 c1 check
+permutation r1 w3 w2 p3 c3 p1 r2 c1 p2 c2 check
+permutation r1 w3 w2 p3 c3 p1 c1 r2 p2 c2 check
+permutation r1 w3 p1 r2 w2 p2 p3 c3 c1 c2 check
+permutation r1 w3 p1 r2 w2 p2 p3 c3 c2 c1 check
+permutation r1 w3 p1 r2 w2 p3 p2 c3 c1 c2 check
+permutation r1 w3 p1 r2 w2 p3 p2 c3 c2 c1 check
+permutation r1 w3 p1 r2 w2 p3 c3 p2 c1 c2 check
+permutation r1 w3 p1 r2 w2 p3 c3 p2 c2 c1 check
+permutation r1 w3 p1 r2 w2 p3 c3 c1 p2 c2 check
+permutation r1 w3 p1 r2 p3 w2 p2 c3 c1 c2 check
+permutation r1 w3 p1 r2 p3 w2 p2 c3 c2 c1 check
+permutation r1 w3 p1 r2 p3 w2 c3 p2 c1 c2 check
+permutation r1 w3 p1 r2 p3 w2 c3 p2 c2 c1 check
+permutation r1 w3 p1 r2 p3 w2 c3 c1 p2 c2 check
+permutation r1 w3 p1 r2 p3 c3 w2 p2 c1 c2 check
+permutation r1 w3 p1 r2 p3 c3 w2 p2 c2 c1 check
+permutation r1 w3 p1 r2 p3 c3 w2 c1 p2 c2 check
+permutation r1 w3 p1 r2 p3 c3 c1 w2 p2 c2 check
+permutation r1 w3 p1 w2 r2 p2 p3 c3 c1 c2 check
+permutation r1 w3 p1 w2 r2 p2 p3 c3 c2 c1 check
+permutation r1 w3 p1 w2 r2 p3 p2 c3 c1 c2 check
+permutation r1 w3 p1 w2 r2 p3 p2 c3 c2 c1 check
+permutation r1 w3 p1 w2 r2 p3 c3 p2 c1 c2 check
+permutation r1 w3 p1 w2 r2 p3 c3 p2 c2 c1 check
+permutation r1 w3 p1 w2 r2 p3 c3 c1 p2 c2 check
+permutation r1 w3 p1 w2 p3 r2 p2 c3 c1 c2 check
+permutation r1 w3 p1 w2 p3 r2 p2 c3 c2 c1 check
+permutation r1 w3 p1 w2 p3 r2 c3 p2 c1 c2 check
+permutation r1 w3 p1 w2 p3 r2 c3 p2 c2 c1 check
+permutation r1 w3 p1 w2 p3 r2 c3 c1 p2 c2 check
+permutation r1 w3 p1 w2 p3 c3 r2 p2 c1 c2 check
+permutation r1 w3 p1 w2 p3 c3 r2 p2 c2 c1 check
+permutation r1 w3 p1 w2 p3 c3 r2 c1 p2 c2 check
+permutation r1 w3 p1 w2 p3 c3 c1 r2 p2 c2 check
+permutation r1 w3 p1 p3 r2 w2 p2 c3 c1 c2 check
+permutation r1 w3 p1 p3 r2 w2 p2 c3 c2 c1 check
+permutation r1 w3 p1 p3 r2 w2 c3 p2 c1 c2 check
+permutation r1 w3 p1 p3 r2 w2 c3 p2 c2 c1 check
+permutation r1 w3 p1 p3 r2 w2 c3 c1 p2 c2 check
+permutation r1 w3 p1 p3 r2 c3 w2 p2 c1 c2 check
+permutation r1 w3 p1 p3 r2 c3 w2 p2 c2 c1 check
+permutation r1 w3 p1 p3 r2 c3 w2 c1 p2 c2 check
+permutation r1 w3 p1 p3 r2 c3 c1 w2 p2 c2 check
+permutation r1 w3 p1 p3 w2 r2 p2 c3 c1 c2 check
+permutation r1 w3 p1 p3 w2 r2 p2 c3 c2 c1 check
+permutation r1 w3 p1 p3 w2 r2 c3 p2 c1 c2 check
+permutation r1 w3 p1 p3 w2 r2 c3 p2 c2 c1 check
+permutation r1 w3 p1 p3 w2 r2 c3 c1 p2 c2 check
+permutation r1 w3 p1 p3 w2 c3 r2 p2 c1 c2 check
+permutation r1 w3 p1 p3 w2 c3 r2 p2 c2 c1 check
+permutation r1 w3 p1 p3 w2 c3 r2 c1 p2 c2 check
+permutation r1 w3 p1 p3 w2 c3 c1 r2 p2 c2 check
+permutation r1 w3 p1 p3 c3 r2 w2 p2 c1 c2 check
+permutation r1 w3 p1 p3 c3 r2 w2 p2 c2 c1 check
+permutation r1 w3 p1 p3 c3 r2 w2 c1 p2 c2 check
+permutation r1 w3 p1 p3 c3 r2 c1 w2 p2 c2 check
+permutation r1 w3 p1 p3 c3 w2 r2 p2 c1 c2 check
+permutation r1 w3 p1 p3 c3 w2 r2 p2 c2 c1 check
+permutation r1 w3 p1 p3 c3 w2 r2 c1 p2 c2 check
+permutation r1 w3 p1 p3 c3 w2 c1 r2 p2 c2 check
+permutation r1 w3 p1 p3 c3 c1 r2 w2 p2 c2 check
+permutation r1 w3 p1 p3 c3 c1 w2 r2 p2 c2 check
+permutation r1 w3 p3 r2 w2 p1 p2 c3 c1 c2 check
+permutation r1 w3 p3 r2 w2 p1 p2 c3 c2 c1 check
+permutation r1 w3 p3 r2 w2 p1 c3 p2 c1 c2 check
+permutation r1 w3 p3 r2 w2 p1 c3 p2 c2 c1 check
+permutation r1 w3 p3 r2 w2 p1 c3 c1 p2 c2 check
+permutation r1 w3 p3 r2 w2 p2 p1 c3 c1 c2 check
+permutation r1 w3 p3 r2 w2 p2 p1 c3 c2 c1 check
+permutation r1 w3 p3 r2 w2 p2 c3 p1 c1 c2 check
+permutation r1 w3 p3 r2 w2 p2 c3 p1 c2 c1 check
+permutation r1 w3 p3 r2 w2 p2 c3 c2 p1 c1 check
+permutation r1 w3 p3 r2 w2 c3 p1 p2 c1 c2 check
+permutation r1 w3 p3 r2 w2 c3 p1 p2 c2 c1 check
+permutation r1 w3 p3 r2 w2 c3 p1 c1 p2 c2 check
+permutation r1 w3 p3 r2 w2 c3 p2 p1 c1 c2 check
+permutation r1 w3 p3 r2 w2 c3 p2 p1 c2 c1 check
+permutation r1 w3 p3 r2 w2 c3 p2 c2 p1 c1 check
+permutation r1 w3 p3 r2 p1 w2 p2 c3 c1 c2 check
+permutation r1 w3 p3 r2 p1 w2 p2 c3 c2 c1 check
+permutation r1 w3 p3 r2 p1 w2 c3 p2 c1 c2 check
+permutation r1 w3 p3 r2 p1 w2 c3 p2 c2 c1 check
+permutation r1 w3 p3 r2 p1 w2 c3 c1 p2 c2 check
+permutation r1 w3 p3 r2 p1 c3 w2 p2 c1 c2 check
+permutation r1 w3 p3 r2 p1 c3 w2 p2 c2 c1 check
+permutation r1 w3 p3 r2 p1 c3 w2 c1 p2 c2 check
+permutation r1 w3 p3 r2 p1 c3 c1 w2 p2 c2 check
+permutation r1 w3 p3 r2 c3 w2 p1 p2 c1 c2 check
+permutation r1 w3 p3 r2 c3 w2 p1 p2 c2 c1 check
+permutation r1 w3 p3 r2 c3 w2 p1 c1 p2 c2 check
+permutation r1 w3 p3 r2 c3 w2 p2 p1 c1 c2 check
+permutation r1 w3 p3 r2 c3 w2 p2 p1 c2 c1 check
+permutation r1 w3 p3 r2 c3 w2 p2 c2 p1 c1 check
+permutation r1 w3 p3 r2 c3 p1 w2 p2 c1 c2 check
+permutation r1 w3 p3 r2 c3 p1 w2 p2 c2 c1 check
+permutation r1 w3 p3 r2 c3 p1 w2 c1 p2 c2 check
+permutation r1 w3 p3 r2 c3 p1 c1 w2 p2 c2 check
+permutation r1 w3 p3 w2 r2 p1 p2 c3 c1 c2 check
+permutation r1 w3 p3 w2 r2 p1 p2 c3 c2 c1 check
+permutation r1 w3 p3 w2 r2 p1 c3 p2 c1 c2 check
+permutation r1 w3 p3 w2 r2 p1 c3 p2 c2 c1 check
+permutation r1 w3 p3 w2 r2 p1 c3 c1 p2 c2 check
+permutation r1 w3 p3 w2 r2 p2 p1 c3 c1 c2 check
+permutation r1 w3 p3 w2 r2 p2 p1 c3 c2 c1 check
+permutation r1 w3 p3 w2 r2 p2 c3 p1 c1 c2 check
+permutation r1 w3 p3 w2 r2 p2 c3 p1 c2 c1 check
+permutation r1 w3 p3 w2 r2 p2 c3 c2 p1 c1 check
+permutation r1 w3 p3 w2 r2 c3 p1 p2 c1 c2 check
+permutation r1 w3 p3 w2 r2 c3 p1 p2 c2 c1 check
+permutation r1 w3 p3 w2 r2 c3 p1 c1 p2 c2 check
+permutation r1 w3 p3 w2 r2 c3 p2 p1 c1 c2 check
+permutation r1 w3 p3 w2 r2 c3 p2 p1 c2 c1 check
+permutation r1 w3 p3 w2 r2 c3 p2 c2 p1 c1 check
+permutation r1 w3 p3 w2 p1 r2 p2 c3 c1 c2 check
+permutation r1 w3 p3 w2 p1 r2 p2 c3 c2 c1 check
+permutation r1 w3 p3 w2 p1 r2 c3 p2 c1 c2 check
+permutation r1 w3 p3 w2 p1 r2 c3 p2 c2 c1 check
+permutation r1 w3 p3 w2 p1 r2 c3 c1 p2 c2 check
+permutation r1 w3 p3 w2 p1 c3 r2 p2 c1 c2 check
+permutation r1 w3 p3 w2 p1 c3 r2 p2 c2 c1 check
+permutation r1 w3 p3 w2 p1 c3 r2 c1 p2 c2 check
+permutation r1 w3 p3 w2 p1 c3 c1 r2 p2 c2 check
+permutation r1 w3 p3 w2 c3 r2 p1 p2 c1 c2 check
+permutation r1 w3 p3 w2 c3 r2 p1 p2 c2 c1 check
+permutation r1 w3 p3 w2 c3 r2 p1 c1 p2 c2 check
+permutation r1 w3 p3 w2 c3 r2 p2 p1 c1 c2 check
+permutation r1 w3 p3 w2 c3 r2 p2 p1 c2 c1 check
+permutation r1 w3 p3 w2 c3 r2 p2 c2 p1 c1 check
+permutation r1 w3 p3 w2 c3 p1 r2 p2 c1 c2 check
+permutation r1 w3 p3 w2 c3 p1 r2 p2 c2 c1 check
+permutation r1 w3 p3 w2 c3 p1 r2 c1 p2 c2 check
+permutation r1 w3 p3 w2 c3 p1 c1 r2 p2 c2 check
+permutation r1 w3 p3 p1 r2 w2 p2 c3 c1 c2 check
+permutation r1 w3 p3 p1 r2 w2 p2 c3 c2 c1 check
+permutation r1 w3 p3 p1 r2 w2 c3 p2 c1 c2 check
+permutation r1 w3 p3 p1 r2 w2 c3 p2 c2 c1 check
+permutation r1 w3 p3 p1 r2 w2 c3 c1 p2 c2 check
+permutation r1 w3 p3 p1 r2 c3 w2 p2 c1 c2 check
+permutation r1 w3 p3 p1 r2 c3 w2 p2 c2 c1 check
+permutation r1 w3 p3 p1 r2 c3 w2 c1 p2 c2 check
+permutation r1 w3 p3 p1 r2 c3 c1 w2 p2 c2 check
+permutation r1 w3 p3 p1 w2 r2 p2 c3 c1 c2 check
+permutation r1 w3 p3 p1 w2 r2 p2 c3 c2 c1 check
+permutation r1 w3 p3 p1 w2 r2 c3 p2 c1 c2 check
+permutation r1 w3 p3 p1 w2 r2 c3 p2 c2 c1 check
+permutation r1 w3 p3 p1 w2 r2 c3 c1 p2 c2 check
+permutation r1 w3 p3 p1 w2 c3 r2 p2 c1 c2 check
+permutation r1 w3 p3 p1 w2 c3 r2 p2 c2 c1 check
+permutation r1 w3 p3 p1 w2 c3 r2 c1 p2 c2 check
+permutation r1 w3 p3 p1 w2 c3 c1 r2 p2 c2 check
+permutation r1 w3 p3 p1 c3 r2 w2 p2 c1 c2 check
+permutation r1 w3 p3 p1 c3 r2 w2 p2 c2 c1 check
+permutation r1 w3 p3 p1 c3 r2 w2 c1 p2 c2 check
+permutation r1 w3 p3 p1 c3 r2 c1 w2 p2 c2 check
+permutation r1 w3 p3 p1 c3 w2 r2 p2 c1 c2 check
+permutation r1 w3 p3 p1 c3 w2 r2 p2 c2 c1 check
+permutation r1 w3 p3 p1 c3 w2 r2 c1 p2 c2 check
+permutation r1 w3 p3 p1 c3 w2 c1 r2 p2 c2 check
+permutation r1 w3 p3 p1 c3 c1 r2 w2 p2 c2 check
+permutation r1 w3 p3 p1 c3 c1 w2 r2 p2 c2 check
+permutation r1 w3 p3 c3 r2 w2 p1 p2 c1 c2 check
+permutation r1 w3 p3 c3 r2 w2 p1 p2 c2 c1 check
+permutation r1 w3 p3 c3 r2 w2 p1 c1 p2 c2 check
+permutation r1 w3 p3 c3 r2 w2 p2 p1 c1 c2 check
+permutation r1 w3 p3 c3 r2 w2 p2 p1 c2 c1 check
+permutation r1 w3 p3 c3 r2 w2 p2 c2 p1 c1 check
+permutation r1 w3 p3 c3 r2 p1 w2 p2 c1 c2 check
+permutation r1 w3 p3 c3 r2 p1 w2 p2 c2 c1 check
+permutation r1 w3 p3 c3 r2 p1 w2 c1 p2 c2 check
+permutation r1 w3 p3 c3 r2 p1 c1 w2 p2 c2 check
+permutation r1 w3 p3 c3 w2 r2 p1 p2 c1 c2 check
+permutation r1 w3 p3 c3 w2 r2 p1 p2 c2 c1 check
+permutation r1 w3 p3 c3 w2 r2 p1 c1 p2 c2 check
+permutation r1 w3 p3 c3 w2 r2 p2 p1 c1 c2 check
+permutation r1 w3 p3 c3 w2 r2 p2 p1 c2 c1 check
+permutation r1 w3 p3 c3 w2 r2 p2 c2 p1 c1 check
+permutation r1 w3 p3 c3 w2 p1 r2 p2 c1 c2 check
+permutation r1 w3 p3 c3 w2 p1 r2 p2 c2 c1 check
+permutation r1 w3 p3 c3 w2 p1 r2 c1 p2 c2 check
+permutation r1 w3 p3 c3 w2 p1 c1 r2 p2 c2 check
+permutation r1 w3 p3 c3 p1 r2 w2 p2 c1 c2 check
+permutation r1 w3 p3 c3 p1 r2 w2 p2 c2 c1 check
+permutation r1 w3 p3 c3 p1 r2 w2 c1 p2 c2 check
+permutation r1 w3 p3 c3 p1 r2 c1 w2 p2 c2 check
+permutation r1 w3 p3 c3 p1 w2 r2 p2 c1 c2 check
+permutation r1 w3 p3 c3 p1 w2 r2 p2 c2 c1 check
+permutation r1 w3 p3 c3 p1 w2 r2 c1 p2 c2 check
+permutation r1 w3 p3 c3 p1 w2 c1 r2 p2 c2 check
+permutation r1 w3 p3 c3 p1 c1 r2 w2 p2 c2 check
+permutation r1 w3 p3 c3 p1 c1 w2 r2 p2 c2 check
+permutation r1 p1 r2 w2 w3 p2 p3 c3 c1 c2 check
+permutation r1 p1 r2 w2 w3 p2 p3 c3 c2 c1 check
+permutation r1 p1 r2 w2 w3 p3 p2 c3 c1 c2 check
+permutation r1 p1 r2 w2 w3 p3 p2 c3 c2 c1 check
+permutation r1 p1 r2 w2 w3 p3 c3 p2 c1 c2 check
+permutation r1 p1 r2 w2 w3 p3 c3 p2 c2 c1 check
+permutation r1 p1 r2 w2 w3 p3 c3 c1 p2 c2 check
+permutation r1 p1 r2 w2 p2 w3 p3 c3 c1 c2 check
+permutation r1 p1 r2 w2 p2 w3 p3 c3 c2 c1 check
+permutation r1 p1 w2 w3 r2 p2 p3 c3 c1 c2 check
+permutation r1 p1 w2 w3 r2 p2 p3 c3 c2 c1 check
+permutation r1 p1 w2 w3 r2 p3 p2 c3 c1 c2 check
+permutation r1 p1 w2 w3 r2 p3 p2 c3 c2 c1 check
+permutation r1 p1 w2 w3 r2 p3 c3 p2 c1 c2 check
+permutation r1 p1 w2 w3 r2 p3 c3 p2 c2 c1 check
+permutation r1 p1 w2 w3 r2 p3 c3 c1 p2 c2 check
+permutation r1 p1 w2 w3 p3 r2 p2 c3 c1 c2 check
+permutation r1 p1 w2 w3 p3 r2 p2 c3 c2 c1 check
+permutation r1 p1 w2 w3 p3 r2 c3 p2 c1 c2 check
+permutation r1 p1 w2 w3 p3 r2 c3 p2 c2 c1 check
+permutation r1 p1 w2 w3 p3 r2 c3 c1 p2 c2 check
+permutation r1 p1 w2 w3 p3 c3 r2 p2 c1 c2 check
+permutation r1 p1 w2 w3 p3 c3 r2 p2 c2 c1 check
+permutation r1 p1 w2 w3 p3 c3 r2 c1 p2 c2 check
+permutation r1 p1 w2 w3 p3 c3 c1 r2 p2 c2 check
+permutation r1 p1 w3 r2 w2 p2 p3 c3 c1 c2 check
+permutation r1 p1 w3 r2 w2 p2 p3 c3 c2 c1 check
+permutation r1 p1 w3 r2 w2 p3 p2 c3 c1 c2 check
+permutation r1 p1 w3 r2 w2 p3 p2 c3 c2 c1 check
+permutation r1 p1 w3 r2 w2 p3 c3 p2 c1 c2 check
+permutation r1 p1 w3 r2 w2 p3 c3 p2 c2 c1 check
+permutation r1 p1 w3 r2 w2 p3 c3 c1 p2 c2 check
+permutation r1 p1 w3 r2 p3 w2 p2 c3 c1 c2 check
+permutation r1 p1 w3 r2 p3 w2 p2 c3 c2 c1 check
+permutation r1 p1 w3 r2 p3 w2 c3 p2 c1 c2 check
+permutation r1 p1 w3 r2 p3 w2 c3 p2 c2 c1 check
+permutation r1 p1 w3 r2 p3 w2 c3 c1 p2 c2 check
+permutation r1 p1 w3 r2 p3 c3 w2 p2 c1 c2 check
+permutation r1 p1 w3 r2 p3 c3 w2 p2 c2 c1 check
+permutation r1 p1 w3 r2 p3 c3 w2 c1 p2 c2 check
+permutation r1 p1 w3 r2 p3 c3 c1 w2 p2 c2 check
+permutation r1 p1 w3 w2 r2 p2 p3 c3 c1 c2 check
+permutation r1 p1 w3 w2 r2 p2 p3 c3 c2 c1 check
+permutation r1 p1 w3 w2 r2 p3 p2 c3 c1 c2 check
+permutation r1 p1 w3 w2 r2 p3 p2 c3 c2 c1 check
+permutation r1 p1 w3 w2 r2 p3 c3 p2 c1 c2 check
+permutation r1 p1 w3 w2 r2 p3 c3 p2 c2 c1 check
+permutation r1 p1 w3 w2 r2 p3 c3 c1 p2 c2 check
+permutation r1 p1 w3 w2 p3 r2 p2 c3 c1 c2 check
+permutation r1 p1 w3 w2 p3 r2 p2 c3 c2 c1 check
+permutation r1 p1 w3 w2 p3 r2 c3 p2 c1 c2 check
+permutation r1 p1 w3 w2 p3 r2 c3 p2 c2 c1 check
+permutation r1 p1 w3 w2 p3 r2 c3 c1 p2 c2 check
+permutation r1 p1 w3 w2 p3 c3 r2 p2 c1 c2 check
+permutation r1 p1 w3 w2 p3 c3 r2 p2 c2 c1 check
+permutation r1 p1 w3 w2 p3 c3 r2 c1 p2 c2 check
+permutation r1 p1 w3 w2 p3 c3 c1 r2 p2 c2 check
+permutation r1 p1 w3 p3 r2 w2 p2 c3 c1 c2 check
+permutation r1 p1 w3 p3 r2 w2 p2 c3 c2 c1 check
+permutation r1 p1 w3 p3 r2 w2 c3 p2 c1 c2 check
+permutation r1 p1 w3 p3 r2 w2 c3 p2 c2 c1 check
+permutation r1 p1 w3 p3 r2 w2 c3 c1 p2 c2 check
+permutation r1 p1 w3 p3 r2 c3 w2 p2 c1 c2 check
+permutation r1 p1 w3 p3 r2 c3 w2 p2 c2 c1 check
+permutation r1 p1 w3 p3 r2 c3 w2 c1 p2 c2 check
+permutation r1 p1 w3 p3 r2 c3 c1 w2 p2 c2 check
+permutation r1 p1 w3 p3 w2 r2 p2 c3 c1 c2 check
+permutation r1 p1 w3 p3 w2 r2 p2 c3 c2 c1 check
+permutation r1 p1 w3 p3 w2 r2 c3 p2 c1 c2 check
+permutation r1 p1 w3 p3 w2 r2 c3 p2 c2 c1 check
+permutation r1 p1 w3 p3 w2 r2 c3 c1 p2 c2 check
+permutation r1 p1 w3 p3 w2 c3 r2 p2 c1 c2 check
+permutation r1 p1 w3 p3 w2 c3 r2 p2 c2 c1 check
+permutation r1 p1 w3 p3 w2 c3 r2 c1 p2 c2 check
+permutation r1 p1 w3 p3 w2 c3 c1 r2 p2 c2 check
+permutation r1 p1 w3 p3 c3 r2 w2 p2 c1 c2 check
+permutation r1 p1 w3 p3 c3 r2 w2 p2 c2 c1 check
+permutation r1 p1 w3 p3 c3 r2 w2 c1 p2 c2 check
+permutation r1 p1 w3 p3 c3 r2 c1 w2 p2 c2 check
+permutation r1 p1 w3 p3 c3 w2 r2 p2 c1 c2 check
+permutation r1 p1 w3 p3 c3 w2 r2 p2 c2 c1 check
+permutation r1 p1 w3 p3 c3 w2 r2 c1 p2 c2 check
+permutation r1 p1 w3 p3 c3 w2 c1 r2 p2 c2 check
+permutation r1 p1 w3 p3 c3 c1 r2 w2 p2 c2 check
+permutation r1 p1 w3 p3 c3 c1 w2 r2 p2 c2 check
+permutation w2 r1 r2 w3 p1 p2 p3 c3 c1 c2 check
+permutation w2 r1 r2 w3 p1 p2 p3 c3 c2 c1 check
+permutation w2 r1 r2 w3 p1 p3 p2 c3 c1 c2 check
+permutation w2 r1 r2 w3 p1 p3 p2 c3 c2 c1 check
+permutation w2 r1 r2 w3 p1 p3 c3 p2 c1 c2 check
+permutation w2 r1 r2 w3 p1 p3 c3 p2 c2 c1 check
+permutation w2 r1 r2 w3 p1 p3 c3 c1 p2 c2 check
+permutation w2 r1 r2 w3 p2 p1 p3 c3 c1 c2 check
+permutation w2 r1 r2 w3 p2 p1 p3 c3 c2 c1 check
+permutation w2 r1 r2 w3 p2 p3 p1 c3 c1 c2 check
+permutation w2 r1 r2 w3 p2 p3 p1 c3 c2 c1 check
+permutation w2 r1 r2 w3 p2 p3 c3 p1 c1 c2 check
+permutation w2 r1 r2 w3 p2 p3 c3 p1 c2 c1 check
+permutation w2 r1 r2 w3 p2 p3 c3 c2 p1 c1 check
+permutation w2 r1 r2 w3 p3 p1 p2 c3 c1 c2 check
+permutation w2 r1 r2 w3 p3 p1 p2 c3 c2 c1 check
+permutation w2 r1 r2 w3 p3 p1 c3 p2 c1 c2 check
+permutation w2 r1 r2 w3 p3 p1 c3 p2 c2 c1 check
+permutation w2 r1 r2 w3 p3 p1 c3 c1 p2 c2 check
+permutation w2 r1 r2 w3 p3 p2 p1 c3 c1 c2 check
+permutation w2 r1 r2 w3 p3 p2 p1 c3 c2 c1 check
+permutation w2 r1 r2 w3 p3 p2 c3 p1 c1 c2 check
+permutation w2 r1 r2 w3 p3 p2 c3 p1 c2 c1 check
+permutation w2 r1 r2 w3 p3 p2 c3 c2 p1 c1 check
+permutation w2 r1 r2 w3 p3 c3 p1 p2 c1 c2 check
+permutation w2 r1 r2 w3 p3 c3 p1 p2 c2 c1 check
+permutation w2 r1 r2 w3 p3 c3 p1 c1 p2 c2 check
+permutation w2 r1 r2 w3 p3 c3 p2 p1 c1 c2 check
+permutation w2 r1 r2 w3 p3 c3 p2 p1 c2 c1 check
+permutation w2 r1 r2 w3 p3 c3 p2 c2 p1 c1 check
+permutation w2 r1 r2 p1 w3 p2 p3 c3 c1 c2 check
+permutation w2 r1 r2 p1 w3 p2 p3 c3 c2 c1 check
+permutation w2 r1 r2 p1 w3 p3 p2 c3 c1 c2 check
+permutation w2 r1 r2 p1 w3 p3 p2 c3 c2 c1 check
+permutation w2 r1 r2 p1 w3 p3 c3 p2 c1 c2 check
+permutation w2 r1 r2 p1 w3 p3 c3 p2 c2 c1 check
+permutation w2 r1 r2 p1 w3 p3 c3 c1 p2 c2 check
+permutation w2 r1 r2 p1 p2 w3 p3 c3 c1 c2 check
+permutation w2 r1 r2 p1 p2 w3 p3 c3 c2 c1 check
+permutation w2 r1 r2 p2 w3 p1 p3 c3 c1 c2 check
+permutation w2 r1 r2 p2 w3 p1 p3 c3 c2 c1 check
+permutation w2 r1 r2 p2 w3 p3 p1 c3 c1 c2 check
+permutation w2 r1 r2 p2 w3 p3 p1 c3 c2 c1 check
+permutation w2 r1 r2 p2 w3 p3 c3 p1 c1 c2 check
+permutation w2 r1 r2 p2 w3 p3 c3 p1 c2 c1 check
+permutation w2 r1 r2 p2 w3 p3 c3 c2 p1 c1 check
+permutation w2 r1 r2 p2 p1 w3 p3 c3 c1 c2 check
+permutation w2 r1 r2 p2 p1 w3 p3 c3 c2 c1 check
+permutation w2 r1 w3 r2 p1 p2 p3 c3 c1 c2 check
+permutation w2 r1 w3 r2 p1 p2 p3 c3 c2 c1 check
+permutation w2 r1 w3 r2 p1 p3 p2 c3 c1 c2 check
+permutation w2 r1 w3 r2 p1 p3 p2 c3 c2 c1 check
+permutation w2 r1 w3 r2 p1 p3 c3 p2 c1 c2 check
+permutation w2 r1 w3 r2 p1 p3 c3 p2 c2 c1 check
+permutation w2 r1 w3 r2 p1 p3 c3 c1 p2 c2 check
+permutation w2 r1 w3 r2 p2 p1 p3 c3 c1 c2 check
+permutation w2 r1 w3 r2 p2 p1 p3 c3 c2 c1 check
+permutation w2 r1 w3 r2 p2 p3 p1 c3 c1 c2 check
+permutation w2 r1 w3 r2 p2 p3 p1 c3 c2 c1 check
+permutation w2 r1 w3 r2 p2 p3 c3 p1 c1 c2 check
+permutation w2 r1 w3 r2 p2 p3 c3 p1 c2 c1 check
+permutation w2 r1 w3 r2 p2 p3 c3 c2 p1 c1 check
+permutation w2 r1 w3 r2 p3 p1 p2 c3 c1 c2 check
+permutation w2 r1 w3 r2 p3 p1 p2 c3 c2 c1 check
+permutation w2 r1 w3 r2 p3 p1 c3 p2 c1 c2 check
+permutation w2 r1 w3 r2 p3 p1 c3 p2 c2 c1 check
+permutation w2 r1 w3 r2 p3 p1 c3 c1 p2 c2 check
+permutation w2 r1 w3 r2 p3 p2 p1 c3 c1 c2 check
+permutation w2 r1 w3 r2 p3 p2 p1 c3 c2 c1 check
+permutation w2 r1 w3 r2 p3 p2 c3 p1 c1 c2 check
+permutation w2 r1 w3 r2 p3 p2 c3 p1 c2 c1 check
+permutation w2 r1 w3 r2 p3 p2 c3 c2 p1 c1 check
+permutation w2 r1 w3 r2 p3 c3 p1 p2 c1 c2 check
+permutation w2 r1 w3 r2 p3 c3 p1 p2 c2 c1 check
+permutation w2 r1 w3 r2 p3 c3 p1 c1 p2 c2 check
+permutation w2 r1 w3 r2 p3 c3 p2 p1 c1 c2 check
+permutation w2 r1 w3 r2 p3 c3 p2 p1 c2 c1 check
+permutation w2 r1 w3 r2 p3 c3 p2 c2 p1 c1 check
+permutation w2 r1 w3 p1 r2 p2 p3 c3 c1 c2 check
+permutation w2 r1 w3 p1 r2 p2 p3 c3 c2 c1 check
+permutation w2 r1 w3 p1 r2 p3 p2 c3 c1 c2 check
+permutation w2 r1 w3 p1 r2 p3 p2 c3 c2 c1 check
+permutation w2 r1 w3 p1 r2 p3 c3 p2 c1 c2 check
+permutation w2 r1 w3 p1 r2 p3 c3 p2 c2 c1 check
+permutation w2 r1 w3 p1 r2 p3 c3 c1 p2 c2 check
+permutation w2 r1 w3 p1 p3 r2 p2 c3 c1 c2 check
+permutation w2 r1 w3 p1 p3 r2 p2 c3 c2 c1 check
+permutation w2 r1 w3 p1 p3 r2 c3 p2 c1 c2 check
+permutation w2 r1 w3 p1 p3 r2 c3 p2 c2 c1 check
+permutation w2 r1 w3 p1 p3 r2 c3 c1 p2 c2 check
+permutation w2 r1 w3 p1 p3 c3 r2 p2 c1 c2 check
+permutation w2 r1 w3 p1 p3 c3 r2 p2 c2 c1 check
+permutation w2 r1 w3 p1 p3 c3 r2 c1 p2 c2 check
+permutation w2 r1 w3 p1 p3 c3 c1 r2 p2 c2 check
+permutation w2 r1 w3 p3 r2 p1 p2 c3 c1 c2 check
+permutation w2 r1 w3 p3 r2 p1 p2 c3 c2 c1 check
+permutation w2 r1 w3 p3 r2 p1 c3 p2 c1 c2 check
+permutation w2 r1 w3 p3 r2 p1 c3 p2 c2 c1 check
+permutation w2 r1 w3 p3 r2 p1 c3 c1 p2 c2 check
+permutation w2 r1 w3 p3 r2 p2 p1 c3 c1 c2 check
+permutation w2 r1 w3 p3 r2 p2 p1 c3 c2 c1 check
+permutation w2 r1 w3 p3 r2 p2 c3 p1 c1 c2 check
+permutation w2 r1 w3 p3 r2 p2 c3 p1 c2 c1 check
+permutation w2 r1 w3 p3 r2 p2 c3 c2 p1 c1 check
+permutation w2 r1 w3 p3 r2 c3 p1 p2 c1 c2 check
+permutation w2 r1 w3 p3 r2 c3 p1 p2 c2 c1 check
+permutation w2 r1 w3 p3 r2 c3 p1 c1 p2 c2 check
+permutation w2 r1 w3 p3 r2 c3 p2 p1 c1 c2 check
+permutation w2 r1 w3 p3 r2 c3 p2 p1 c2 c1 check
+permutation w2 r1 w3 p3 r2 c3 p2 c2 p1 c1 check
+permutation w2 r1 w3 p3 p1 r2 p2 c3 c1 c2 check
+permutation w2 r1 w3 p3 p1 r2 p2 c3 c2 c1 check
+permutation w2 r1 w3 p3 p1 r2 c3 p2 c1 c2 check
+permutation w2 r1 w3 p3 p1 r2 c3 p2 c2 c1 check
+permutation w2 r1 w3 p3 p1 r2 c3 c1 p2 c2 check
+permutation w2 r1 w3 p3 p1 c3 r2 p2 c1 c2 check
+permutation w2 r1 w3 p3 p1 c3 r2 p2 c2 c1 check
+permutation w2 r1 w3 p3 p1 c3 r2 c1 p2 c2 check
+permutation w2 r1 w3 p3 p1 c3 c1 r2 p2 c2 check
+permutation w2 r1 w3 p3 c3 r2 p1 p2 c1 c2 check
+permutation w2 r1 w3 p3 c3 r2 p1 p2 c2 c1 check
+permutation w2 r1 w3 p3 c3 r2 p1 c1 p2 c2 check
+permutation w2 r1 w3 p3 c3 r2 p2 p1 c1 c2 check
+permutation w2 r1 w3 p3 c3 r2 p2 p1 c2 c1 check
+permutation w2 r1 w3 p3 c3 r2 p2 c2 p1 c1 check
+permutation w2 r1 w3 p3 c3 p1 r2 p2 c1 c2 check
+permutation w2 r1 w3 p3 c3 p1 r2 p2 c2 c1 check
+permutation w2 r1 w3 p3 c3 p1 r2 c1 p2 c2 check
+permutation w2 r1 w3 p3 c3 p1 c1 r2 p2 c2 check
+permutation w2 r1 p1 r2 w3 p2 p3 c3 c1 c2 check
+permutation w2 r1 p1 r2 w3 p2 p3 c3 c2 c1 check
+permutation w2 r1 p1 r2 w3 p3 p2 c3 c1 c2 check
+permutation w2 r1 p1 r2 w3 p3 p2 c3 c2 c1 check
+permutation w2 r1 p1 r2 w3 p3 c3 p2 c1 c2 check
+permutation w2 r1 p1 r2 w3 p3 c3 p2 c2 c1 check
+permutation w2 r1 p1 r2 w3 p3 c3 c1 p2 c2 check
+permutation w2 r1 p1 r2 p2 w3 p3 c3 c1 c2 check
+permutation w2 r1 p1 r2 p2 w3 p3 c3 c2 c1 check
+permutation w2 r1 p1 w3 r2 p2 p3 c3 c1 c2 check
+permutation w2 r1 p1 w3 r2 p2 p3 c3 c2 c1 check
+permutation w2 r1 p1 w3 r2 p3 p2 c3 c1 c2 check
+permutation w2 r1 p1 w3 r2 p3 p2 c3 c2 c1 check
+permutation w2 r1 p1 w3 r2 p3 c3 p2 c1 c2 check
+permutation w2 r1 p1 w3 r2 p3 c3 p2 c2 c1 check
+permutation w2 r1 p1 w3 r2 p3 c3 c1 p2 c2 check
+permutation w2 r1 p1 w3 p3 r2 p2 c3 c1 c2 check
+permutation w2 r1 p1 w3 p3 r2 p2 c3 c2 c1 check
+permutation w2 r1 p1 w3 p3 r2 c3 p2 c1 c2 check
+permutation w2 r1 p1 w3 p3 r2 c3 p2 c2 c1 check
+permutation w2 r1 p1 w3 p3 r2 c3 c1 p2 c2 check
+permutation w2 r1 p1 w3 p3 c3 r2 p2 c1 c2 check
+permutation w2 r1 p1 w3 p3 c3 r2 p2 c2 c1 check
+permutation w2 r1 p1 w3 p3 c3 r2 c1 p2 c2 check
+permutation w2 r1 p1 w3 p3 c3 c1 r2 p2 c2 check
+permutation w3 r1 r2 w2 p1 p2 p3 c3 c1 c2 check
+permutation w3 r1 r2 w2 p1 p2 p3 c3 c2 c1 check
+permutation w3 r1 r2 w2 p1 p3 p2 c3 c1 c2 check
+permutation w3 r1 r2 w2 p1 p3 p2 c3 c2 c1 check
+permutation w3 r1 r2 w2 p1 p3 c3 p2 c1 c2 check
+permutation w3 r1 r2 w2 p1 p3 c3 p2 c2 c1 check
+permutation w3 r1 r2 w2 p1 p3 c3 c1 p2 c2 check
+permutation w3 r1 r2 w2 p2 p1 p3 c3 c1 c2 check
+permutation w3 r1 r2 w2 p2 p1 p3 c3 c2 c1 check
+permutation w3 r1 r2 w2 p2 p3 p1 c3 c1 c2 check
+permutation w3 r1 r2 w2 p2 p3 p1 c3 c2 c1 check
+permutation w3 r1 r2 w2 p2 p3 c3 p1 c1 c2 check
+permutation w3 r1 r2 w2 p2 p3 c3 p1 c2 c1 check
+permutation w3 r1 r2 w2 p2 p3 c3 c2 p1 c1 check
+permutation w3 r1 r2 w2 p3 p1 p2 c3 c1 c2 check
+permutation w3 r1 r2 w2 p3 p1 p2 c3 c2 c1 check
+permutation w3 r1 r2 w2 p3 p1 c3 p2 c1 c2 check
+permutation w3 r1 r2 w2 p3 p1 c3 p2 c2 c1 check
+permutation w3 r1 r2 w2 p3 p1 c3 c1 p2 c2 check
+permutation w3 r1 r2 w2 p3 p2 p1 c3 c1 c2 check
+permutation w3 r1 r2 w2 p3 p2 p1 c3 c2 c1 check
+permutation w3 r1 r2 w2 p3 p2 c3 p1 c1 c2 check
+permutation w3 r1 r2 w2 p3 p2 c3 p1 c2 c1 check
+permutation w3 r1 r2 w2 p3 p2 c3 c2 p1 c1 check
+permutation w3 r1 r2 w2 p3 c3 p1 p2 c1 c2 check
+permutation w3 r1 r2 w2 p3 c3 p1 p2 c2 c1 check
+permutation w3 r1 r2 w2 p3 c3 p1 c1 p2 c2 check
+permutation w3 r1 r2 w2 p3 c3 p2 p1 c1 c2 check
+permutation w3 r1 r2 w2 p3 c3 p2 p1 c2 c1 check
+permutation w3 r1 r2 w2 p3 c3 p2 c2 p1 c1 check
+permutation w3 r1 r2 p1 w2 p2 p3 c3 c1 c2 check
+permutation w3 r1 r2 p1 w2 p2 p3 c3 c2 c1 check
+permutation w3 r1 r2 p1 w2 p3 p2 c3 c1 c2 check
+permutation w3 r1 r2 p1 w2 p3 p2 c3 c2 c1 check
+permutation w3 r1 r2 p1 w2 p3 c3 p2 c1 c2 check
+permutation w3 r1 r2 p1 w2 p3 c3 p2 c2 c1 check
+permutation w3 r1 r2 p1 w2 p3 c3 c1 p2 c2 check
+permutation w3 r1 r2 p1 p3 w2 p2 c3 c1 c2 check
+permutation w3 r1 r2 p1 p3 w2 p2 c3 c2 c1 check
+permutation w3 r1 r2 p1 p3 w2 c3 p2 c1 c2 check
+permutation w3 r1 r2 p1 p3 w2 c3 p2 c2 c1 check
+permutation w3 r1 r2 p1 p3 w2 c3 c1 p2 c2 check
+permutation w3 r1 r2 p1 p3 c3 w2 p2 c1 c2 check
+permutation w3 r1 r2 p1 p3 c3 w2 p2 c2 c1 check
+permutation w3 r1 r2 p1 p3 c3 w2 c1 p2 c2 check
+permutation w3 r1 r2 p1 p3 c3 c1 w2 p2 c2 check
+permutation w3 r1 r2 p3 w2 p1 p2 c3 c1 c2 check
+permutation w3 r1 r2 p3 w2 p1 p2 c3 c2 c1 check
+permutation w3 r1 r2 p3 w2 p1 c3 p2 c1 c2 check
+permutation w3 r1 r2 p3 w2 p1 c3 p2 c2 c1 check
+permutation w3 r1 r2 p3 w2 p1 c3 c1 p2 c2 check
+permutation w3 r1 r2 p3 w2 p2 p1 c3 c1 c2 check
+permutation w3 r1 r2 p3 w2 p2 p1 c3 c2 c1 check
+permutation w3 r1 r2 p3 w2 p2 c3 p1 c1 c2 check
+permutation w3 r1 r2 p3 w2 p2 c3 p1 c2 c1 check
+permutation w3 r1 r2 p3 w2 p2 c3 c2 p1 c1 check
+permutation w3 r1 r2 p3 w2 c3 p1 p2 c1 c2 check
+permutation w3 r1 r2 p3 w2 c3 p1 p2 c2 c1 check
+permutation w3 r1 r2 p3 w2 c3 p1 c1 p2 c2 check
+permutation w3 r1 r2 p3 w2 c3 p2 p1 c1 c2 check
+permutation w3 r1 r2 p3 w2 c3 p2 p1 c2 c1 check
+permutation w3 r1 r2 p3 w2 c3 p2 c2 p1 c1 check
+permutation w3 r1 r2 p3 p1 w2 p2 c3 c1 c2 check
+permutation w3 r1 r2 p3 p1 w2 p2 c3 c2 c1 check
+permutation w3 r1 r2 p3 p1 w2 c3 p2 c1 c2 check
+permutation w3 r1 r2 p3 p1 w2 c3 p2 c2 c1 check
+permutation w3 r1 r2 p3 p1 w2 c3 c1 p2 c2 check
+permutation w3 r1 r2 p3 p1 c3 w2 p2 c1 c2 check
+permutation w3 r1 r2 p3 p1 c3 w2 p2 c2 c1 check
+permutation w3 r1 r2 p3 p1 c3 w2 c1 p2 c2 check
+permutation w3 r1 r2 p3 p1 c3 c1 w2 p2 c2 check
+permutation w3 r1 r2 p3 c3 w2 p1 p2 c1 c2 check
+permutation w3 r1 r2 p3 c3 w2 p1 p2 c2 c1 check
+permutation w3 r1 r2 p3 c3 w2 p1 c1 p2 c2 check
+permutation w3 r1 r2 p3 c3 w2 p2 p1 c1 c2 check
+permutation w3 r1 r2 p3 c3 w2 p2 p1 c2 c1 check
+permutation w3 r1 r2 p3 c3 w2 p2 c2 p1 c1 check
+permutation w3 r1 r2 p3 c3 p1 w2 p2 c1 c2 check
+permutation w3 r1 r2 p3 c3 p1 w2 p2 c2 c1 check
+permutation w3 r1 r2 p3 c3 p1 w2 c1 p2 c2 check
+permutation w3 r1 r2 p3 c3 p1 c1 w2 p2 c2 check
+permutation w3 r1 w2 r2 p1 p2 p3 c3 c1 c2 check
+permutation w3 r1 w2 r2 p1 p2 p3 c3 c2 c1 check
+permutation w3 r1 w2 r2 p1 p3 p2 c3 c1 c2 check
+permutation w3 r1 w2 r2 p1 p3 p2 c3 c2 c1 check
+permutation w3 r1 w2 r2 p1 p3 c3 p2 c1 c2 check
+permutation w3 r1 w2 r2 p1 p3 c3 p2 c2 c1 check
+permutation w3 r1 w2 r2 p1 p3 c3 c1 p2 c2 check
+permutation w3 r1 w2 r2 p2 p1 p3 c3 c1 c2 check
+permutation w3 r1 w2 r2 p2 p1 p3 c3 c2 c1 check
+permutation w3 r1 w2 r2 p2 p3 p1 c3 c1 c2 check
+permutation w3 r1 w2 r2 p2 p3 p1 c3 c2 c1 check
+permutation w3 r1 w2 r2 p2 p3 c3 p1 c1 c2 check
+permutation w3 r1 w2 r2 p2 p3 c3 p1 c2 c1 check
+permutation w3 r1 w2 r2 p2 p3 c3 c2 p1 c1 check
+permutation w3 r1 w2 r2 p3 p1 p2 c3 c1 c2 check
+permutation w3 r1 w2 r2 p3 p1 p2 c3 c2 c1 check
+permutation w3 r1 w2 r2 p3 p1 c3 p2 c1 c2 check
+permutation w3 r1 w2 r2 p3 p1 c3 p2 c2 c1 check
+permutation w3 r1 w2 r2 p3 p1 c3 c1 p2 c2 check
+permutation w3 r1 w2 r2 p3 p2 p1 c3 c1 c2 check
+permutation w3 r1 w2 r2 p3 p2 p1 c3 c2 c1 check
+permutation w3 r1 w2 r2 p3 p2 c3 p1 c1 c2 check
+permutation w3 r1 w2 r2 p3 p2 c3 p1 c2 c1 check
+permutation w3 r1 w2 r2 p3 p2 c3 c2 p1 c1 check
+permutation w3 r1 w2 r2 p3 c3 p1 p2 c1 c2 check
+permutation w3 r1 w2 r2 p3 c3 p1 p2 c2 c1 check
+permutation w3 r1 w2 r2 p3 c3 p1 c1 p2 c2 check
+permutation w3 r1 w2 r2 p3 c3 p2 p1 c1 c2 check
+permutation w3 r1 w2 r2 p3 c3 p2 p1 c2 c1 check
+permutation w3 r1 w2 r2 p3 c3 p2 c2 p1 c1 check
+permutation w3 r1 w2 p1 r2 p2 p3 c3 c1 c2 check
+permutation w3 r1 w2 p1 r2 p2 p3 c3 c2 c1 check
+permutation w3 r1 w2 p1 r2 p3 p2 c3 c1 c2 check
+permutation w3 r1 w2 p1 r2 p3 p2 c3 c2 c1 check
+permutation w3 r1 w2 p1 r2 p3 c3 p2 c1 c2 check
+permutation w3 r1 w2 p1 r2 p3 c3 p2 c2 c1 check
+permutation w3 r1 w2 p1 r2 p3 c3 c1 p2 c2 check
+permutation w3 r1 w2 p1 p3 r2 p2 c3 c1 c2 check
+permutation w3 r1 w2 p1 p3 r2 p2 c3 c2 c1 check
+permutation w3 r1 w2 p1 p3 r2 c3 p2 c1 c2 check
+permutation w3 r1 w2 p1 p3 r2 c3 p2 c2 c1 check
+permutation w3 r1 w2 p1 p3 r2 c3 c1 p2 c2 check
+permutation w3 r1 w2 p1 p3 c3 r2 p2 c1 c2 check
+permutation w3 r1 w2 p1 p3 c3 r2 p2 c2 c1 check
+permutation w3 r1 w2 p1 p3 c3 r2 c1 p2 c2 check
+permutation w3 r1 w2 p1 p3 c3 c1 r2 p2 c2 check
+permutation w3 r1 w2 p3 r2 p1 p2 c3 c1 c2 check
+permutation w3 r1 w2 p3 r2 p1 p2 c3 c2 c1 check
+permutation w3 r1 w2 p3 r2 p1 c3 p2 c1 c2 check
+permutation w3 r1 w2 p3 r2 p1 c3 p2 c2 c1 check
+permutation w3 r1 w2 p3 r2 p1 c3 c1 p2 c2 check
+permutation w3 r1 w2 p3 r2 p2 p1 c3 c1 c2 check
+permutation w3 r1 w2 p3 r2 p2 p1 c3 c2 c1 check
+permutation w3 r1 w2 p3 r2 p2 c3 p1 c1 c2 check
+permutation w3 r1 w2 p3 r2 p2 c3 p1 c2 c1 check
+permutation w3 r1 w2 p3 r2 p2 c3 c2 p1 c1 check
+permutation w3 r1 w2 p3 r2 c3 p1 p2 c1 c2 check
+permutation w3 r1 w2 p3 r2 c3 p1 p2 c2 c1 check
+permutation w3 r1 w2 p3 r2 c3 p1 c1 p2 c2 check
+permutation w3 r1 w2 p3 r2 c3 p2 p1 c1 c2 check
+permutation w3 r1 w2 p3 r2 c3 p2 p1 c2 c1 check
+permutation w3 r1 w2 p3 r2 c3 p2 c2 p1 c1 check
+permutation w3 r1 w2 p3 p1 r2 p2 c3 c1 c2 check
+permutation w3 r1 w2 p3 p1 r2 p2 c3 c2 c1 check
+permutation w3 r1 w2 p3 p1 r2 c3 p2 c1 c2 check
+permutation w3 r1 w2 p3 p1 r2 c3 p2 c2 c1 check
+permutation w3 r1 w2 p3 p1 r2 c3 c1 p2 c2 check
+permutation w3 r1 w2 p3 p1 c3 r2 p2 c1 c2 check
+permutation w3 r1 w2 p3 p1 c3 r2 p2 c2 c1 check
+permutation w3 r1 w2 p3 p1 c3 r2 c1 p2 c2 check
+permutation w3 r1 w2 p3 p1 c3 c1 r2 p2 c2 check
+permutation w3 r1 w2 p3 c3 r2 p1 p2 c1 c2 check
+permutation w3 r1 w2 p3 c3 r2 p1 p2 c2 c1 check
+permutation w3 r1 w2 p3 c3 r2 p1 c1 p2 c2 check
+permutation w3 r1 w2 p3 c3 r2 p2 p1 c1 c2 check
+permutation w3 r1 w2 p3 c3 r2 p2 p1 c2 c1 check
+permutation w3 r1 w2 p3 c3 r2 p2 c2 p1 c1 check
+permutation w3 r1 w2 p3 c3 p1 r2 p2 c1 c2 check
+permutation w3 r1 w2 p3 c3 p1 r2 p2 c2 c1 check
+permutation w3 r1 w2 p3 c3 p1 r2 c1 p2 c2 check
+permutation w3 r1 w2 p3 c3 p1 c1 r2 p2 c2 check
+permutation w3 r1 p1 r2 w2 p2 p3 c3 c1 c2 check
+permutation w3 r1 p1 r2 w2 p2 p3 c3 c2 c1 check
+permutation w3 r1 p1 r2 w2 p3 p2 c3 c1 c2 check
+permutation w3 r1 p1 r2 w2 p3 p2 c3 c2 c1 check
+permutation w3 r1 p1 r2 w2 p3 c3 p2 c1 c2 check
+permutation w3 r1 p1 r2 w2 p3 c3 p2 c2 c1 check
+permutation w3 r1 p1 r2 w2 p3 c3 c1 p2 c2 check
+permutation w3 r1 p1 r2 p3 w2 p2 c3 c1 c2 check
+permutation w3 r1 p1 r2 p3 w2 p2 c3 c2 c1 check
+permutation w3 r1 p1 r2 p3 w2 c3 p2 c1 c2 check
+permutation w3 r1 p1 r2 p3 w2 c3 p2 c2 c1 check
+permutation w3 r1 p1 r2 p3 w2 c3 c1 p2 c2 check
+permutation w3 r1 p1 r2 p3 c3 w2 p2 c1 c2 check
+permutation w3 r1 p1 r2 p3 c3 w2 p2 c2 c1 check
+permutation w3 r1 p1 r2 p3 c3 w2 c1 p2 c2 check
+permutation w3 r1 p1 r2 p3 c3 c1 w2 p2 c2 check
+permutation w3 r1 p1 w2 r2 p2 p3 c3 c1 c2 check
+permutation w3 r1 p1 w2 r2 p2 p3 c3 c2 c1 check
+permutation w3 r1 p1 w2 r2 p3 p2 c3 c1 c2 check
+permutation w3 r1 p1 w2 r2 p3 p2 c3 c2 c1 check
+permutation w3 r1 p1 w2 r2 p3 c3 p2 c1 c2 check
+permutation w3 r1 p1 w2 r2 p3 c3 p2 c2 c1 check
+permutation w3 r1 p1 w2 r2 p3 c3 c1 p2 c2 check
+permutation w3 r1 p1 w2 p3 r2 p2 c3 c1 c2 check
+permutation w3 r1 p1 w2 p3 r2 p2 c3 c2 c1 check
+permutation w3 r1 p1 w2 p3 r2 c3 p2 c1 c2 check
+permutation w3 r1 p1 w2 p3 r2 c3 p2 c2 c1 check
+permutation w3 r1 p1 w2 p3 r2 c3 c1 p2 c2 check
+permutation w3 r1 p1 w2 p3 c3 r2 p2 c1 c2 check
+permutation w3 r1 p1 w2 p3 c3 r2 p2 c2 c1 check
+permutation w3 r1 p1 w2 p3 c3 r2 c1 p2 c2 check
+permutation w3 r1 p1 w2 p3 c3 c1 r2 p2 c2 check
+permutation w3 r1 p1 p3 r2 w2 p2 c3 c1 c2 check
+permutation w3 r1 p1 p3 r2 w2 p2 c3 c2 c1 check
+permutation w3 r1 p1 p3 r2 w2 c3 p2 c1 c2 check
+permutation w3 r1 p1 p3 r2 w2 c3 p2 c2 c1 check
+permutation w3 r1 p1 p3 r2 w2 c3 c1 p2 c2 check
+permutation w3 r1 p1 p3 r2 c3 w2 p2 c1 c2 check
+permutation w3 r1 p1 p3 r2 c3 w2 p2 c2 c1 check
+permutation w3 r1 p1 p3 r2 c3 w2 c1 p2 c2 check
+permutation w3 r1 p1 p3 r2 c3 c1 w2 p2 c2 check
+permutation w3 r1 p1 p3 w2 r2 p2 c3 c1 c2 check
+permutation w3 r1 p1 p3 w2 r2 p2 c3 c2 c1 check
+permutation w3 r1 p1 p3 w2 r2 c3 p2 c1 c2 check
+permutation w3 r1 p1 p3 w2 r2 c3 p2 c2 c1 check
+permutation w3 r1 p1 p3 w2 r2 c3 c1 p2 c2 check
+permutation w3 r1 p1 p3 w2 c3 r2 p2 c1 c2 check
+permutation w3 r1 p1 p3 w2 c3 r2 p2 c2 c1 check
+permutation w3 r1 p1 p3 w2 c3 r2 c1 p2 c2 check
+permutation w3 r1 p1 p3 w2 c3 c1 r2 p2 c2 check
+permutation w3 r1 p1 p3 c3 r2 w2 p2 c1 c2 check
+permutation w3 r1 p1 p3 c3 r2 w2 p2 c2 c1 check
+permutation w3 r1 p1 p3 c3 r2 w2 c1 p2 c2 check
+permutation w3 r1 p1 p3 c3 r2 c1 w2 p2 c2 check
+permutation w3 r1 p1 p3 c3 w2 r2 p2 c1 c2 check
+permutation w3 r1 p1 p3 c3 w2 r2 p2 c2 c1 check
+permutation w3 r1 p1 p3 c3 w2 r2 c1 p2 c2 check
+permutation w3 r1 p1 p3 c3 w2 c1 r2 p2 c2 check
+permutation w3 r1 p1 p3 c3 c1 r2 w2 p2 c2 check
+permutation w3 r1 p1 p3 c3 c1 w2 r2 p2 c2 check
+permutation w3 r1 p3 r2 w2 p1 p2 c3 c1 c2 check
+permutation w3 r1 p3 r2 w2 p1 p2 c3 c2 c1 check
+permutation w3 r1 p3 r2 w2 p1 c3 p2 c1 c2 check
+permutation w3 r1 p3 r2 w2 p1 c3 p2 c2 c1 check
+permutation w3 r1 p3 r2 w2 p1 c3 c1 p2 c2 check
+permutation w3 r1 p3 r2 w2 p2 p1 c3 c1 c2 check
+permutation w3 r1 p3 r2 w2 p2 p1 c3 c2 c1 check
+permutation w3 r1 p3 r2 w2 p2 c3 p1 c1 c2 check
+permutation w3 r1 p3 r2 w2 p2 c3 p1 c2 c1 check
+permutation w3 r1 p3 r2 w2 p2 c3 c2 p1 c1 check
+permutation w3 r1 p3 r2 w2 c3 p1 p2 c1 c2 check
+permutation w3 r1 p3 r2 w2 c3 p1 p2 c2 c1 check
+permutation w3 r1 p3 r2 w2 c3 p1 c1 p2 c2 check
+permutation w3 r1 p3 r2 w2 c3 p2 p1 c1 c2 check
+permutation w3 r1 p3 r2 w2 c3 p2 p1 c2 c1 check
+permutation w3 r1 p3 r2 w2 c3 p2 c2 p1 c1 check
+permutation w3 r1 p3 r2 p1 w2 p2 c3 c1 c2 check
+permutation w3 r1 p3 r2 p1 w2 p2 c3 c2 c1 check
+permutation w3 r1 p3 r2 p1 w2 c3 p2 c1 c2 check
+permutation w3 r1 p3 r2 p1 w2 c3 p2 c2 c1 check
+permutation w3 r1 p3 r2 p1 w2 c3 c1 p2 c2 check
+permutation w3 r1 p3 r2 p1 c3 w2 p2 c1 c2 check
+permutation w3 r1 p3 r2 p1 c3 w2 p2 c2 c1 check
+permutation w3 r1 p3 r2 p1 c3 w2 c1 p2 c2 check
+permutation w3 r1 p3 r2 p1 c3 c1 w2 p2 c2 check
+permutation w3 r1 p3 r2 c3 w2 p1 p2 c1 c2 check
+permutation w3 r1 p3 r2 c3 w2 p1 p2 c2 c1 check
+permutation w3 r1 p3 r2 c3 w2 p1 c1 p2 c2 check
+permutation w3 r1 p3 r2 c3 w2 p2 p1 c1 c2 check
+permutation w3 r1 p3 r2 c3 w2 p2 p1 c2 c1 check
+permutation w3 r1 p3 r2 c3 w2 p2 c2 p1 c1 check
+permutation w3 r1 p3 r2 c3 p1 w2 p2 c1 c2 check
+permutation w3 r1 p3 r2 c3 p1 w2 p2 c2 c1 check
+permutation w3 r1 p3 r2 c3 p1 w2 c1 p2 c2 check
+permutation w3 r1 p3 r2 c3 p1 c1 w2 p2 c2 check
+permutation w3 r1 p3 w2 r2 p1 p2 c3 c1 c2 check
+permutation w3 r1 p3 w2 r2 p1 p2 c3 c2 c1 check
+permutation w3 r1 p3 w2 r2 p1 c3 p2 c1 c2 check
+permutation w3 r1 p3 w2 r2 p1 c3 p2 c2 c1 check
+permutation w3 r1 p3 w2 r2 p1 c3 c1 p2 c2 check
+permutation w3 r1 p3 w2 r2 p2 p1 c3 c1 c2 check
+permutation w3 r1 p3 w2 r2 p2 p1 c3 c2 c1 check
+permutation w3 r1 p3 w2 r2 p2 c3 p1 c1 c2 check
+permutation w3 r1 p3 w2 r2 p2 c3 p1 c2 c1 check
+permutation w3 r1 p3 w2 r2 p2 c3 c2 p1 c1 check
+permutation w3 r1 p3 w2 r2 c3 p1 p2 c1 c2 check
+permutation w3 r1 p3 w2 r2 c3 p1 p2 c2 c1 check
+permutation w3 r1 p3 w2 r2 c3 p1 c1 p2 c2 check
+permutation w3 r1 p3 w2 r2 c3 p2 p1 c1 c2 check
+permutation w3 r1 p3 w2 r2 c3 p2 p1 c2 c1 check
+permutation w3 r1 p3 w2 r2 c3 p2 c2 p1 c1 check
+permutation w3 r1 p3 w2 p1 r2 p2 c3 c1 c2 check
+permutation w3 r1 p3 w2 p1 r2 p2 c3 c2 c1 check
+permutation w3 r1 p3 w2 p1 r2 c3 p2 c1 c2 check
+permutation w3 r1 p3 w2 p1 r2 c3 p2 c2 c1 check
+permutation w3 r1 p3 w2 p1 r2 c3 c1 p2 c2 check
+permutation w3 r1 p3 w2 p1 c3 r2 p2 c1 c2 check
+permutation w3 r1 p3 w2 p1 c3 r2 p2 c2 c1 check
+permutation w3 r1 p3 w2 p1 c3 r2 c1 p2 c2 check
+permutation w3 r1 p3 w2 p1 c3 c1 r2 p2 c2 check
+permutation w3 r1 p3 w2 c3 r2 p1 p2 c1 c2 check
+permutation w3 r1 p3 w2 c3 r2 p1 p2 c2 c1 check
+permutation w3 r1 p3 w2 c3 r2 p1 c1 p2 c2 check
+permutation w3 r1 p3 w2 c3 r2 p2 p1 c1 c2 check
+permutation w3 r1 p3 w2 c3 r2 p2 p1 c2 c1 check
+permutation w3 r1 p3 w2 c3 r2 p2 c2 p1 c1 check
+permutation w3 r1 p3 w2 c3 p1 r2 p2 c1 c2 check
+permutation w3 r1 p3 w2 c3 p1 r2 p2 c2 c1 check
+permutation w3 r1 p3 w2 c3 p1 r2 c1 p2 c2 check
+permutation w3 r1 p3 w2 c3 p1 c1 r2 p2 c2 check
+permutation w3 r1 p3 p1 r2 w2 p2 c3 c1 c2 check
+permutation w3 r1 p3 p1 r2 w2 p2 c3 c2 c1 check
+permutation w3 r1 p3 p1 r2 w2 c3 p2 c1 c2 check
+permutation w3 r1 p3 p1 r2 w2 c3 p2 c2 c1 check
+permutation w3 r1 p3 p1 r2 w2 c3 c1 p2 c2 check
+permutation w3 r1 p3 p1 r2 c3 w2 p2 c1 c2 check
+permutation w3 r1 p3 p1 r2 c3 w2 p2 c2 c1 check
+permutation w3 r1 p3 p1 r2 c3 w2 c1 p2 c2 check
+permutation w3 r1 p3 p1 r2 c3 c1 w2 p2 c2 check
+permutation w3 r1 p3 p1 w2 r2 p2 c3 c1 c2 check
+permutation w3 r1 p3 p1 w2 r2 p2 c3 c2 c1 check
+permutation w3 r1 p3 p1 w2 r2 c3 p2 c1 c2 check
+permutation w3 r1 p3 p1 w2 r2 c3 p2 c2 c1 check
+permutation w3 r1 p3 p1 w2 r2 c3 c1 p2 c2 check
+permutation w3 r1 p3 p1 w2 c3 r2 p2 c1 c2 check
+permutation w3 r1 p3 p1 w2 c3 r2 p2 c2 c1 check
+permutation w3 r1 p3 p1 w2 c3 r2 c1 p2 c2 check
+permutation w3 r1 p3 p1 w2 c3 c1 r2 p2 c2 check
+permutation w3 r1 p3 p1 c3 r2 w2 p2 c1 c2 check
+permutation w3 r1 p3 p1 c3 r2 w2 p2 c2 c1 check
+permutation w3 r1 p3 p1 c3 r2 w2 c1 p2 c2 check
+permutation w3 r1 p3 p1 c3 r2 c1 w2 p2 c2 check
+permutation w3 r1 p3 p1 c3 w2 r2 p2 c1 c2 check
+permutation w3 r1 p3 p1 c3 w2 r2 p2 c2 c1 check
+permutation w3 r1 p3 p1 c3 w2 r2 c1 p2 c2 check
+permutation w3 r1 p3 p1 c3 w2 c1 r2 p2 c2 check
+permutation w3 r1 p3 p1 c3 c1 r2 w2 p2 c2 check
+permutation w3 r1 p3 p1 c3 c1 w2 r2 p2 c2 check
+permutation w3 r1 p3 c3 r2 w2 p1 p2 c1 c2 check
+permutation w3 r1 p3 c3 r2 w2 p1 p2 c2 c1 check
+permutation w3 r1 p3 c3 r2 w2 p1 c1 p2 c2 check
+permutation w3 r1 p3 c3 r2 w2 p2 p1 c1 c2 check
+permutation w3 r1 p3 c3 r2 w2 p2 p1 c2 c1 check
+permutation w3 r1 p3 c3 r2 w2 p2 c2 p1 c1 check
+permutation w3 r1 p3 c3 r2 p1 w2 p2 c1 c2 check
+permutation w3 r1 p3 c3 r2 p1 w2 p2 c2 c1 check
+permutation w3 r1 p3 c3 r2 p1 w2 c1 p2 c2 check
+permutation w3 r1 p3 c3 r2 p1 c1 w2 p2 c2 check
+permutation w3 r1 p3 c3 w2 r2 p1 p2 c1 c2 check
+permutation w3 r1 p3 c3 w2 r2 p1 p2 c2 c1 check
+permutation w3 r1 p3 c3 w2 r2 p1 c1 p2 c2 check
+permutation w3 r1 p3 c3 w2 r2 p2 p1 c1 c2 check
+permutation w3 r1 p3 c3 w2 r2 p2 p1 c2 c1 check
+permutation w3 r1 p3 c3 w2 r2 p2 c2 p1 c1 check
+permutation w3 r1 p3 c3 w2 p1 r2 p2 c1 c2 check
+permutation w3 r1 p3 c3 w2 p1 r2 p2 c2 c1 check
+permutation w3 r1 p3 c3 w2 p1 r2 c1 p2 c2 check
+permutation w3 r1 p3 c3 w2 p1 c1 r2 p2 c2 check
+permutation w3 r1 p3 c3 p1 r2 w2 p2 c1 c2 check
+permutation w3 r1 p3 c3 p1 r2 w2 p2 c2 c1 check
+permutation w3 r1 p3 c3 p1 r2 w2 c1 p2 c2 check
+permutation w3 r1 p3 c3 p1 r2 c1 w2 p2 c2 check
+permutation w3 r1 p3 c3 p1 w2 r2 p2 c1 c2 check
+permutation w3 r1 p3 c3 p1 w2 r2 p2 c2 c1 check
+permutation w3 r1 p3 c3 p1 w2 r2 c1 p2 c2 check
+permutation w3 r1 p3 c3 p1 w2 c1 r2 p2 c2 check
+permutation w3 r1 p3 c3 p1 c1 r2 w2 p2 c2 check
+permutation w3 r1 p3 c3 p1 c1 w2 r2 p2 c2 check
+permutation w3 r2 r1 w2 p1 p2 p3 c3 c1 c2 check
+permutation w3 r2 r1 w2 p1 p2 p3 c3 c2 c1 check
+permutation w3 r2 r1 w2 p1 p3 p2 c3 c1 c2 check
+permutation w3 r2 r1 w2 p1 p3 p2 c3 c2 c1 check
+permutation w3 r2 r1 w2 p1 p3 c3 p2 c1 c2 check
+permutation w3 r2 r1 w2 p1 p3 c3 p2 c2 c1 check
+permutation w3 r2 r1 w2 p1 p3 c3 c1 p2 c2 check
+permutation w3 r2 r1 w2 p2 p1 p3 c3 c1 c2 check
+permutation w3 r2 r1 w2 p2 p1 p3 c3 c2 c1 check
+permutation w3 r2 r1 w2 p2 p3 p1 c3 c1 c2 check
+permutation w3 r2 r1 w2 p2 p3 p1 c3 c2 c1 check
+permutation w3 r2 r1 w2 p2 p3 c3 p1 c1 c2 check
+permutation w3 r2 r1 w2 p2 p3 c3 p1 c2 c1 check
+permutation w3 r2 r1 w2 p2 p3 c3 c2 p1 c1 check
+permutation w3 r2 r1 w2 p3 p1 p2 c3 c1 c2 check
+permutation w3 r2 r1 w2 p3 p1 p2 c3 c2 c1 check
+permutation w3 r2 r1 w2 p3 p1 c3 p2 c1 c2 check
+permutation w3 r2 r1 w2 p3 p1 c3 p2 c2 c1 check
+permutation w3 r2 r1 w2 p3 p1 c3 c1 p2 c2 check
+permutation w3 r2 r1 w2 p3 p2 p1 c3 c1 c2 check
+permutation w3 r2 r1 w2 p3 p2 p1 c3 c2 c1 check
+permutation w3 r2 r1 w2 p3 p2 c3 p1 c1 c2 check
+permutation w3 r2 r1 w2 p3 p2 c3 p1 c2 c1 check
+permutation w3 r2 r1 w2 p3 p2 c3 c2 p1 c1 check
+permutation w3 r2 r1 w2 p3 c3 p1 p2 c1 c2 check
+permutation w3 r2 r1 w2 p3 c3 p1 p2 c2 c1 check
+permutation w3 r2 r1 w2 p3 c3 p1 c1 p2 c2 check
+permutation w3 r2 r1 w2 p3 c3 p2 p1 c1 c2 check
+permutation w3 r2 r1 w2 p3 c3 p2 p1 c2 c1 check
+permutation w3 r2 r1 w2 p3 c3 p2 c2 p1 c1 check
+permutation w3 r2 r1 p1 w2 p2 p3 c3 c1 c2 check
+permutation w3 r2 r1 p1 w2 p2 p3 c3 c2 c1 check
+permutation w3 r2 r1 p1 w2 p3 p2 c3 c1 c2 check
+permutation w3 r2 r1 p1 w2 p3 p2 c3 c2 c1 check
+permutation w3 r2 r1 p1 w2 p3 c3 p2 c1 c2 check
+permutation w3 r2 r1 p1 w2 p3 c3 p2 c2 c1 check
+permutation w3 r2 r1 p1 w2 p3 c3 c1 p2 c2 check
+permutation w3 r2 r1 p1 p3 w2 p2 c3 c1 c2 check
+permutation w3 r2 r1 p1 p3 w2 p2 c3 c2 c1 check
+permutation w3 r2 r1 p1 p3 w2 c3 p2 c1 c2 check
+permutation w3 r2 r1 p1 p3 w2 c3 p2 c2 c1 check
+permutation w3 r2 r1 p1 p3 w2 c3 c1 p2 c2 check
+permutation w3 r2 r1 p1 p3 c3 w2 p2 c1 c2 check
+permutation w3 r2 r1 p1 p3 c3 w2 p2 c2 c1 check
+permutation w3 r2 r1 p1 p3 c3 w2 c1 p2 c2 check
+permutation w3 r2 r1 p1 p3 c3 c1 w2 p2 c2 check
+permutation w3 r2 r1 p3 w2 p1 p2 c3 c1 c2 check
+permutation w3 r2 r1 p3 w2 p1 p2 c3 c2 c1 check
+permutation w3 r2 r1 p3 w2 p1 c3 p2 c1 c2 check
+permutation w3 r2 r1 p3 w2 p1 c3 p2 c2 c1 check
+permutation w3 r2 r1 p3 w2 p1 c3 c1 p2 c2 check
+permutation w3 r2 r1 p3 w2 p2 p1 c3 c1 c2 check
+permutation w3 r2 r1 p3 w2 p2 p1 c3 c2 c1 check
+permutation w3 r2 r1 p3 w2 p2 c3 p1 c1 c2 check
+permutation w3 r2 r1 p3 w2 p2 c3 p1 c2 c1 check
+permutation w3 r2 r1 p3 w2 p2 c3 c2 p1 c1 check
+permutation w3 r2 r1 p3 w2 c3 p1 p2 c1 c2 check
+permutation w3 r2 r1 p3 w2 c3 p1 p2 c2 c1 check
+permutation w3 r2 r1 p3 w2 c3 p1 c1 p2 c2 check
+permutation w3 r2 r1 p3 w2 c3 p2 p1 c1 c2 check
+permutation w3 r2 r1 p3 w2 c3 p2 p1 c2 c1 check
+permutation w3 r2 r1 p3 w2 c3 p2 c2 p1 c1 check
+permutation w3 r2 r1 p3 p1 w2 p2 c3 c1 c2 check
+permutation w3 r2 r1 p3 p1 w2 p2 c3 c2 c1 check
+permutation w3 r2 r1 p3 p1 w2 c3 p2 c1 c2 check
+permutation w3 r2 r1 p3 p1 w2 c3 p2 c2 c1 check
+permutation w3 r2 r1 p3 p1 w2 c3 c1 p2 c2 check
+permutation w3 r2 r1 p3 p1 c3 w2 p2 c1 c2 check
+permutation w3 r2 r1 p3 p1 c3 w2 p2 c2 c1 check
+permutation w3 r2 r1 p3 p1 c3 w2 c1 p2 c2 check
+permutation w3 r2 r1 p3 p1 c3 c1 w2 p2 c2 check
+permutation w3 r2 r1 p3 c3 w2 p1 p2 c1 c2 check
+permutation w3 r2 r1 p3 c3 w2 p1 p2 c2 c1 check
+permutation w3 r2 r1 p3 c3 w2 p1 c1 p2 c2 check
+permutation w3 r2 r1 p3 c3 w2 p2 p1 c1 c2 check
+permutation w3 r2 r1 p3 c3 w2 p2 p1 c2 c1 check
+permutation w3 r2 r1 p3 c3 w2 p2 c2 p1 c1 check
+permutation w3 r2 r1 p3 c3 p1 w2 p2 c1 c2 check
+permutation w3 r2 r1 p3 c3 p1 w2 p2 c2 c1 check
+permutation w3 r2 r1 p3 c3 p1 w2 c1 p2 c2 check
+permutation w3 r2 r1 p3 c3 p1 c1 w2 p2 c2 check
+permutation w3 r2 p3 r1 w2 p1 p2 c3 c1 c2 check
+permutation w3 r2 p3 r1 w2 p1 p2 c3 c2 c1 check
+permutation w3 r2 p3 r1 w2 p1 c3 p2 c1 c2 check
+permutation w3 r2 p3 r1 w2 p1 c3 p2 c2 c1 check
+permutation w3 r2 p3 r1 w2 p1 c3 c1 p2 c2 check
+permutation w3 r2 p3 r1 w2 p2 p1 c3 c1 c2 check
+permutation w3 r2 p3 r1 w2 p2 p1 c3 c2 c1 check
+permutation w3 r2 p3 r1 w2 p2 c3 p1 c1 c2 check
+permutation w3 r2 p3 r1 w2 p2 c3 p1 c2 c1 check
+permutation w3 r2 p3 r1 w2 p2 c3 c2 p1 c1 check
+permutation w3 r2 p3 r1 w2 c3 p1 p2 c1 c2 check
+permutation w3 r2 p3 r1 w2 c3 p1 p2 c2 c1 check
+permutation w3 r2 p3 r1 w2 c3 p1 c1 p2 c2 check
+permutation w3 r2 p3 r1 w2 c3 p2 p1 c1 c2 check
+permutation w3 r2 p3 r1 w2 c3 p2 p1 c2 c1 check
+permutation w3 r2 p3 r1 w2 c3 p2 c2 p1 c1 check
+permutation w3 r2 p3 r1 p1 w2 p2 c3 c1 c2 check
+permutation w3 r2 p3 r1 p1 w2 p2 c3 c2 c1 check
+permutation w3 r2 p3 r1 p1 w2 c3 p2 c1 c2 check
+permutation w3 r2 p3 r1 p1 w2 c3 p2 c2 c1 check
+permutation w3 r2 p3 r1 p1 w2 c3 c1 p2 c2 check
+permutation w3 r2 p3 r1 p1 c3 w2 p2 c1 c2 check
+permutation w3 r2 p3 r1 p1 c3 w2 p2 c2 c1 check
+permutation w3 r2 p3 r1 p1 c3 w2 c1 p2 c2 check
+permutation w3 r2 p3 r1 p1 c3 c1 w2 p2 c2 check
+permutation w3 r2 p3 r1 c3 w2 p1 p2 c1 c2 check
+permutation w3 r2 p3 r1 c3 w2 p1 p2 c2 c1 check
+permutation w3 r2 p3 r1 c3 w2 p1 c1 p2 c2 check
+permutation w3 r2 p3 r1 c3 w2 p2 p1 c1 c2 check
+permutation w3 r2 p3 r1 c3 w2 p2 p1 c2 c1 check
+permutation w3 r2 p3 r1 c3 w2 p2 c2 p1 c1 check
+permutation w3 r2 p3 r1 c3 p1 w2 p2 c1 c2 check
+permutation w3 r2 p3 r1 c3 p1 w2 p2 c2 c1 check
+permutation w3 r2 p3 r1 c3 p1 w2 c1 p2 c2 check
+permutation w3 r2 p3 r1 c3 p1 c1 w2 p2 c2 check
+permutation w3 r2 p3 c3 r1 w2 p1 p2 c1 c2 check
+permutation w3 r2 p3 c3 r1 w2 p1 p2 c2 c1 check
+permutation w3 r2 p3 c3 r1 w2 p1 c1 p2 c2 check
+permutation w3 r2 p3 c3 r1 w2 p2 p1 c1 c2 check
+permutation w3 r2 p3 c3 r1 w2 p2 p1 c2 c1 check
+permutation w3 r2 p3 c3 r1 w2 p2 c2 p1 c1 check
+permutation w3 r2 p3 c3 r1 p1 w2 p2 c1 c2 check
+permutation w3 r2 p3 c3 r1 p1 w2 p2 c2 c1 check
+permutation w3 r2 p3 c3 r1 p1 w2 c1 p2 c2 check
+permutation w3 r2 p3 c3 r1 p1 c1 w2 p2 c2 check
+permutation w3 p3 r1 r2 w2 p1 p2 c3 c1 c2 check
+permutation w3 p3 r1 r2 w2 p1 p2 c3 c2 c1 check
+permutation w3 p3 r1 r2 w2 p1 c3 p2 c1 c2 check
+permutation w3 p3 r1 r2 w2 p1 c3 p2 c2 c1 check
+permutation w3 p3 r1 r2 w2 p1 c3 c1 p2 c2 check
+permutation w3 p3 r1 r2 w2 p2 p1 c3 c1 c2 check
+permutation w3 p3 r1 r2 w2 p2 p1 c3 c2 c1 check
+permutation w3 p3 r1 r2 w2 p2 c3 p1 c1 c2 check
+permutation w3 p3 r1 r2 w2 p2 c3 p1 c2 c1 check
+permutation w3 p3 r1 r2 w2 p2 c3 c2 p1 c1 check
+permutation w3 p3 r1 r2 w2 c3 p1 p2 c1 c2 check
+permutation w3 p3 r1 r2 w2 c3 p1 p2 c2 c1 check
+permutation w3 p3 r1 r2 w2 c3 p1 c1 p2 c2 check
+permutation w3 p3 r1 r2 w2 c3 p2 p1 c1 c2 check
+permutation w3 p3 r1 r2 w2 c3 p2 p1 c2 c1 check
+permutation w3 p3 r1 r2 w2 c3 p2 c2 p1 c1 check
+permutation w3 p3 r1 r2 p1 w2 p2 c3 c1 c2 check
+permutation w3 p3 r1 r2 p1 w2 p2 c3 c2 c1 check
+permutation w3 p3 r1 r2 p1 w2 c3 p2 c1 c2 check
+permutation w3 p3 r1 r2 p1 w2 c3 p2 c2 c1 check
+permutation w3 p3 r1 r2 p1 w2 c3 c1 p2 c2 check
+permutation w3 p3 r1 r2 p1 c3 w2 p2 c1 c2 check
+permutation w3 p3 r1 r2 p1 c3 w2 p2 c2 c1 check
+permutation w3 p3 r1 r2 p1 c3 w2 c1 p2 c2 check
+permutation w3 p3 r1 r2 p1 c3 c1 w2 p2 c2 check
+permutation w3 p3 r1 r2 c3 w2 p1 p2 c1 c2 check
+permutation w3 p3 r1 r2 c3 w2 p1 p2 c2 c1 check
+permutation w3 p3 r1 r2 c3 w2 p1 c1 p2 c2 check
+permutation w3 p3 r1 r2 c3 w2 p2 p1 c1 c2 check
+permutation w3 p3 r1 r2 c3 w2 p2 p1 c2 c1 check
+permutation w3 p3 r1 r2 c3 w2 p2 c2 p1 c1 check
+permutation w3 p3 r1 r2 c3 p1 w2 p2 c1 c2 check
+permutation w3 p3 r1 r2 c3 p1 w2 p2 c2 c1 check
+permutation w3 p3 r1 r2 c3 p1 w2 c1 p2 c2 check
+permutation w3 p3 r1 r2 c3 p1 c1 w2 p2 c2 check
+permutation w3 p3 r1 w2 r2 p1 p2 c3 c1 c2 check
+permutation w3 p3 r1 w2 r2 p1 p2 c3 c2 c1 check
+permutation w3 p3 r1 w2 r2 p1 c3 p2 c1 c2 check
+permutation w3 p3 r1 w2 r2 p1 c3 p2 c2 c1 check
+permutation w3 p3 r1 w2 r2 p1 c3 c1 p2 c2 check
+permutation w3 p3 r1 w2 r2 p2 p1 c3 c1 c2 check
+permutation w3 p3 r1 w2 r2 p2 p1 c3 c2 c1 check
+permutation w3 p3 r1 w2 r2 p2 c3 p1 c1 c2 check
+permutation w3 p3 r1 w2 r2 p2 c3 p1 c2 c1 check
+permutation w3 p3 r1 w2 r2 p2 c3 c2 p1 c1 check
+permutation w3 p3 r1 w2 r2 c3 p1 p2 c1 c2 check
+permutation w3 p3 r1 w2 r2 c3 p1 p2 c2 c1 check
+permutation w3 p3 r1 w2 r2 c3 p1 c1 p2 c2 check
+permutation w3 p3 r1 w2 r2 c3 p2 p1 c1 c2 check
+permutation w3 p3 r1 w2 r2 c3 p2 p1 c2 c1 check
+permutation w3 p3 r1 w2 r2 c3 p2 c2 p1 c1 check
+permutation w3 p3 r1 w2 p1 r2 p2 c3 c1 c2 check
+permutation w3 p3 r1 w2 p1 r2 p2 c3 c2 c1 check
+permutation w3 p3 r1 w2 p1 r2 c3 p2 c1 c2 check
+permutation w3 p3 r1 w2 p1 r2 c3 p2 c2 c1 check
+permutation w3 p3 r1 w2 p1 r2 c3 c1 p2 c2 check
+permutation w3 p3 r1 w2 p1 c3 r2 p2 c1 c2 check
+permutation w3 p3 r1 w2 p1 c3 r2 p2 c2 c1 check
+permutation w3 p3 r1 w2 p1 c3 r2 c1 p2 c2 check
+permutation w3 p3 r1 w2 p1 c3 c1 r2 p2 c2 check
+permutation w3 p3 r1 w2 c3 r2 p1 p2 c1 c2 check
+permutation w3 p3 r1 w2 c3 r2 p1 p2 c2 c1 check
+permutation w3 p3 r1 w2 c3 r2 p1 c1 p2 c2 check
+permutation w3 p3 r1 w2 c3 r2 p2 p1 c1 c2 check
+permutation w3 p3 r1 w2 c3 r2 p2 p1 c2 c1 check
+permutation w3 p3 r1 w2 c3 r2 p2 c2 p1 c1 check
+permutation w3 p3 r1 w2 c3 p1 r2 p2 c1 c2 check
+permutation w3 p3 r1 w2 c3 p1 r2 p2 c2 c1 check
+permutation w3 p3 r1 w2 c3 p1 r2 c1 p2 c2 check
+permutation w3 p3 r1 w2 c3 p1 c1 r2 p2 c2 check
+permutation w3 p3 r1 p1 r2 w2 p2 c3 c1 c2 check
+permutation w3 p3 r1 p1 r2 w2 p2 c3 c2 c1 check
+permutation w3 p3 r1 p1 r2 w2 c3 p2 c1 c2 check
+permutation w3 p3 r1 p1 r2 w2 c3 p2 c2 c1 check
+permutation w3 p3 r1 p1 r2 w2 c3 c1 p2 c2 check
+permutation w3 p3 r1 p1 r2 c3 w2 p2 c1 c2 check
+permutation w3 p3 r1 p1 r2 c3 w2 p2 c2 c1 check
+permutation w3 p3 r1 p1 r2 c3 w2 c1 p2 c2 check
+permutation w3 p3 r1 p1 r2 c3 c1 w2 p2 c2 check
+permutation w3 p3 r1 p1 w2 r2 p2 c3 c1 c2 check
+permutation w3 p3 r1 p1 w2 r2 p2 c3 c2 c1 check
+permutation w3 p3 r1 p1 w2 r2 c3 p2 c1 c2 check
+permutation w3 p3 r1 p1 w2 r2 c3 p2 c2 c1 check
+permutation w3 p3 r1 p1 w2 r2 c3 c1 p2 c2 check
+permutation w3 p3 r1 p1 w2 c3 r2 p2 c1 c2 check
+permutation w3 p3 r1 p1 w2 c3 r2 p2 c2 c1 check
+permutation w3 p3 r1 p1 w2 c3 r2 c1 p2 c2 check
+permutation w3 p3 r1 p1 w2 c3 c1 r2 p2 c2 check
+permutation w3 p3 r1 p1 c3 r2 w2 p2 c1 c2 check
+permutation w3 p3 r1 p1 c3 r2 w2 p2 c2 c1 check
+permutation w3 p3 r1 p1 c3 r2 w2 c1 p2 c2 check
+permutation w3 p3 r1 p1 c3 r2 c1 w2 p2 c2 check
+permutation w3 p3 r1 p1 c3 w2 r2 p2 c1 c2 check
+permutation w3 p3 r1 p1 c3 w2 r2 p2 c2 c1 check
+permutation w3 p3 r1 p1 c3 w2 r2 c1 p2 c2 check
+permutation w3 p3 r1 p1 c3 w2 c1 r2 p2 c2 check
+permutation w3 p3 r1 p1 c3 c1 r2 w2 p2 c2 check
+permutation w3 p3 r1 p1 c3 c1 w2 r2 p2 c2 check
+permutation w3 p3 r1 c3 r2 w2 p1 p2 c1 c2 check
+permutation w3 p3 r1 c3 r2 w2 p1 p2 c2 c1 check
+permutation w3 p3 r1 c3 r2 w2 p1 c1 p2 c2 check
+permutation w3 p3 r1 c3 r2 w2 p2 p1 c1 c2 check
+permutation w3 p3 r1 c3 r2 w2 p2 p1 c2 c1 check
+permutation w3 p3 r1 c3 r2 w2 p2 c2 p1 c1 check
+permutation w3 p3 r1 c3 r2 p1 w2 p2 c1 c2 check
+permutation w3 p3 r1 c3 r2 p1 w2 p2 c2 c1 check
+permutation w3 p3 r1 c3 r2 p1 w2 c1 p2 c2 check
+permutation w3 p3 r1 c3 r2 p1 c1 w2 p2 c2 check
+permutation w3 p3 r1 c3 w2 r2 p1 p2 c1 c2 check
+permutation w3 p3 r1 c3 w2 r2 p1 p2 c2 c1 check
+permutation w3 p3 r1 c3 w2 r2 p1 c1 p2 c2 check
+permutation w3 p3 r1 c3 w2 r2 p2 p1 c1 c2 check
+permutation w3 p3 r1 c3 w2 r2 p2 p1 c2 c1 check
+permutation w3 p3 r1 c3 w2 r2 p2 c2 p1 c1 check
+permutation w3 p3 r1 c3 w2 p1 r2 p2 c1 c2 check
+permutation w3 p3 r1 c3 w2 p1 r2 p2 c2 c1 check
+permutation w3 p3 r1 c3 w2 p1 r2 c1 p2 c2 check
+permutation w3 p3 r1 c3 w2 p1 c1 r2 p2 c2 check
+permutation w3 p3 r1 c3 p1 r2 w2 p2 c1 c2 check
+permutation w3 p3 r1 c3 p1 r2 w2 p2 c2 c1 check
+permutation w3 p3 r1 c3 p1 r2 w2 c1 p2 c2 check
+permutation w3 p3 r1 c3 p1 r2 c1 w2 p2 c2 check
+permutation w3 p3 r1 c3 p1 w2 r2 p2 c1 c2 check
+permutation w3 p3 r1 c3 p1 w2 r2 p2 c2 c1 check
+permutation w3 p3 r1 c3 p1 w2 r2 c1 p2 c2 check
+permutation w3 p3 r1 c3 p1 w2 c1 r2 p2 c2 check
+permutation w3 p3 r1 c3 p1 c1 r2 w2 p2 c2 check
+permutation w3 p3 r1 c3 p1 c1 w2 r2 p2 c2 check
+permutation w3 p3 r2 r1 w2 p1 p2 c3 c1 c2 check
+permutation w3 p3 r2 r1 w2 p1 p2 c3 c2 c1 check
+permutation w3 p3 r2 r1 w2 p1 c3 p2 c1 c2 check
+permutation w3 p3 r2 r1 w2 p1 c3 p2 c2 c1 check
+permutation w3 p3 r2 r1 w2 p1 c3 c1 p2 c2 check
+permutation w3 p3 r2 r1 w2 p2 p1 c3 c1 c2 check
+permutation w3 p3 r2 r1 w2 p2 p1 c3 c2 c1 check
+permutation w3 p3 r2 r1 w2 p2 c3 p1 c1 c2 check
+permutation w3 p3 r2 r1 w2 p2 c3 p1 c2 c1 check
+permutation w3 p3 r2 r1 w2 p2 c3 c2 p1 c1 check
+permutation w3 p3 r2 r1 w2 c3 p1 p2 c1 c2 check
+permutation w3 p3 r2 r1 w2 c3 p1 p2 c2 c1 check
+permutation w3 p3 r2 r1 w2 c3 p1 c1 p2 c2 check
+permutation w3 p3 r2 r1 w2 c3 p2 p1 c1 c2 check
+permutation w3 p3 r2 r1 w2 c3 p2 p1 c2 c1 check
+permutation w3 p3 r2 r1 w2 c3 p2 c2 p1 c1 check
+permutation w3 p3 r2 r1 p1 w2 p2 c3 c1 c2 check
+permutation w3 p3 r2 r1 p1 w2 p2 c3 c2 c1 check
+permutation w3 p3 r2 r1 p1 w2 c3 p2 c1 c2 check
+permutation w3 p3 r2 r1 p1 w2 c3 p2 c2 c1 check
+permutation w3 p3 r2 r1 p1 w2 c3 c1 p2 c2 check
+permutation w3 p3 r2 r1 p1 c3 w2 p2 c1 c2 check
+permutation w3 p3 r2 r1 p1 c3 w2 p2 c2 c1 check
+permutation w3 p3 r2 r1 p1 c3 w2 c1 p2 c2 check
+permutation w3 p3 r2 r1 p1 c3 c1 w2 p2 c2 check
+permutation w3 p3 r2 r1 c3 w2 p1 p2 c1 c2 check
+permutation w3 p3 r2 r1 c3 w2 p1 p2 c2 c1 check
+permutation w3 p3 r2 r1 c3 w2 p1 c1 p2 c2 check
+permutation w3 p3 r2 r1 c3 w2 p2 p1 c1 c2 check
+permutation w3 p3 r2 r1 c3 w2 p2 p1 c2 c1 check
+permutation w3 p3 r2 r1 c3 w2 p2 c2 p1 c1 check
+permutation w3 p3 r2 r1 c3 p1 w2 p2 c1 c2 check
+permutation w3 p3 r2 r1 c3 p1 w2 p2 c2 c1 check
+permutation w3 p3 r2 r1 c3 p1 w2 c1 p2 c2 check
+permutation w3 p3 r2 r1 c3 p1 c1 w2 p2 c2 check
+permutation w3 p3 r2 c3 r1 w2 p1 p2 c1 c2 check
+permutation w3 p3 r2 c3 r1 w2 p1 p2 c2 c1 check
+permutation w3 p3 r2 c3 r1 w2 p1 c1 p2 c2 check
+permutation w3 p3 r2 c3 r1 w2 p2 p1 c1 c2 check
+permutation w3 p3 r2 c3 r1 w2 p2 p1 c2 c1 check
+permutation w3 p3 r2 c3 r1 w2 p2 c2 p1 c1 check
+permutation w3 p3 r2 c3 r1 p1 w2 p2 c1 c2 check
+permutation w3 p3 r2 c3 r1 p1 w2 p2 c2 c1 check
+permutation w3 p3 r2 c3 r1 p1 w2 c1 p2 c2 check
+permutation w3 p3 r2 c3 r1 p1 c1 w2 p2 c2 check
+permutation w3 p3 c3 r1 r2 w2 p1 p2 c1 c2 check
+permutation w3 p3 c3 r1 r2 w2 p1 p2 c2 c1 check
+permutation w3 p3 c3 r1 r2 w2 p1 c1 p2 c2 check
+permutation w3 p3 c3 r1 r2 w2 p2 p1 c1 c2 check
+permutation w3 p3 c3 r1 r2 w2 p2 p1 c2 c1 check
+permutation w3 p3 c3 r1 r2 w2 p2 c2 p1 c1 check
+permutation w3 p3 c3 r1 r2 p1 w2 p2 c1 c2 check
+permutation w3 p3 c3 r1 r2 p1 w2 p2 c2 c1 check
+permutation w3 p3 c3 r1 r2 p1 w2 c1 p2 c2 check
+permutation w3 p3 c3 r1 r2 p1 c1 w2 p2 c2 check
+permutation w3 p3 c3 r1 w2 r2 p1 p2 c1 c2 check
+permutation w3 p3 c3 r1 w2 r2 p1 p2 c2 c1 check
+permutation w3 p3 c3 r1 w2 r2 p1 c1 p2 c2 check
+permutation w3 p3 c3 r1 w2 r2 p2 p1 c1 c2 check
+permutation w3 p3 c3 r1 w2 r2 p2 p1 c2 c1 check
+permutation w3 p3 c3 r1 w2 r2 p2 c2 p1 c1 check
+permutation w3 p3 c3 r1 w2 p1 r2 p2 c1 c2 check
+permutation w3 p3 c3 r1 w2 p1 r2 p2 c2 c1 check
+permutation w3 p3 c3 r1 w2 p1 r2 c1 p2 c2 check
+permutation w3 p3 c3 r1 w2 p1 c1 r2 p2 c2 check
+permutation w3 p3 c3 r1 p1 r2 w2 p2 c1 c2 check
+permutation w3 p3 c3 r1 p1 r2 w2 p2 c2 c1 check
+permutation w3 p3 c3 r1 p1 r2 w2 c1 p2 c2 check
+permutation w3 p3 c3 r1 p1 r2 c1 w2 p2 c2 check
+permutation w3 p3 c3 r1 p1 w2 r2 p2 c1 c2 check
+permutation w3 p3 c3 r1 p1 w2 r2 p2 c2 c1 check
+permutation w3 p3 c3 r1 p1 w2 r2 c1 p2 c2 check
+permutation w3 p3 c3 r1 p1 w2 c1 r2 p2 c2 check
+permutation w3 p3 c3 r1 p1 c1 r2 w2 p2 c2 check
+permutation w3 p3 c3 r1 p1 c1 w2 r2 p2 c2 check
+permutation w3 p3 c3 r2 r1 w2 p1 p2 c1 c2 check
+permutation w3 p3 c3 r2 r1 w2 p1 p2 c2 c1 check
+permutation w3 p3 c3 r2 r1 w2 p1 c1 p2 c2 check
+permutation w3 p3 c3 r2 r1 w2 p2 p1 c1 c2 check
+permutation w3 p3 c3 r2 r1 w2 p2 p1 c2 c1 check
+permutation w3 p3 c3 r2 r1 w2 p2 c2 p1 c1 check
+permutation w3 p3 c3 r2 r1 p1 w2 p2 c1 c2 check
+permutation w3 p3 c3 r2 r1 p1 w2 p2 c2 c1 check
+permutation w3 p3 c3 r2 r1 p1 w2 c1 p2 c2 check
+permutation w3 p3 c3 r2 r1 p1 c1 w2 p2 c2 check
diff --git a/src/test/isolation/specs/project-manager.spec b/src/test/isolation/specs/project-manager.spec
new file mode 100644
index 0000000..42e5fc5
--- /dev/null
+++ b/src/test/isolation/specs/project-manager.spec
@@ -0,0 +1,30 @@
+# Project Manager test
+#
+# Ensure that the person who is on the project as a manager
+# is flagged as a project manager in the person table.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE person (person_id int NOT NULL PRIMARY KEY, name text NOT NULL, is_project_manager bool NOT NULL);
+ INSERT INTO person VALUES (1, 'Robert Haas', true);
+ CREATE TABLE project (project_no int NOT NULL PRIMARY KEY, description text NOT NULL, project_manager int NOT NULL);
+}
+
+teardown
+{
+ DROP TABLE person, project;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rx1 { SELECT count(*) FROM person WHERE person_id = 1 AND is_project_manager; }
+step wy1 { INSERT INTO project VALUES (101, 'Build Great Wall', 1); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step ry2 { SELECT count(*) FROM project WHERE project_manager = 1; }
+step wx2 { UPDATE person SET is_project_manager = false WHERE person_id = 1; }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/propagate-lock-delete.spec b/src/test/isolation/specs/propagate-lock-delete.spec
new file mode 100644
index 0000000..641fb84
--- /dev/null
+++ b/src/test/isolation/specs/propagate-lock-delete.spec
@@ -0,0 +1,42 @@
+# When an update propagates a preexisting lock on the updated tuple, make sure
+# we don't ignore the lock in subsequent operations of the new version. (The
+# version with the aborted savepoint uses a slightly different code path).
+setup
+{
+ create table parent (i int, c char(3));
+ create unique index parent_idx on parent (i);
+ insert into parent values (1, 'AAA');
+ create table child (i int references parent(i));
+}
+
+teardown
+{
+ drop table child, parent;
+}
+
+session s1
+step s1b { BEGIN; }
+step s1l { INSERT INTO child VALUES (1); }
+step s1c { COMMIT; }
+
+session s2
+step s2b { BEGIN; }
+step s2l { INSERT INTO child VALUES (1); }
+step s2c { COMMIT; }
+
+session s3
+step s3b { BEGIN; }
+step s3u { UPDATE parent SET c=lower(c); } # no key update
+step s3u2 { UPDATE parent SET i = i; } # key update
+step s3svu { SAVEPOINT f; UPDATE parent SET c = 'bbb'; ROLLBACK TO f; }
+step s3d { DELETE FROM parent; }
+step s3c { COMMIT; }
+
+permutation s1b s1l s2b s2l s3b s3u s3d s1c s2c s3c
+permutation s1b s1l s2b s2l s3b s3u s3svu s3d s1c s2c s3c
+permutation s1b s1l s2b s2l s3b s3u2 s3d s1c s2c s3c
+permutation s1b s1l s2b s2l s3b s3u2 s3svu s3d s1c s2c s3c
+permutation s1b s1l s3b s3u s3d s1c s3c
+permutation s1b s1l s3b s3u s3svu s3d s1c s3c
+permutation s1b s1l s3b s3u2 s3d s1c s3c
+permutation s1b s1l s3b s3u2 s3svu s3d s1c s3c
diff --git a/src/test/isolation/specs/read-only-anomaly-2.spec b/src/test/isolation/specs/read-only-anomaly-2.spec
new file mode 100644
index 0000000..6b579a6
--- /dev/null
+++ b/src/test/isolation/specs/read-only-anomaly-2.spec
@@ -0,0 +1,42 @@
+# The example from the paper "A read-only transaction anomaly under snapshot
+# isolation"[1].
+#
+# Here we test that serializable snapshot isolation (SERIALIZABLE) doesn't
+# suffer from the anomaly, because s2 is aborted upon detection of a cycle.
+#
+# [1] http://www.cs.umb.edu/~poneil/ROAnom.pdf
+
+setup
+{
+ CREATE TABLE bank_account (id TEXT PRIMARY KEY, balance DECIMAL NOT NULL);
+ INSERT INTO bank_account (id, balance) VALUES ('X', 0), ('Y', 0);
+}
+
+teardown
+{
+ DROP TABLE bank_account;
+}
+
+session s1
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s1ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s1wy { UPDATE bank_account SET balance = 20 WHERE id = 'Y'; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s2rx { SELECT balance FROM bank_account WHERE id = 'X'; }
+step s2ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s2wx { UPDATE bank_account SET balance = -11 WHERE id = 'X'; }
+step s2c { COMMIT; }
+
+session s3
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s3r { SELECT id, balance FROM bank_account WHERE id IN ('X', 'Y') ORDER BY id; }
+step s3c { COMMIT; }
+
+# without s3, s1 and s2 commit
+permutation s2rx s2ry s1ry s1wy s1c s2wx s2c s3c
+
+# once s3 observes the data committed by s1, a cycle is created and s2 aborts
+permutation s2rx s2ry s1ry s1wy s1c s3r s3c s2wx
diff --git a/src/test/isolation/specs/read-only-anomaly-3.spec b/src/test/isolation/specs/read-only-anomaly-3.spec
new file mode 100644
index 0000000..61d9c0b
--- /dev/null
+++ b/src/test/isolation/specs/read-only-anomaly-3.spec
@@ -0,0 +1,39 @@
+# The example from the paper "A read-only transaction anomaly under snapshot
+# isolation"[1].
+#
+# Here we test that serializable snapshot isolation can avoid the anomaly
+# without aborting any transactions, by instead causing s3 to be deferred
+# until a safe snapshot can be taken.
+#
+# [1] http://www.cs.umb.edu/~poneil/ROAnom.pdf
+
+setup
+{
+ CREATE TABLE bank_account (id TEXT PRIMARY KEY, balance DECIMAL NOT NULL);
+ INSERT INTO bank_account (id, balance) VALUES ('X', 0), ('Y', 0);
+}
+
+teardown
+{
+ DROP TABLE bank_account;
+}
+
+session s1
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s1ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s1wy { UPDATE bank_account SET balance = 20 WHERE id = 'Y'; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s2rx { SELECT balance FROM bank_account WHERE id = 'X'; }
+step s2ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s2wx { UPDATE bank_account SET balance = -11 WHERE id = 'X'; }
+step s2c { COMMIT; }
+
+session s3
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE; }
+step s3r { SELECT id, balance FROM bank_account WHERE id IN ('X', 'Y') ORDER BY id; }
+step s3c { COMMIT; }
+
+permutation s2rx s2ry s1ry s1wy s1c s3r s2wx s2c s3c
diff --git a/src/test/isolation/specs/read-only-anomaly.spec b/src/test/isolation/specs/read-only-anomaly.spec
new file mode 100644
index 0000000..8ff1af5
--- /dev/null
+++ b/src/test/isolation/specs/read-only-anomaly.spec
@@ -0,0 +1,38 @@
+# The example from the paper "A read-only transaction anomaly under snapshot
+# isolation"[1].
+#
+# Here we use snapshot isolation (REPEATABLE READ), so that s3 sees a state of
+# afairs that is not consistent with any serial ordering of s1 and s2.
+#
+# [1] http://www.cs.umb.edu/~poneil/ROAnom.pdf
+
+setup
+{
+ CREATE TABLE bank_account (id TEXT PRIMARY KEY, balance DECIMAL NOT NULL);
+ INSERT INTO bank_account (id, balance) VALUES ('X', 0), ('Y', 0);
+}
+
+teardown
+{
+ DROP TABLE bank_account;
+}
+
+session s1
+setup { BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; }
+step s1ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s1wy { UPDATE bank_account SET balance = 20 WHERE id = 'Y'; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; }
+step s2rx { SELECT balance FROM bank_account WHERE id = 'X'; }
+step s2ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s2wx { UPDATE bank_account SET balance = -11 WHERE id = 'X'; }
+step s2c { COMMIT; }
+
+session s3
+setup { BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; }
+step s3r { SELECT id, balance FROM bank_account WHERE id IN ('X', 'Y') ORDER BY id; }
+step s3c { COMMIT; }
+
+permutation s2rx s2ry s1ry s1wy s1c s3r s2wx s2c s3c
diff --git a/src/test/isolation/specs/read-write-unique-2.spec b/src/test/isolation/specs/read-write-unique-2.spec
new file mode 100644
index 0000000..16c73e1
--- /dev/null
+++ b/src/test/isolation/specs/read-write-unique-2.spec
@@ -0,0 +1,36 @@
+# Read-write-unique test.
+
+setup
+{
+ CREATE TABLE test (i integer PRIMARY KEY);
+}
+
+teardown
+{
+ DROP TABLE test;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r1 { SELECT * FROM test WHERE i = 42; }
+step w1 { INSERT INTO test VALUES (42); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r2 { SELECT * FROM test WHERE i = 42; }
+step w2 { INSERT INTO test VALUES (42); }
+step c2 { COMMIT; }
+
+# Two SSI transactions see that there is no row with value 42
+# in the table, then try to insert that value; T1 inserts,
+# and then T2 blocks waiting for T1 to commit. Finally,
+# T2 reports a serialization failure.
+
+permutation r1 r2 w1 w2 c1 c2
+
+# If the value is already visible before T2 begins, then a
+# regular unique constraint violation should still be raised
+# by T2.
+
+permutation r1 w1 c1 r2 w2 c2
diff --git a/src/test/isolation/specs/read-write-unique-3.spec b/src/test/isolation/specs/read-write-unique-3.spec
new file mode 100644
index 0000000..cba2c4c
--- /dev/null
+++ b/src/test/isolation/specs/read-write-unique-3.spec
@@ -0,0 +1,33 @@
+# Read-write-unique test.
+# From bug report 9301.
+
+setup
+{
+ CREATE TABLE test (
+ key integer UNIQUE,
+ val text
+ );
+
+ CREATE OR REPLACE FUNCTION insert_unique(k integer, v text) RETURNS void
+ LANGUAGE SQL AS $$
+ INSERT INTO test (key, val) SELECT k, v WHERE NOT EXISTS (SELECT key FROM test WHERE key = k);
+ $$;
+}
+
+teardown
+{
+ DROP FUNCTION insert_unique(integer, text);
+ DROP TABLE test;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rw1 { SELECT insert_unique(1, '1'); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rw2 { SELECT insert_unique(1, '2'); }
+step c2 { COMMIT; }
+
+permutation rw1 rw2 c1 c2
diff --git a/src/test/isolation/specs/read-write-unique-4.spec b/src/test/isolation/specs/read-write-unique-4.spec
new file mode 100644
index 0000000..9002248
--- /dev/null
+++ b/src/test/isolation/specs/read-write-unique-4.spec
@@ -0,0 +1,48 @@
+# Read-write-unique test.
+# Implementing a gapless sequence of ID numbers for each year.
+
+setup
+{
+ CREATE TABLE invoice (
+ year int,
+ invoice_number int,
+ PRIMARY KEY (year, invoice_number)
+ );
+
+ INSERT INTO invoice VALUES (2016, 1), (2016, 2);
+}
+
+teardown
+{
+ DROP TABLE invoice;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r1 { SELECT COALESCE(MAX(invoice_number) + 1, 1) FROM invoice WHERE year = 2016; }
+step w1 { INSERT INTO invoice VALUES (2016, 3); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r2 { SELECT COALESCE(MAX(invoice_number) + 1, 1) FROM invoice WHERE year = 2016; }
+step w2 { INSERT INTO invoice VALUES (2016, 3); }
+step c2 { COMMIT; }
+
+# if they both read first then there should be an SSI conflict
+permutation r1 r2 w1 w2 c1 c2
+
+# cases where one session doesn't explicitly read before writing:
+
+# if s2 doesn't explicitly read, then trying to insert the value
+# generates a unique constraint violation after s1 commits, as if s2
+# ran after s1
+permutation r1 w1 w2 c1 c2
+
+# if s1 doesn't explicitly read, but s2 does, then s1 inserts and
+# commits first, should s2 experience an SSI failure instead of a
+# unique constraint violation? there is no serial order of operations
+# (s1, s2) or (s2, s1) where s1 succeeds, and s2 doesn't see the row
+# in an explicit select but then fails to insert due to unique
+# constraint violation
+permutation r2 w1 w2 c1 c2
diff --git a/src/test/isolation/specs/read-write-unique.spec b/src/test/isolation/specs/read-write-unique.spec
new file mode 100644
index 0000000..3ce059f
--- /dev/null
+++ b/src/test/isolation/specs/read-write-unique.spec
@@ -0,0 +1,39 @@
+# Read-write-unique test.
+
+setup
+{
+ CREATE TABLE test (i integer PRIMARY KEY);
+}
+
+teardown
+{
+ DROP TABLE test;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r1 { SELECT * FROM test; }
+step w1 { INSERT INTO test VALUES (42); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r2 { SELECT * FROM test; }
+step w2 { INSERT INTO test VALUES (42); }
+step c2 { COMMIT; }
+
+# Two SSI transactions see that there is no row with value 42
+# in the table, then try to insert that value; T1 inserts,
+# and then T2 blocks waiting for T1 to commit. Finally,
+# T2 reports a serialization failure.
+#
+# (In an earlier version of Postgres, T2 would report a unique
+# constraint violation).
+
+permutation r1 r2 w1 w2 c1 c2
+
+# If the value is already visible before T2 begins, then a
+# regular unique constraint violation should still be raised
+# by T2.
+
+permutation r1 w1 c1 r2 w2 c2
diff --git a/src/test/isolation/specs/receipt-report.spec b/src/test/isolation/specs/receipt-report.spec
new file mode 100644
index 0000000..85ac60f
--- /dev/null
+++ b/src/test/isolation/specs/receipt-report.spec
@@ -0,0 +1,47 @@
+# Daily Report of Receipts test.
+#
+# This test doesn't persist a bad state in the database; rather, it
+# provides a view of the data which is not consistent with any
+# order of execution of the serializable transactions. It
+# demonstrates a situation where the deposit date for receipts could
+# be changed and a report of the closed day's receipts subsequently
+# run which will miss a receipt from the date which has been closed.
+#
+# There are only six permutations which must cause a serialization failure.
+# Failure cases are where s1 overlaps both s2 and s3, but s2 commits before
+# s3 executes its first SELECT.
+#
+# As long as s3 is declared READ ONLY there should be no false positives.
+# If s3 were changed to READ WRITE, we would currently expect 42 false
+# positives. Further work dealing with de facto READ ONLY transactions
+# may be able to reduce or eliminate those false positives.
+
+setup
+{
+ CREATE TABLE ctl (k text NOT NULL PRIMARY KEY, deposit_date date NOT NULL);
+ INSERT INTO ctl VALUES ('receipt', DATE '2008-12-22');
+ CREATE TABLE receipt (receipt_no int NOT NULL PRIMARY KEY, deposit_date date NOT NULL, amount numeric(13,2));
+ INSERT INTO receipt VALUES (1, (SELECT deposit_date FROM ctl WHERE k = 'receipt'), 1.00);
+ INSERT INTO receipt VALUES (2, (SELECT deposit_date FROM ctl WHERE k = 'receipt'), 2.00);
+}
+
+teardown
+{
+ DROP TABLE ctl, receipt;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rxwy1 { INSERT INTO receipt VALUES (3, (SELECT deposit_date FROM ctl WHERE k = 'receipt'), 4.00); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wx2 { UPDATE ctl SET deposit_date = DATE '2008-12-23' WHERE k = 'receipt'; }
+step c2 { COMMIT; }
+
+session s3
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE, READ ONLY; }
+step rx3 { SELECT * FROM ctl WHERE k = 'receipt'; }
+step ry3 { SELECT * FROM receipt WHERE deposit_date = DATE '2008-12-22'; }
+step c3 { COMMIT; }
diff --git a/src/test/isolation/specs/referential-integrity.spec b/src/test/isolation/specs/referential-integrity.spec
new file mode 100644
index 0000000..ecaa9bb
--- /dev/null
+++ b/src/test/isolation/specs/referential-integrity.spec
@@ -0,0 +1,32 @@
+# Referential Integrity test
+#
+# The assumption here is that the application code issuing the SELECT
+# to test for the presence or absence of a related record would do the
+# right thing -- this script doesn't include that logic.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE a (i int PRIMARY KEY);
+ CREATE TABLE b (a_id int);
+ INSERT INTO a VALUES (1);
+}
+
+teardown
+{
+ DROP TABLE a, b;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rx1 { SELECT i FROM a WHERE i = 1; }
+step wy1 { INSERT INTO b VALUES (1); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rx2 { SELECT i FROM a WHERE i = 1; }
+step ry2 { SELECT a_id FROM b WHERE a_id = 1; }
+step wx2 { DELETE FROM a WHERE i = 1; }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/reindex-concurrently.spec b/src/test/isolation/specs/reindex-concurrently.spec
new file mode 100644
index 0000000..31844bd
--- /dev/null
+++ b/src/test/isolation/specs/reindex-concurrently.spec
@@ -0,0 +1,40 @@
+# REINDEX CONCURRENTLY
+#
+# Ensure that concurrent operations work correctly when a REINDEX is performed
+# concurrently.
+
+setup
+{
+ CREATE TABLE reind_con_tab(id serial primary key, data text);
+ INSERT INTO reind_con_tab(data) VALUES ('aa');
+ INSERT INTO reind_con_tab(data) VALUES ('aaa');
+ INSERT INTO reind_con_tab(data) VALUES ('aaaa');
+ INSERT INTO reind_con_tab(data) VALUES ('aaaaa');
+}
+
+teardown
+{
+ DROP TABLE reind_con_tab;
+}
+
+session s1
+setup { BEGIN; }
+step sel1 { SELECT data FROM reind_con_tab WHERE id = 3; }
+step end1 { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step upd2 { UPDATE reind_con_tab SET data = 'bbbb' WHERE id = 3; }
+step ins2 { INSERT INTO reind_con_tab(data) VALUES ('cccc'); }
+step del2 { DELETE FROM reind_con_tab WHERE data = 'cccc'; }
+step end2 { COMMIT; }
+
+session s3
+step reindex { REINDEX TABLE CONCURRENTLY reind_con_tab; }
+
+permutation reindex sel1 upd2 ins2 del2 end1 end2
+permutation sel1 reindex upd2 ins2 del2 end1 end2
+permutation sel1 upd2 reindex ins2 del2 end1 end2
+permutation sel1 upd2 ins2 reindex del2 end1 end2
+permutation sel1 upd2 ins2 del2 reindex end1 end2
+permutation sel1 upd2 ins2 del2 end1 reindex end2
diff --git a/src/test/isolation/specs/ri-trigger.spec b/src/test/isolation/specs/ri-trigger.spec
new file mode 100644
index 0000000..00fcdff
--- /dev/null
+++ b/src/test/isolation/specs/ri-trigger.spec
@@ -0,0 +1,53 @@
+# RI Trigger test
+#
+# Test trigger-based referential integrity enforcement.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE parent (parent_id SERIAL NOT NULL PRIMARY KEY);
+ CREATE TABLE child (child_id SERIAL NOT NULL PRIMARY KEY, parent_id INTEGER NOT NULL);
+ CREATE FUNCTION ri_parent() RETURNS TRIGGER LANGUAGE PLPGSQL AS $body$
+ BEGIN
+ PERFORM TRUE FROM child WHERE parent_id = OLD.parent_id;
+ IF FOUND THEN
+ RAISE SQLSTATE '23503' USING MESSAGE = 'child row exists';
+ END IF;
+ IF TG_OP = 'DELETE' THEN
+ RETURN OLD;
+ END IF;
+ RETURN NEW;
+ END;
+ $body$;
+ CREATE TRIGGER ri_parent BEFORE UPDATE OR DELETE ON parent FOR EACH ROW EXECUTE PROCEDURE ri_parent();
+ CREATE FUNCTION ri_child() RETURNS TRIGGER LANGUAGE PLPGSQL AS $body$
+ BEGIN
+ PERFORM TRUE FROM parent WHERE parent_id = NEW.parent_id;
+ IF NOT FOUND THEN
+ RAISE SQLSTATE '23503' USING MESSAGE = 'parent row missing';
+ END IF;
+ RETURN NEW;
+ END;
+ $body$;
+ CREATE TRIGGER ri_child BEFORE INSERT OR UPDATE ON child FOR EACH ROW EXECUTE PROCEDURE ri_child();
+ INSERT INTO parent VALUES(0);
+}
+
+teardown
+{
+ DROP TABLE parent, child;
+ DROP FUNCTION ri_parent();
+ DROP FUNCTION ri_child();
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wxry1 { INSERT INTO child (parent_id) VALUES (0); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step r2 { SELECT TRUE; }
+step wyrx2 { DELETE FROM parent WHERE parent_id = 0; }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/sequence-ddl.spec b/src/test/isolation/specs/sequence-ddl.spec
new file mode 100644
index 0000000..7ead8af
--- /dev/null
+++ b/src/test/isolation/specs/sequence-ddl.spec
@@ -0,0 +1,41 @@
+# Test sequence usage and concurrent sequence DDL
+
+setup
+{
+ CREATE SEQUENCE seq1;
+}
+
+teardown
+{
+ DROP SEQUENCE seq1;
+}
+
+session s1
+setup { BEGIN; }
+step s1alter { ALTER SEQUENCE seq1 MAXVALUE 10; }
+step s1alter2 { ALTER SEQUENCE seq1 MAXVALUE 20; }
+step s1restart { ALTER SEQUENCE seq1 RESTART WITH 5; }
+step s1commit { COMMIT; }
+
+session s2
+step s2begin { BEGIN; }
+step s2nv { SELECT nextval('seq1') FROM generate_series(1, 15); }
+step s2commit { COMMIT; }
+
+permutation s1alter s1commit s2nv
+
+# Prior to PG10, the s2nv step would see the uncommitted s1alter
+# change, but now it waits.
+permutation s1alter s2nv s1commit
+
+# Prior to PG10, the s2nv step would see the uncommitted s1restart
+# change, but now it waits.
+permutation s1restart s2nv s1commit
+
+# In contrast to ALTER setval() is non-transactional, so it doesn't
+# have to wait.
+permutation s1restart s2nv s1commit
+
+# nextval doesn't release lock until transaction end, so s1alter2 has
+# to wait for s2commit.
+permutation s2begin s2nv s1alter2 s2commit s1commit
diff --git a/src/test/isolation/specs/serializable-parallel-2.spec b/src/test/isolation/specs/serializable-parallel-2.spec
new file mode 100644
index 0000000..f3941f7
--- /dev/null
+++ b/src/test/isolation/specs/serializable-parallel-2.spec
@@ -0,0 +1,30 @@
+# Exercise the case where a read-only serializable transaction has
+# SXACT_FLAG_RO_SAFE set in a parallel query.
+
+setup
+{
+ CREATE TABLE foo AS SELECT generate_series(1, 10)::int a;
+ ALTER TABLE foo SET (parallel_workers = 2);
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s1r { SELECT * FROM foo; }
+step s1c { COMMIT; }
+
+session s2
+setup {
+ BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY;
+ SET parallel_setup_cost = 0;
+ SET parallel_tuple_cost = 0;
+ }
+step s2r1 { SELECT * FROM foo; }
+step s2r2 { SELECT * FROM foo; }
+step s2c { COMMIT; }
+
+permutation s1r s2r1 s1c s2r2 s2c
diff --git a/src/test/isolation/specs/serializable-parallel.spec b/src/test/isolation/specs/serializable-parallel.spec
new file mode 100644
index 0000000..508648e
--- /dev/null
+++ b/src/test/isolation/specs/serializable-parallel.spec
@@ -0,0 +1,47 @@
+# The example from the paper "A read-only transaction anomaly under snapshot
+# isolation"[1].
+#
+# Here we test that serializable snapshot isolation (SERIALIZABLE) doesn't
+# suffer from the anomaly, because s2 is aborted upon detection of a cycle.
+# In this case the read only query s3 happens to be running in a parallel
+# worker.
+#
+# [1] http://www.cs.umb.edu/~poneil/ROAnom.pdf
+
+setup
+{
+ CREATE TABLE bank_account (id TEXT PRIMARY KEY, balance DECIMAL NOT NULL);
+ INSERT INTO bank_account (id, balance) VALUES ('X', 0), ('Y', 0);
+}
+
+teardown
+{
+ DROP TABLE bank_account;
+}
+
+session s1
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s1ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s1wy { UPDATE bank_account SET balance = 20 WHERE id = 'Y'; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step s2rx { SELECT balance FROM bank_account WHERE id = 'X'; }
+step s2ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
+step s2wx { UPDATE bank_account SET balance = -11 WHERE id = 'X'; }
+step s2c { COMMIT; }
+
+session s3
+setup {
+ BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+ SET force_parallel_mode = on;
+ }
+step s3r { SELECT id, balance FROM bank_account WHERE id IN ('X', 'Y') ORDER BY id; }
+step s3c { COMMIT; }
+
+# without s3, s1 and s2 commit
+permutation s2rx s2ry s1ry s1wy s1c s2wx s2c s3c
+
+# once s3 observes the data committed by s1, a cycle is created and s2 aborts
+permutation s2rx s2ry s1ry s1wy s1c s3r s3c s2wx
diff --git a/src/test/isolation/specs/simple-write-skew.spec b/src/test/isolation/specs/simple-write-skew.spec
new file mode 100644
index 0000000..ecabbf1
--- /dev/null
+++ b/src/test/isolation/specs/simple-write-skew.spec
@@ -0,0 +1,30 @@
+# Write skew test.
+#
+# This test has two serializable transactions: one which updates all
+# 'apple' rows to 'pear' and one which updates all 'pear' rows to
+# 'apple'. If these were serialized (run one at a time) either
+# value could be present, but not both. One must be rolled back to
+# prevent the write skew anomaly.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE test (i int PRIMARY KEY, t text);
+ INSERT INTO test VALUES (5, 'apple'), (7, 'pear'), (11, 'banana');
+}
+
+teardown
+{
+ DROP TABLE test;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rwx1 { UPDATE test SET t = 'apple' WHERE t = 'pear'; }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rwx2 { UPDATE test SET t = 'pear' WHERE t = 'apple'}
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/skip-locked-2.spec b/src/test/isolation/specs/skip-locked-2.spec
new file mode 100644
index 0000000..cfdaa93
--- /dev/null
+++ b/src/test/isolation/specs/skip-locked-2.spec
@@ -0,0 +1,41 @@
+# Test SKIP LOCKED with multixact locks.
+
+setup
+{
+ CREATE TABLE queue (
+ id int PRIMARY KEY,
+ data text NOT NULL,
+ status text NOT NULL
+ );
+ INSERT INTO queue VALUES (1, 'foo', 'NEW'), (2, 'bar', 'NEW');
+}
+
+teardown
+{
+ DROP TABLE queue;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM queue ORDER BY id FOR SHARE SKIP LOCKED LIMIT 1; }
+step s1b { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2a { SELECT * FROM queue ORDER BY id FOR SHARE SKIP LOCKED LIMIT 1; }
+step s2b { SELECT * FROM queue ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 1; }
+step s2c { COMMIT; }
+
+# s1 and s2 both get SHARE lock, creating a multixact lock, then s2
+# tries to update to UPDATE but skips the record because it can't
+# acquire a multixact lock
+permutation s1a s2a s2b s1b s2c
+
+# the same but with the SHARE locks acquired in a different order, so
+# s2 again skips because it can't acquired a multixact lock
+permutation s2a s1a s2b s1b s2c
+
+# s2 acquires SHARE then UPDATE, then s1 tries to acquire SHARE but
+# can't so skips the first record because it can't acquire a regular
+# lock
+permutation s2a s2b s1a s1b s2c
diff --git a/src/test/isolation/specs/skip-locked-3.spec b/src/test/isolation/specs/skip-locked-3.spec
new file mode 100644
index 0000000..7921425
--- /dev/null
+++ b/src/test/isolation/specs/skip-locked-3.spec
@@ -0,0 +1,36 @@
+# Test SKIP LOCKED with tuple locks.
+
+setup
+{
+ CREATE TABLE queue (
+ id int PRIMARY KEY,
+ data text NOT NULL,
+ status text NOT NULL
+ );
+ INSERT INTO queue VALUES (1, 'foo', 'NEW'), (2, 'bar', 'NEW');
+}
+
+teardown
+{
+ DROP TABLE queue;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM queue ORDER BY id FOR UPDATE LIMIT 1; }
+step s1b { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2a { SELECT * FROM queue ORDER BY id FOR UPDATE LIMIT 1; }
+step s2b { COMMIT; }
+
+session s3
+setup { BEGIN; }
+step s3a { SELECT * FROM queue ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 1; }
+step s3b { COMMIT; }
+
+# s3 skips to the second record because it can't obtain the tuple lock
+# (s2 holds the tuple lock because it is next in line to obtain the
+# row lock, and s1 holds the row lock)
+permutation s1a s2a s3a s1b s2b s3b
diff --git a/src/test/isolation/specs/skip-locked-4.spec b/src/test/isolation/specs/skip-locked-4.spec
new file mode 100644
index 0000000..02994a3
--- /dev/null
+++ b/src/test/isolation/specs/skip-locked-4.spec
@@ -0,0 +1,36 @@
+# Test SKIP LOCKED with an updated tuple chain.
+
+setup
+{
+ CREATE TABLE foo (
+ id int PRIMARY KEY,
+ data text NOT NULL
+ );
+ INSERT INTO foo VALUES (1, 'x'), (2, 'x');
+}
+
+teardown
+{
+ DROP TABLE foo;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM foo WHERE pg_advisory_lock(0) IS NOT NULL ORDER BY id LIMIT 1 FOR UPDATE SKIP LOCKED; }
+step s1b { COMMIT; }
+
+session s2
+step s2a { SELECT pg_advisory_lock(0); }
+step s2b { UPDATE foo SET data = data WHERE id = 1; }
+step s2c { BEGIN; }
+step s2d { UPDATE foo SET data = data WHERE id = 1; }
+step s2e { SELECT pg_advisory_unlock(0); }
+step s2f { COMMIT; }
+
+# s1 takes a snapshot but then waits on an advisory lock, then s2
+# updates the row in one transaction, then again in another without
+# committing, before allowing s1 to proceed to try to lock a row;
+# because it has a snapshot that sees the older version, we reach the
+# waiting code in EvalPlanQualFetch which skips rows when in SKIP
+# LOCKED mode, so s1 sees the second row
+permutation s2a s1a s2b s2c s2d s2e s1b s2f
diff --git a/src/test/isolation/specs/skip-locked.spec b/src/test/isolation/specs/skip-locked.spec
new file mode 100644
index 0000000..12168f8
--- /dev/null
+++ b/src/test/isolation/specs/skip-locked.spec
@@ -0,0 +1,28 @@
+# Test SKIP LOCKED when regular row locks can't be acquired.
+
+setup
+{
+ CREATE TABLE queue (
+ id int PRIMARY KEY,
+ data text NOT NULL,
+ status text NOT NULL
+ );
+ INSERT INTO queue VALUES (1, 'foo', 'NEW'), (2, 'bar', 'NEW');
+}
+
+teardown
+{
+ DROP TABLE queue;
+}
+
+session s1
+setup { BEGIN; }
+step s1a { SELECT * FROM queue ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 1; }
+step s1b { SELECT * FROM queue ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 1; }
+step s1c { COMMIT; }
+
+session s2
+setup { BEGIN; }
+step s2a { SELECT * FROM queue ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 1; }
+step s2b { SELECT * FROM queue ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 1; }
+step s2c { COMMIT; }
diff --git a/src/test/isolation/specs/temporal-range-integrity.spec b/src/test/isolation/specs/temporal-range-integrity.spec
new file mode 100644
index 0000000..2d4c59c
--- /dev/null
+++ b/src/test/isolation/specs/temporal-range-integrity.spec
@@ -0,0 +1,38 @@
+# Temporal Range Integrity test
+#
+# Snapshot integrity fails with simple referential integrity tests,
+# but those don't make for good demonstrations because people just
+# say that foreign key definitions should be used instead. There
+# are many integrity tests which are conceptually very similar but
+# don't have built-in support which will fail when used in triggers.
+# This is intended to illustrate such cases. It is obviously very
+# hard to exercise all these permutations when the code is actually
+# in a trigger; this test pulls what would normally be inside of
+# triggers out to the top level to control the permutations.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+
+setup
+{
+ CREATE TABLE statute (statute_cite text NOT NULL, eff_date date NOT NULL, exp_date date, CONSTRAINT statute_pkey PRIMARY KEY (statute_cite, eff_date));
+ INSERT INTO statute VALUES ('123.45(1)a', DATE '2008-01-01', NULL);
+ CREATE TABLE offense (offense_no int NOT NULL, statute_cite text NOT NULL, offense_date date NOT NULL, CONSTRAINT offense_pkey PRIMARY KEY (offense_no));
+}
+
+teardown
+{
+ DROP TABLE statute, offense;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rx1 { SELECT count(*) FROM statute WHERE statute_cite = '123.45(1)a' AND eff_date <= DATE '2009-05-15' AND (exp_date IS NULL OR exp_date > DATE '2009-05-15'); }
+step wy1 { INSERT INTO offense VALUES (1, '123.45(1)a', DATE '2009-05-15'); }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step ry2 { SELECT count(*) FROM offense WHERE statute_cite = '123.45(1)a' AND offense_date >= DATE '2008-01-01'; }
+step wx2 { DELETE FROM statute WHERE statute_cite = '123.45(1)a' AND eff_date = DATE '2008-01-01'; }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/timeouts.spec b/src/test/isolation/specs/timeouts.spec
new file mode 100644
index 0000000..c747b4a
--- /dev/null
+++ b/src/test/isolation/specs/timeouts.spec
@@ -0,0 +1,49 @@
+# Simple tests for statement_timeout and lock_timeout features
+
+setup
+{
+ CREATE TABLE accounts (accountid text PRIMARY KEY, balance numeric not null);
+ INSERT INTO accounts VALUES ('checking', 600), ('savings', 600);
+}
+
+teardown
+{
+ DROP TABLE accounts;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step rdtbl { SELECT * FROM accounts; }
+step wrtbl { UPDATE accounts SET balance = balance + 100; }
+teardown { ABORT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step sto { SET statement_timeout = '10ms'; }
+step lto { SET lock_timeout = '10ms'; }
+step lsto { SET lock_timeout = '10ms'; SET statement_timeout = '10s'; }
+step slto { SET lock_timeout = '10s'; SET statement_timeout = '10ms'; }
+step locktbl { LOCK TABLE accounts; }
+step update { DELETE FROM accounts WHERE accountid = 'checking'; }
+teardown { ABORT; }
+
+# It's possible that the isolation tester will not observe the final
+# steps as "waiting", thanks to the relatively short timeouts we use.
+# We can ensure consistent test output by marking those steps with (*).
+
+# statement timeout, table-level lock
+permutation rdtbl sto locktbl(*)
+# lock timeout, table-level lock
+permutation rdtbl lto locktbl(*)
+# lock timeout expires first, table-level lock
+permutation rdtbl lsto locktbl(*)
+# statement timeout expires first, table-level lock
+permutation rdtbl slto locktbl(*)
+# statement timeout, row-level lock
+permutation wrtbl sto update(*)
+# lock timeout, row-level lock
+permutation wrtbl lto update(*)
+# lock timeout expires first, row-level lock
+permutation wrtbl lsto update(*)
+# statement timeout expires first, row-level lock
+permutation wrtbl slto update(*)
diff --git a/src/test/isolation/specs/total-cash.spec b/src/test/isolation/specs/total-cash.spec
new file mode 100644
index 0000000..d98121a
--- /dev/null
+++ b/src/test/isolation/specs/total-cash.spec
@@ -0,0 +1,28 @@
+# Total Cash test
+#
+# Another famous test of snapshot isolation anomaly.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE accounts (accountid text NOT NULL PRIMARY KEY, balance numeric not null);
+ INSERT INTO accounts VALUES ('checking', 600),('savings',600);
+}
+
+teardown
+{
+ DROP TABLE accounts;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wx1 { UPDATE accounts SET balance = balance - 200 WHERE accountid = 'checking'; }
+step rxy1 { SELECT SUM(balance) FROM accounts; }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wy2 { UPDATE accounts SET balance = balance - 200 WHERE accountid = 'savings'; }
+step rxy2 { SELECT SUM(balance) FROM accounts; }
+step c2 { COMMIT; }
diff --git a/src/test/isolation/specs/truncate-conflict.spec b/src/test/isolation/specs/truncate-conflict.spec
new file mode 100644
index 0000000..0f77ff0
--- /dev/null
+++ b/src/test/isolation/specs/truncate-conflict.spec
@@ -0,0 +1,38 @@
+# Tests for locking conflicts with TRUNCATE commands.
+
+setup
+{
+ CREATE ROLE regress_truncate_conflict;
+ CREATE TABLE truncate_tab (a int);
+}
+
+teardown
+{
+ DROP TABLE truncate_tab;
+ DROP ROLE regress_truncate_conflict;
+}
+
+session s1
+step s1_begin { BEGIN; }
+step s1_tab_lookup { SELECT count(*) >= 0 FROM truncate_tab; }
+step s1_commit { COMMIT; }
+
+session s2
+step s2_grant { GRANT TRUNCATE ON truncate_tab TO regress_truncate_conflict; }
+step s2_auth { SET ROLE regress_truncate_conflict; }
+step s2_truncate { TRUNCATE truncate_tab; }
+step s2_reset { RESET ROLE; }
+
+# The role doesn't have privileges to truncate the table, so TRUNCATE should
+# immediately fail without waiting for a lock.
+permutation s1_begin s1_tab_lookup s2_auth s2_truncate s1_commit s2_reset
+permutation s1_begin s2_auth s2_truncate s1_tab_lookup s1_commit s2_reset
+permutation s1_begin s2_auth s1_tab_lookup s2_truncate s1_commit s2_reset
+permutation s2_auth s2_truncate s1_begin s1_tab_lookup s1_commit s2_reset
+
+# The role has privileges to truncate the table, TRUNCATE will block if
+# another session holds a lock on the table and succeed in all cases.
+permutation s1_begin s1_tab_lookup s2_grant s2_auth s2_truncate s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s2_truncate s1_tab_lookup s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s1_tab_lookup s2_truncate s1_commit s2_reset
+permutation s2_grant s2_auth s2_truncate s1_begin s1_tab_lookup s1_commit s2_reset
diff --git a/src/test/isolation/specs/tuplelock-conflict.spec b/src/test/isolation/specs/tuplelock-conflict.spec
new file mode 100644
index 0000000..8558230
--- /dev/null
+++ b/src/test/isolation/specs/tuplelock-conflict.spec
@@ -0,0 +1,63 @@
+# Here we verify that tuple lock levels conform to their documented
+# conflict tables.
+
+setup {
+ DROP TABLE IF EXISTS multixact_conflict;
+ CREATE TABLE multixact_conflict (a int primary key);
+ INSERT INTO multixact_conflict VALUES (1);
+}
+
+teardown {
+ DROP TABLE multixact_conflict;
+}
+
+session s1
+step s1_begin { BEGIN; }
+step s1_lcksvpt { SELECT * FROM multixact_conflict FOR KEY SHARE; SAVEPOINT foo; }
+step s1_tuplock1 { SELECT * FROM multixact_conflict FOR KEY SHARE; }
+step s1_tuplock2 { SELECT * FROM multixact_conflict FOR SHARE; }
+step s1_tuplock3 { SELECT * FROM multixact_conflict FOR NO KEY UPDATE; }
+step s1_tuplock4 { SELECT * FROM multixact_conflict FOR UPDATE; }
+step s1_commit { COMMIT; }
+
+session s2
+step s2_tuplock1 { SELECT * FROM multixact_conflict FOR KEY SHARE; }
+step s2_tuplock2 { SELECT * FROM multixact_conflict FOR SHARE; }
+step s2_tuplock3 { SELECT * FROM multixact_conflict FOR NO KEY UPDATE; }
+step s2_tuplock4 { SELECT * FROM multixact_conflict FOR UPDATE; }
+
+# The version with savepoints test the multixact cases
+permutation s1_begin s1_lcksvpt s1_tuplock1 s2_tuplock1 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock1 s2_tuplock2 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock1 s2_tuplock3 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock1 s2_tuplock4 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock2 s2_tuplock1 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock2 s2_tuplock2 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock2 s2_tuplock3 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock2 s2_tuplock4 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock3 s2_tuplock1 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock3 s2_tuplock2 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock3 s2_tuplock3 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock3 s2_tuplock4 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock4 s2_tuplock1 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock4 s2_tuplock2 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock4 s2_tuplock3 s1_commit
+permutation s1_begin s1_lcksvpt s1_tuplock4 s2_tuplock4 s1_commit
+
+# no multixacts here
+permutation s1_begin s1_tuplock1 s2_tuplock1 s1_commit
+permutation s1_begin s1_tuplock1 s2_tuplock2 s1_commit
+permutation s1_begin s1_tuplock1 s2_tuplock3 s1_commit
+permutation s1_begin s1_tuplock1 s2_tuplock4 s1_commit
+permutation s1_begin s1_tuplock2 s2_tuplock1 s1_commit
+permutation s1_begin s1_tuplock2 s2_tuplock2 s1_commit
+permutation s1_begin s1_tuplock2 s2_tuplock3 s1_commit
+permutation s1_begin s1_tuplock2 s2_tuplock4 s1_commit
+permutation s1_begin s1_tuplock3 s2_tuplock1 s1_commit
+permutation s1_begin s1_tuplock3 s2_tuplock2 s1_commit
+permutation s1_begin s1_tuplock3 s2_tuplock3 s1_commit
+permutation s1_begin s1_tuplock3 s2_tuplock4 s1_commit
+permutation s1_begin s1_tuplock4 s2_tuplock1 s1_commit
+permutation s1_begin s1_tuplock4 s2_tuplock2 s1_commit
+permutation s1_begin s1_tuplock4 s2_tuplock3 s1_commit
+permutation s1_begin s1_tuplock4 s2_tuplock4 s1_commit
diff --git a/src/test/isolation/specs/tuplelock-partition.spec b/src/test/isolation/specs/tuplelock-partition.spec
new file mode 100644
index 0000000..c267b28
--- /dev/null
+++ b/src/test/isolation/specs/tuplelock-partition.spec
@@ -0,0 +1,32 @@
+# Test tuple locking on INSERT ON CONFLICT UPDATE on a partitioned table.
+
+setup
+{
+ DROP TABLE IF EXISTS parttab;
+ CREATE TABLE parttab (col1 text, key INTEGER PRIMARY KEY, col2 text) PARTITION BY LIST (key);
+ CREATE TABLE parttab1 (key INTEGER PRIMARY KEY, col1 text, col2 text);
+ CREATE TABLE parttab2 (key INTEGER PRIMARY KEY, col1 text, col2 text);
+ ALTER TABLE parttab ATTACH PARTITION parttab1 FOR VALUES IN (1);
+ ALTER TABLE parttab ATTACH PARTITION parttab2 FOR VALUES IN (2);
+ INSERT INTO parttab (key, col1, col2) VALUES (1, 'a', 'b');
+}
+
+teardown
+{
+ DROP TABLE parttab;
+}
+
+session s1
+step s1b { BEGIN; }
+step s1update_nokey { INSERT INTO parttab (key, col1, col2) VALUES (1, 'a', 'b') ON CONFLICT (key) DO UPDATE SET col1 = 'x', col2 = 'y'; }
+step s1update_key { INSERT INTO parttab (key, col1, col2) VALUES (1, 'a', 'b') ON CONFLICT (key) DO UPDATE SET key=1; }
+step s1c { COMMIT; }
+
+session s2
+step s2locktuple { SELECT * FROM parttab FOR KEY SHARE; }
+
+# INSERT ON CONFLICT UPDATE, performs an UPDATE on non-key columns
+permutation s1b s1update_nokey s2locktuple s1c
+
+# INSERT ON CONFLICT UPDATE, performs an UPDATE on key column
+permutation s1b s1update_key s2locktuple s1c
diff --git a/src/test/isolation/specs/tuplelock-update.spec b/src/test/isolation/specs/tuplelock-update.spec
new file mode 100644
index 0000000..4b940bc
--- /dev/null
+++ b/src/test/isolation/specs/tuplelock-update.spec
@@ -0,0 +1,37 @@
+setup {
+ DROP TABLE IF EXISTS pktab;
+ CREATE TABLE pktab (id int PRIMARY KEY, data SERIAL NOT NULL);
+ INSERT INTO pktab VALUES (1, DEFAULT);
+}
+
+teardown {
+ DROP TABLE pktab;
+}
+
+session s1
+step s1_advlock {
+ SELECT pg_advisory_lock(142857),
+ pg_advisory_lock(285714),
+ pg_advisory_lock(571428);
+ }
+step s1_chain { UPDATE pktab SET data = DEFAULT; }
+step s1_begin { BEGIN; }
+step s1_grablock { SELECT * FROM pktab FOR KEY SHARE; }
+step s1_advunlock1 { SELECT pg_advisory_unlock(142857); }
+step s1_advunlock2 { SELECT pg_advisory_unlock(285714); }
+step s1_advunlock3 { SELECT pg_advisory_unlock(571428); }
+step s1_commit { COMMIT; }
+
+session s2
+step s2_update { UPDATE pktab SET data = DEFAULT WHERE pg_advisory_lock_shared(142857) IS NOT NULL; }
+
+session s3
+step s3_update { UPDATE pktab SET data = DEFAULT WHERE pg_advisory_lock_shared(285714) IS NOT NULL; }
+
+session s4
+step s4_update { UPDATE pktab SET data = DEFAULT WHERE pg_advisory_lock_shared(571428) IS NOT NULL; }
+
+# We use blocker annotations on the s1_advunlockN steps so that we will not
+# move on to the next step until the other session's released step finishes.
+# This ensures stable ordering of the test output.
+permutation s1_advlock s2_update s3_update s4_update s1_chain s1_begin s1_grablock s1_advunlock1(s2_update) s1_advunlock2(s3_update) s1_advunlock3(s4_update) s1_commit
diff --git a/src/test/isolation/specs/tuplelock-upgrade-no-deadlock.spec b/src/test/isolation/specs/tuplelock-upgrade-no-deadlock.spec
new file mode 100644
index 0000000..6221a27
--- /dev/null
+++ b/src/test/isolation/specs/tuplelock-upgrade-no-deadlock.spec
@@ -0,0 +1,69 @@
+# This test checks that multiple sessions locking a single row in a table
+# do not deadlock each other when one of them upgrades its existing lock
+# while the others are waiting for it.
+
+setup
+{
+ drop table if exists tlu_job;
+ create table tlu_job (id integer primary key, name text);
+
+ insert into tlu_job values(1, 'a');
+}
+
+
+teardown
+{
+ drop table tlu_job;
+}
+
+session s0
+step s0_begin { begin; }
+step s0_keyshare { select id from tlu_job where id = 1 for key share;}
+step s0_rollback { rollback; }
+
+session s1
+setup { begin; }
+step s1_keyshare { select id from tlu_job where id = 1 for key share;}
+step s1_share { select id from tlu_job where id = 1 for share; }
+step s1_fornokeyupd { select id from tlu_job where id = 1 for no key update; }
+step s1_update { update tlu_job set name = 'b' where id = 1; }
+step s1_savept_e { savepoint s1_e; }
+step s1_savept_f { savepoint s1_f; }
+step s1_rollback_e { rollback to s1_e; }
+step s1_rollback_f { rollback to s1_f; }
+step s1_rollback { rollback; }
+step s1_commit { commit; }
+
+session s2
+setup { begin; }
+step s2_for_keyshare { select id from tlu_job where id = 1 for key share; }
+step s2_fornokeyupd { select id from tlu_job where id = 1 for no key update; }
+step s2_for_update { select id from tlu_job where id = 1 for update; }
+step s2_update { update tlu_job set name = 'b' where id = 1; }
+step s2_delete { delete from tlu_job where id = 1; }
+step s2_rollback { rollback; }
+
+session s3
+setup { begin; }
+step s3_keyshare { select id from tlu_job where id = 1 for key share; }
+step s3_share { select id from tlu_job where id = 1 for share; }
+step s3_for_update { select id from tlu_job where id = 1 for update; }
+step s3_update { update tlu_job set name = 'c' where id = 1; }
+step s3_delete { delete from tlu_job where id = 1; }
+step s3_rollback { rollback; }
+step s3_commit { commit; }
+
+# test that s2 will not deadlock with s3 when s1 is rolled back
+permutation s1_share s2_for_update s3_share s3_for_update s1_rollback s3_rollback s2_rollback
+# test that update does not cause deadlocks if it can proceed
+permutation s1_keyshare s2_for_update s3_keyshare s1_update s3_update s1_rollback s3_rollback s2_rollback
+permutation s1_keyshare s2_for_update s3_keyshare s1_update s3_update s1_commit s3_rollback s2_rollback
+# test that delete does not cause deadlocks if it can proceed
+permutation s1_keyshare s2_for_update s3_keyshare s3_delete s1_rollback s3_rollback s2_rollback
+permutation s1_keyshare s2_for_update s3_keyshare s3_delete s1_rollback s3_commit s2_rollback
+# test that sessions that don't upgrade locks acquire them in order
+permutation s1_share s2_for_update s3_for_update s1_rollback s2_rollback s3_rollback
+permutation s1_share s2_update s3_update s1_rollback s2_rollback s3_rollback
+permutation s1_share s2_delete s3_delete s1_rollback s2_rollback s3_rollback
+# test s2 retrying the overall tuple lock algorithm after initially avoiding deadlock
+permutation s1_keyshare s3_for_update s2_for_keyshare s1_savept_e s1_share s1_savept_f s1_fornokeyupd s2_fornokeyupd s0_begin s0_keyshare s1_rollback_f s0_keyshare s1_rollback_e s1_rollback s2_rollback s0_rollback s3_rollback
diff --git a/src/test/isolation/specs/two-ids.spec b/src/test/isolation/specs/two-ids.spec
new file mode 100644
index 0000000..fc0289f
--- /dev/null
+++ b/src/test/isolation/specs/two-ids.spec
@@ -0,0 +1,40 @@
+# Two IDs test
+#
+# Small, simple test showing read-only anomalies.
+#
+# There are only four permutations which must cause a serialization failure.
+# Required failure cases are where s2 overlaps both s1 and s3, but s1
+# commits before s3 executes its first SELECT.
+#
+# If s3 were declared READ ONLY there would be no false positives.
+# With s3 defaulting to READ WRITE, we currently expect 12 false
+# positives. Further work dealing with de facto READ ONLY transactions
+# may be able to reduce or eliminate those false positives.
+
+setup
+{
+ create table D1 (id int not null);
+ create table D2 (id int not null);
+ insert into D1 values (1);
+ insert into D2 values (1);
+}
+
+teardown
+{
+ DROP TABLE D1, D2;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wx1 { update D1 set id = id + 1; }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step rxwy2 { update D2 set id = (select id+1 from D1); }
+step c2 { COMMIT; }
+
+session s3
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step ry3 { select id from D2; }
+step c3 { COMMIT; }
diff --git a/src/test/isolation/specs/update-conflict-out.spec b/src/test/isolation/specs/update-conflict-out.spec
new file mode 100644
index 0000000..8aad6aa
--- /dev/null
+++ b/src/test/isolation/specs/update-conflict-out.spec
@@ -0,0 +1,54 @@
+# Test for interactions between SSI's "conflict out" handling for heapam and
+# concurrently updated tuple
+#
+# See bug report:
+# https://postgr.es/m/db7b729d-0226-d162-a126-8a8ab2dc4443%40jepsen.io
+
+setup
+{
+ CREATE TABLE txn0(id int4 PRIMARY KEY, val TEXT);
+ CREATE TABLE txn1(id int4 PRIMARY KEY, val TEXT);
+}
+
+teardown
+{
+ DROP TABLE txn0;
+ DROP TABLE txn1;
+}
+
+session foo
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step foo_select { SELECT * FROM txn0 WHERE id = 42; }
+step foo_insert { INSERT INTO txn1 SELECT 7, 'foo_insert'; }
+step foo_commit { COMMIT; }
+
+session bar
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step bar_select { SELECT * FROM txn1 WHERE id = 7; }
+step bar_insert { INSERT INTO txn0 SELECT 42, 'bar_insert'; }
+step bar_commit { COMMIT; }
+
+# This session creates the conditions that confused bar's "conflict out"
+# handling in old releases affected by bug:
+session trouble
+setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
+step trouble_update { UPDATE txn1 SET val = 'add physical version for "bar_select"' WHERE id = 7; }
+step trouble_delete { DELETE FROM txn1 WHERE id = 7; }
+step trouble_abort { ABORT; }
+
+permutation foo_select
+ bar_insert
+ foo_insert foo_commit
+ trouble_update # Updates tuple...
+ bar_select # Should observe one distinct XID per version
+ bar_commit # "bar" should fail here at the latest
+ trouble_abort
+
+# Same as above, but "trouble" session DELETEs this time around
+permutation foo_select
+ bar_insert
+ foo_insert foo_commit
+ trouble_delete # Deletes tuple...
+ bar_select # Should observe foo's XID
+ bar_commit # "bar" should fail here at the latest
+ trouble_abort
diff --git a/src/test/isolation/specs/update-locked-tuple.spec b/src/test/isolation/specs/update-locked-tuple.spec
new file mode 100644
index 0000000..0dad792
--- /dev/null
+++ b/src/test/isolation/specs/update-locked-tuple.spec
@@ -0,0 +1,38 @@
+# Test updating a locked tuple. When the lock doesn't conflict with the
+# update, no blocking nor serializability problems should occur.
+
+setup
+{
+ DROP TABLE IF EXISTS users, orders;
+ CREATE TABLE users (id INTEGER PRIMARY KEY,
+ name varchar,
+ sometime timestamp);
+ CREATE TABLE orders (id INTEGER PRIMARY KEY,
+ name varchar,
+ user_id INTEGER REFERENCES users (id));
+ INSERT INTO users (id, name) VALUES (1, 'olivier');
+ INSERT INTO orders (id, name) VALUES (1, 'order of olivier (1)');
+}
+
+teardown
+{
+ DROP TABLE users, orders;
+}
+
+session s1
+step s1b { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step s1u1 { UPDATE orders SET name = 'order of olivier (2)', user_id = 1 WHERE id = 1; }
+step s1u2 { UPDATE orders SET name = 'order of olivier (3)', user_id = 1 WHERE id = 1; }
+step s1c { COMMIT; }
+
+session s2
+step s2b { BEGIN ISOLATION LEVEL REPEATABLE READ; }
+step s2u { UPDATE users SET sometime = '1830-10-04' WHERE id = 1; }
+step s2c { COMMIT; }
+
+permutation s1b s2b s2u s2c s1u1 s1u2 s1c
+permutation s1b s2b s2u s1u1 s2c s1u2 s1c
+permutation s1b s2b s1u1 s2u s2c s1u2 s1c
+permutation s1b s1u1 s2b s2u s2c s1u2 s1c
+permutation s1b s1u1 s2b s1u2 s2u s2c s1c
+permutation s1b s1u1 s1u2 s2b s2u s2c s1c
diff --git a/src/test/isolation/specs/vacuum-concurrent-drop.spec b/src/test/isolation/specs/vacuum-concurrent-drop.spec
new file mode 100644
index 0000000..148a2d5
--- /dev/null
+++ b/src/test/isolation/specs/vacuum-concurrent-drop.spec
@@ -0,0 +1,45 @@
+# Test for log messages emitted by VACUUM and ANALYZE when a specified
+# relation is concurrently dropped.
+#
+# This also verifies that log messages are not emitted for concurrently
+# dropped relations that were not specified in the VACUUM or ANALYZE
+# command.
+
+setup
+{
+ CREATE TABLE parted (a INT) PARTITION BY LIST (a);
+ CREATE TABLE part1 PARTITION OF parted FOR VALUES IN (1);
+ CREATE TABLE part2 PARTITION OF parted FOR VALUES IN (2);
+}
+
+teardown
+{
+ DROP TABLE IF EXISTS parted;
+}
+
+session s1
+step lock
+{
+ BEGIN;
+ LOCK part1 IN SHARE MODE;
+}
+step drop_and_commit
+{
+ DROP TABLE part2;
+ COMMIT;
+}
+
+session s2
+step vac_specified { VACUUM part1, part2; }
+step vac_all_parts { VACUUM parted; }
+step analyze_specified { ANALYZE part1, part2; }
+step analyze_all_parts { ANALYZE parted; }
+step vac_analyze_specified { VACUUM ANALYZE part1, part2; }
+step vac_analyze_all_parts { VACUUM ANALYZE parted; }
+
+permutation lock vac_specified drop_and_commit
+permutation lock vac_all_parts drop_and_commit
+permutation lock analyze_specified drop_and_commit
+permutation lock analyze_all_parts drop_and_commit
+permutation lock vac_analyze_specified drop_and_commit
+permutation lock vac_analyze_all_parts drop_and_commit
diff --git a/src/test/isolation/specs/vacuum-conflict.spec b/src/test/isolation/specs/vacuum-conflict.spec
new file mode 100644
index 0000000..3cb8926
--- /dev/null
+++ b/src/test/isolation/specs/vacuum-conflict.spec
@@ -0,0 +1,51 @@
+# Tests for locking conflicts with VACUUM and ANALYZE commands.
+
+setup
+{
+ CREATE ROLE regress_vacuum_conflict;
+ CREATE TABLE vacuum_tab (a int);
+}
+
+teardown
+{
+ DROP TABLE vacuum_tab;
+ DROP ROLE regress_vacuum_conflict;
+}
+
+session s1
+step s1_begin { BEGIN; }
+step s1_lock { LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE; }
+step s1_commit { COMMIT; }
+
+session s2
+step s2_grant { ALTER TABLE vacuum_tab OWNER TO regress_vacuum_conflict; }
+step s2_auth { SET ROLE regress_vacuum_conflict; }
+step s2_vacuum { VACUUM vacuum_tab; }
+step s2_analyze { ANALYZE vacuum_tab; }
+step s2_reset { RESET ROLE; }
+
+# The role doesn't have privileges to vacuum the table, so VACUUM should
+# immediately skip the table without waiting for a lock.
+permutation s1_begin s1_lock s2_auth s2_vacuum s1_commit s2_reset
+permutation s1_begin s2_auth s2_vacuum s1_lock s1_commit s2_reset
+permutation s1_begin s2_auth s1_lock s2_vacuum s1_commit s2_reset
+permutation s2_auth s2_vacuum s1_begin s1_lock s1_commit s2_reset
+
+# Same as previously for ANALYZE
+permutation s1_begin s1_lock s2_auth s2_analyze s1_commit s2_reset
+permutation s1_begin s2_auth s2_analyze s1_lock s1_commit s2_reset
+permutation s1_begin s2_auth s1_lock s2_analyze s1_commit s2_reset
+permutation s2_auth s2_analyze s1_begin s1_lock s1_commit s2_reset
+
+# The role has privileges to vacuum the table, VACUUM will block if
+# another session holds a lock on the table and succeed in all cases.
+permutation s1_begin s2_grant s1_lock s2_auth s2_vacuum s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s2_vacuum s1_lock s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s1_lock s2_vacuum s1_commit s2_reset
+permutation s2_grant s2_auth s2_vacuum s1_begin s1_lock s1_commit s2_reset
+
+# Same as previously for ANALYZE
+permutation s1_begin s2_grant s1_lock s2_auth s2_analyze s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s2_analyze s1_lock s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s1_lock s2_analyze s1_commit s2_reset
+permutation s2_grant s2_auth s2_analyze s1_begin s1_lock s1_commit s2_reset
diff --git a/src/test/isolation/specs/vacuum-reltuples.spec b/src/test/isolation/specs/vacuum-reltuples.spec
new file mode 100644
index 0000000..ae2f79b
--- /dev/null
+++ b/src/test/isolation/specs/vacuum-reltuples.spec
@@ -0,0 +1,48 @@
+# Test for vacuum's handling of reltuples when pages are skipped due
+# to page pins. We absolutely need to avoid setting reltuples=0 in
+# such cases, since that interferes badly with planning.
+#
+# Expected result in second permutation is 20 tuples rather than 21 as
+# for the others, because vacuum should leave the previous result
+# (from before the insert) in place.
+
+setup {
+ create table smalltbl
+ as select i as id from generate_series(1,20) i;
+ alter table smalltbl set (autovacuum_enabled = off);
+}
+setup {
+ vacuum analyze smalltbl;
+}
+
+teardown {
+ drop table smalltbl;
+}
+
+session worker
+step open {
+ begin;
+ declare c1 cursor for select 1 as dummy from smalltbl;
+}
+step fetch1 {
+ fetch next from c1;
+}
+step close {
+ commit;
+}
+step stats {
+ select relpages, reltuples from pg_class
+ where oid='smalltbl'::regclass;
+}
+
+session vacuumer
+step vac {
+ vacuum smalltbl;
+}
+step modify {
+ insert into smalltbl select max(id)+1 from smalltbl;
+}
+
+permutation modify vac stats
+permutation modify open fetch1 vac close stats
+permutation modify vac stats
diff --git a/src/test/isolation/specs/vacuum-skip-locked.spec b/src/test/isolation/specs/vacuum-skip-locked.spec
new file mode 100644
index 0000000..3fad6e1
--- /dev/null
+++ b/src/test/isolation/specs/vacuum-skip-locked.spec
@@ -0,0 +1,61 @@
+# Test for SKIP_LOCKED option of VACUUM and ANALYZE commands.
+#
+# This also verifies that log messages are not emitted for skipped relations
+# that were not specified in the VACUUM or ANALYZE command.
+
+setup
+{
+ CREATE TABLE parted (a INT) PARTITION BY LIST (a);
+ CREATE TABLE part1 PARTITION OF parted FOR VALUES IN (1);
+ ALTER TABLE part1 SET (autovacuum_enabled = false);
+ CREATE TABLE part2 PARTITION OF parted FOR VALUES IN (2);
+ ALTER TABLE part2 SET (autovacuum_enabled = false);
+}
+
+teardown
+{
+ DROP TABLE IF EXISTS parted;
+}
+
+session s1
+step lock_share
+{
+ BEGIN;
+ LOCK part1 IN SHARE MODE;
+}
+step lock_access_exclusive
+{
+ BEGIN;
+ LOCK part1 IN ACCESS EXCLUSIVE MODE;
+}
+step commit
+{
+ COMMIT;
+}
+
+session s2
+step vac_specified { VACUUM (SKIP_LOCKED) part1, part2; }
+step vac_all_parts { VACUUM (SKIP_LOCKED) parted; }
+step analyze_specified { ANALYZE (SKIP_LOCKED) part1, part2; }
+step analyze_all_parts { ANALYZE (SKIP_LOCKED) parted; }
+step vac_analyze_specified { VACUUM (ANALYZE, SKIP_LOCKED) part1, part2; }
+step vac_analyze_all_parts { VACUUM (ANALYZE, SKIP_LOCKED) parted; }
+step vac_full_specified { VACUUM (SKIP_LOCKED, FULL) part1, part2; }
+step vac_full_all_parts { VACUUM (SKIP_LOCKED, FULL) parted; }
+
+permutation lock_share vac_specified commit
+permutation lock_share vac_all_parts commit
+permutation lock_share analyze_specified commit
+permutation lock_share analyze_all_parts commit
+permutation lock_share vac_analyze_specified commit
+permutation lock_share vac_analyze_all_parts commit
+permutation lock_share vac_full_specified commit
+permutation lock_share vac_full_all_parts commit
+permutation lock_access_exclusive vac_specified commit
+permutation lock_access_exclusive vac_all_parts commit
+permutation lock_access_exclusive analyze_specified commit
+permutation lock_access_exclusive analyze_all_parts commit
+permutation lock_access_exclusive vac_analyze_specified commit
+permutation lock_access_exclusive vac_analyze_all_parts commit
+permutation lock_access_exclusive vac_full_specified commit
+permutation lock_access_exclusive vac_full_all_parts commit
diff --git a/src/test/isolation/specscanner.c b/src/test/isolation/specscanner.c
new file mode 100644
index 0000000..f22a807
--- /dev/null
+++ b/src/test/isolation/specscanner.c
@@ -0,0 +1,2220 @@
+#line 2 "specscanner.c"
+
+#line 4 "specscanner.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define yy_create_buffer spec_yy_create_buffer
+#define yy_delete_buffer spec_yy_delete_buffer
+#define yy_scan_buffer spec_yy_scan_buffer
+#define yy_scan_string spec_yy_scan_string
+#define yy_scan_bytes spec_yy_scan_bytes
+#define yy_init_buffer spec_yy_init_buffer
+#define yy_flush_buffer spec_yy_flush_buffer
+#define yy_load_buffer_state spec_yy_load_buffer_state
+#define yy_switch_to_buffer spec_yy_switch_to_buffer
+#define yypush_buffer_state spec_yypush_buffer_state
+#define yypop_buffer_state spec_yypop_buffer_state
+#define yyensure_buffer_stack spec_yyensure_buffer_stack
+#define yy_flex_debug spec_yy_flex_debug
+#define yyin spec_yyin
+#define yyleng spec_yyleng
+#define yylex spec_yylex
+#define yylineno spec_yylineno
+#define yyout spec_yyout
+#define yyrestart spec_yyrestart
+#define yytext spec_yytext
+#define yywrap spec_yywrap
+#define yyalloc spec_yyalloc
+#define yyrealloc spec_yyrealloc
+#define yyfree spec_yyfree
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 6
+#define YY_FLEX_SUBMINOR_VERSION 4
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+#ifdef yy_create_buffer
+#define spec_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer spec_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define spec_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer spec_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define spec_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer spec_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define spec_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string spec_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define spec_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes spec_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define spec_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer spec_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define spec_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer spec_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define spec_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state spec_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define spec_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer spec_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define spec_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state spec_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define spec_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state spec_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define spec_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack spec_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define spec_yylex_ALREADY_DEFINED
+#else
+#define yylex spec_yylex
+#endif
+
+#ifdef yyrestart
+#define spec_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart spec_yyrestart
+#endif
+
+#ifdef yylex_init
+#define spec_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init spec_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define spec_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra spec_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define spec_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy spec_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define spec_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug spec_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define spec_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug spec_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define spec_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra spec_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define spec_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra spec_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define spec_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in spec_yyget_in
+#endif
+
+#ifdef yyset_in
+#define spec_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in spec_yyset_in
+#endif
+
+#ifdef yyget_out
+#define spec_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out spec_yyget_out
+#endif
+
+#ifdef yyset_out
+#define spec_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out spec_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define spec_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng spec_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define spec_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text spec_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define spec_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno spec_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define spec_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno spec_yyset_lineno
+#endif
+
+#ifdef yywrap
+#define spec_yywrap_ALREADY_DEFINED
+#else
+#define yywrap spec_yywrap
+#endif
+
+#ifdef yyalloc
+#define spec_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc spec_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define spec_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc spec_yyrealloc
+#endif
+
+#ifdef yyfree
+#define spec_yyfree_ALREADY_DEFINED
+#else
+#define yyfree spec_yyfree
+#endif
+
+#ifdef yytext
+#define spec_yytext_ALREADY_DEFINED
+#else
+#define yytext spec_yytext
+#endif
+
+#ifdef yyleng
+#define spec_yyleng_ALREADY_DEFINED
+#else
+#define yyleng spec_yyleng
+#endif
+
+#ifdef yyin
+#define spec_yyin_ALREADY_DEFINED
+#else
+#define yyin spec_yyin
+#endif
+
+#ifdef yyout
+#define spec_yyout_ALREADY_DEFINED
+#else
+#define yyout spec_yyout
+#endif
+
+#ifdef yy_flex_debug
+#define spec_yy_flex_debug_ALREADY_DEFINED
+#else
+#define yy_flex_debug spec_yy_flex_debug
+#endif
+
+#ifdef yylineno
+#define spec_yylineno_ALREADY_DEFINED
+#else
+#define yylineno spec_yylineno
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+/* begin standard C++ headers. */
+
+/* TODO: this is always defined, so inline it */
+#define yyconst const
+
+#if defined(__GNUC__) && __GNUC__ >= 3
+#define yynoreturn __attribute__((__noreturn__))
+#else
+#define yynoreturn
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
+ */
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+extern int yyleng;
+
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+ #define YY_LINENO_REWIND_TO(ptr)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ int yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = NULL;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart ( FILE *input_file );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size );
+void yy_delete_buffer ( YY_BUFFER_STATE b );
+void yy_flush_buffer ( YY_BUFFER_STATE b );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer );
+void yypop_buffer_state ( void );
+
+static void yyensure_buffer_stack ( void );
+static void yy_load_buffer_state ( void );
+static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file );
+#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len );
+
+void *yyalloc ( yy_size_t );
+void *yyrealloc ( void *, yy_size_t );
+void yyfree ( void * );
+
+#define yy_new_buffer yy_create_buffer
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define spec_yywrap() (/*CONSTCOND*/1)
+#define YY_SKIP_YYWRAP
+typedef flex_uint8_t YY_CHAR;
+
+FILE *yyin = NULL, *yyout = NULL;
+
+typedef int yy_state_type;
+
+extern int yylineno;
+int yylineno = 1;
+
+extern char *yytext;
+#ifdef yytext_ptr
+#undef yytext_ptr
+#endif
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state ( void );
+static yy_state_type yy_try_NUL_trans ( yy_state_type current_state );
+static int yy_get_next_buffer ( void );
+static void yynoreturn yy_fatal_error ( const char* msg );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+ yyleng = (int) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+ (yy_c_buf_p) = yy_cp;
+#define YY_NUM_RULES 23
+#define YY_END_OF_BUFFER 24
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static const flex_int16_t yy_accept[71] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 24, 22, 9, 7,
+ 11, 8, 21, 20, 10, 10, 10, 10, 10, 16,
+ 18, 18, 19, 17, 14, 15, 13, 8, 20, 10,
+ 10, 10, 10, 10, 10, 16, 0, 17, 12, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 5,
+ 10, 10, 10, 10, 4, 10, 10, 10, 10, 10,
+ 1, 10, 3, 10, 10, 6, 10, 10, 2, 0
+ } ;
+
+static const YY_CHAR yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 2, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 5, 6, 7, 1, 1, 1, 8,
+ 8, 8, 1, 8, 1, 1, 1, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 1, 1, 1,
+ 1, 1, 1, 1, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 1, 1, 1, 1, 10, 1, 11, 10, 12, 13,
+
+ 14, 10, 10, 10, 15, 10, 10, 10, 16, 17,
+ 18, 19, 10, 20, 21, 22, 23, 10, 24, 10,
+ 10, 10, 25, 1, 26, 1, 1, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10
+ } ;
+
+static const YY_CHAR yy_meta[27] =
+ { 0,
+ 1, 1, 2, 2, 1, 1, 3, 1, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 1, 1
+ } ;
+
+static const flex_int16_t yy_base[75] =
+ { 0,
+ 0, 0, 25, 50, 27, 28, 96, 97, 97, 97,
+ 97, 0, 97, 86, 0, 76, 79, 20, 78, 33,
+ 97, 34, 97, 97, 97, 97, 86, 0, 81, 0,
+ 67, 68, 18, 73, 75, 39, 42, 97, 97, 69,
+ 59, 53, 50, 53, 51, 58, 46, 52, 47, 0,
+ 52, 50, 41, 44, 0, 43, 38, 47, 40, 32,
+ 0, 33, 0, 33, 34, 0, 30, 30, 0, 97,
+ 76, 79, 82, 42
+ } ;
+
+static const flex_int16_t yy_def[75] =
+ { 0,
+ 70, 1, 71, 71, 72, 72, 70, 70, 70, 70,
+ 70, 73, 70, 70, 74, 74, 74, 74, 74, 70,
+ 70, 70, 70, 70, 70, 70, 70, 73, 70, 74,
+ 74, 74, 74, 74, 74, 70, 70, 70, 70, 74,
+ 74, 74, 74, 74, 74, 74, 74, 74, 74, 74,
+ 74, 74, 74, 74, 74, 74, 74, 74, 74, 74,
+ 74, 74, 74, 74, 74, 74, 74, 74, 74, 0,
+ 70, 70, 70, 70
+ } ;
+
+static const flex_int16_t yy_nxt[124] =
+ { 0,
+ 8, 9, 10, 9, 11, 12, 8, 13, 14, 15,
+ 15, 15, 15, 15, 15, 15, 16, 15, 17, 15,
+ 18, 19, 15, 15, 20, 8, 22, 23, 22, 26,
+ 26, 27, 27, 33, 36, 37, 36, 37, 42, 43,
+ 36, 34, 36, 37, 30, 37, 69, 68, 67, 66,
+ 24, 22, 23, 22, 65, 64, 63, 62, 61, 38,
+ 60, 59, 58, 57, 56, 55, 54, 38, 53, 52,
+ 51, 50, 49, 48, 47, 24, 21, 21, 21, 25,
+ 25, 25, 28, 46, 28, 45, 44, 41, 40, 29,
+ 39, 35, 32, 31, 29, 70, 7, 70, 70, 70,
+
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70
+ } ;
+
+static const flex_int16_t yy_chk[124] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 3, 3, 3, 5,
+ 6, 5, 6, 18, 20, 22, 20, 22, 33, 33,
+ 36, 18, 36, 37, 74, 37, 68, 67, 65, 64,
+ 3, 4, 4, 4, 62, 60, 59, 58, 57, 22,
+ 56, 54, 53, 52, 51, 49, 48, 37, 47, 46,
+ 45, 44, 43, 42, 41, 4, 71, 71, 71, 72,
+ 72, 72, 73, 40, 73, 35, 34, 32, 31, 29,
+ 27, 19, 17, 16, 14, 7, 70, 70, 70, 70,
+
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
+ 70, 70, 70
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int yy_flex_debug;
+int yy_flex_debug = 0;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "specscanner.l"
+#line 2 "specscanner.l"
+/*-------------------------------------------------------------------------
+ *
+ * specscanner.l
+ * a lexical scanner for an isolation test specification
+ *
+ * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static int yyline = 1; /* line number for error reporting */
+
+#define LITBUF_INIT 1024 /* initial size of litbuf */
+static char *litbuf = NULL;
+static size_t litbufsize = 0;
+static size_t litbufpos = 0;
+
+static void addlitchar(char c);
+
+/* LCOV_EXCL_START */
+
+#line 775 "specscanner.c"
+#define YY_NO_INPUT 1
+
+#line 778 "specscanner.c"
+
+#define INITIAL 0
+#define sql 1
+#define qident 2
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+static int yy_init_globals ( void );
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int yylex_destroy ( void );
+
+int yyget_debug ( void );
+
+void yyset_debug ( int debug_flag );
+
+YY_EXTRA_TYPE yyget_extra ( void );
+
+void yyset_extra ( YY_EXTRA_TYPE user_defined );
+
+FILE *yyget_in ( void );
+
+void yyset_in ( FILE * _in_str );
+
+FILE *yyget_out ( void );
+
+void yyset_out ( FILE * _out_str );
+
+ int yyget_leng ( void );
+
+char *yyget_text ( void );
+
+int yyget_lineno ( void );
+
+void yyset_lineno ( int _line_number );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap ( void );
+#else
+extern int yywrap ( void );
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy ( char *, const char *, int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen ( const char * );
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput ( void );
+#else
+static int input ( void );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ int n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int yylex (void);
+
+#define YY_DECL int yylex (void)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK /*LINTED*/break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_load_buffer_state( );
+ }
+
+ {
+#line 52 "specscanner.l"
+
+
+
+#line 56 "specscanner.l"
+ /* Allocate litbuf in first call of yylex() */
+ if (litbuf == NULL)
+ {
+ litbuf = pg_malloc(LITBUF_INIT);
+ litbufsize = LITBUF_INIT;
+ }
+
+
+ /* Keywords (must appear before the {identifier} rule!) */
+#line 1009 "specscanner.c"
+
+ while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of yytext. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 71 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 70 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 65 "specscanner.l"
+{ return NOTICES; }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 66 "specscanner.l"
+{ return PERMUTATION; }
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 67 "specscanner.l"
+{ return SESSION; }
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 68 "specscanner.l"
+{ return SETUP; }
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 69 "specscanner.l"
+{ return STEP; }
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 70 "specscanner.l"
+{ return TEARDOWN; }
+ YY_BREAK
+/* Whitespace and comments */
+case 7:
+/* rule 7 can match eol */
+YY_RULE_SETUP
+#line 73 "specscanner.l"
+{ yyline++; }
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 74 "specscanner.l"
+{ /* ignore */ }
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 75 "specscanner.l"
+{ /* ignore */ }
+ YY_BREAK
+/* Plain identifiers */
+case 10:
+YY_RULE_SETUP
+#line 78 "specscanner.l"
+{
+ yylval.str = pg_strdup(yytext);
+ return(identifier);
+ }
+ YY_BREAK
+/* Quoted identifiers: "foo" */
+case 11:
+YY_RULE_SETUP
+#line 84 "specscanner.l"
+{
+ litbufpos = 0;
+ BEGIN(qident);
+ }
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 88 "specscanner.l"
+{ addlitchar(yytext[0]); }
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 89 "specscanner.l"
+{
+ litbuf[litbufpos] = '\0';
+ yylval.str = pg_strdup(litbuf);
+ BEGIN(INITIAL);
+ return(identifier);
+ }
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 95 "specscanner.l"
+{ addlitchar(yytext[0]); }
+ YY_BREAK
+case 15:
+/* rule 15 can match eol */
+YY_RULE_SETUP
+#line 96 "specscanner.l"
+{ yyerror("unexpected newline in quoted identifier"); }
+ YY_BREAK
+case YY_STATE_EOF(qident):
+#line 97 "specscanner.l"
+{ yyerror("unterminated quoted identifier"); }
+ YY_BREAK
+/* SQL blocks: { UPDATE ... } */
+/* We trim leading/trailing whitespace, otherwise they're unprocessed */
+case 16:
+YY_RULE_SETUP
+#line 101 "specscanner.l"
+{
+
+ litbufpos = 0;
+ BEGIN(sql);
+ }
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 106 "specscanner.l"
+{
+ litbuf[litbufpos] = '\0';
+ yylval.str = pg_strdup(litbuf);
+ BEGIN(INITIAL);
+ return(sqlblock);
+ }
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 112 "specscanner.l"
+{
+ addlitchar(yytext[0]);
+ }
+ YY_BREAK
+case 19:
+/* rule 19 can match eol */
+YY_RULE_SETUP
+#line 115 "specscanner.l"
+{
+ yyline++;
+ addlitchar(yytext[0]);
+ }
+ YY_BREAK
+case YY_STATE_EOF(sql):
+#line 119 "specscanner.l"
+{
+ yyerror("unterminated sql block");
+ }
+ YY_BREAK
+/* Numbers and punctuation */
+case 20:
+YY_RULE_SETUP
+#line 124 "specscanner.l"
+{
+ yylval.integer = atoi(yytext);
+ return INTEGER;
+ }
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 129 "specscanner.l"
+{ return yytext[0]; }
+ YY_BREAK
+/* Anything else is an error */
+case 22:
+YY_RULE_SETUP
+#line 132 "specscanner.l"
+{
+ fprintf(stderr, "syntax error at line %d: unexpected character \"%s\"\n", yyline, yytext);
+ exit(1);
+ }
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 136 "specscanner.l"
+YY_FATAL_ERROR( "flex scanner jammed" );
+ YY_BREAK
+#line 1228 "specscanner.c"
+case YY_STATE_EOF(INITIAL):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( yywrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+ } /* end of user's declarations */
+} /* end of yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (void)
+{
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = (yytext_ptr);
+ int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ int num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ yyrealloc( (void *) b->yy_ch_buf,
+ (yy_size_t) (b->yy_buf_size + 2) );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = NULL;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
+ (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ /* "- 2" to take care of EOB's */
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (void)
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 71 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+{
+ int yy_is_jam;
+ char *yy_cp = (yy_c_buf_p);
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 71 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ yy_is_jam = (yy_current_state == 70);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_UNPUT
+
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ int offset = (int) ((yy_c_buf_p) - (yytext_ptr));
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart( yyin );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap( ) )
+ return 0;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve yytext */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void yyrestart (FILE * input_file )
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file );
+ yy_load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
+ */
+ yyensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ yy_load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+static void yy_load_buffer_state (void)
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with yy_create_buffer()
+ *
+ */
+ void yy_delete_buffer (YY_BUFFER_STATE b )
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ yyfree( (void *) b->yy_ch_buf );
+
+ yyfree( (void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a yyrestart() or at EOF.
+ */
+ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
+
+{
+ int oerrno = errno;
+
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+ void yy_flush_buffer (YY_BUFFER_STATE b )
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ yy_load_buffer_state( );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
+{
+ if (new_buffer == NULL)
+ return;
+
+ yyensure_buffer_stack();
+
+ /* This block is copied from yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+void yypop_buffer_state (void)
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ yy_delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void yyensure_buffer_stack (void)
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
+ (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ yy_size_t grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return NULL;
+
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+ b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = NULL;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer( b );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ *
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE yy_scan_string (const char * yystr )
+{
+
+ return yy_scan_bytes( yystr, (int) strlen(yystr) );
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) yyalloc( n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer( buf, n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yynoreturn yy_fatal_error (const char* msg )
+{
+ fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = (yy_hold_char); \
+ (yy_c_buf_p) = yytext + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the current line number.
+ *
+ */
+int yyget_lineno (void)
+{
+
+ return yylineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *yyget_in (void)
+{
+ return yyin;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *yyget_out (void)
+{
+ return yyout;
+}
+
+/** Get the length of the current token.
+ *
+ */
+int yyget_leng (void)
+{
+ return yyleng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *yyget_text (void)
+{
+ return yytext;
+}
+
+/** Set the current line number.
+ * @param _line_number line number
+ *
+ */
+void yyset_lineno (int _line_number )
+{
+
+ yylineno = _line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param _in_str A readable stream.
+ *
+ * @see yy_switch_to_buffer
+ */
+void yyset_in (FILE * _in_str )
+{
+ yyin = _in_str ;
+}
+
+void yyset_out (FILE * _out_str )
+{
+ yyout = _out_str ;
+}
+
+int yyget_debug (void)
+{
+ return yy_flex_debug;
+}
+
+void yyset_debug (int _bdebug )
+{
+ yy_flex_debug = _bdebug ;
+}
+
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from yylex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = NULL;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = NULL;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = NULL;
+ yyout = NULL;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * yylex_init()
+ */
+ return 0;
+}
+
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int yylex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ yypop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ yyfree((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * yylex() is called, initialization will occur. */
+ yy_init_globals( );
+
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, const char * s2, int n )
+{
+
+ int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (const char * s )
+{
+ int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *yyalloc (yy_size_t size )
+{
+ return malloc(size);
+}
+
+void *yyrealloc (void * ptr, yy_size_t size )
+{
+
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return realloc(ptr, size);
+}
+
+void yyfree (void * ptr )
+{
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 136 "specscanner.l"
+
+
+/* LCOV_EXCL_STOP */
+
+static void
+addlitchar(char c)
+{
+ /* We must always leave room to add a trailing \0 */
+ if (litbufpos >= litbufsize - 1)
+ {
+ /* Double the size of litbuf if it gets full */
+ litbufsize += litbufsize;
+ litbuf = pg_realloc(litbuf, litbufsize);
+ }
+ litbuf[litbufpos++] = c;
+}
+
+void
+yyerror(const char *message)
+{
+ fprintf(stderr, "%s at line %d\n", message, yyline);
+ exit(1);
+}
+
diff --git a/src/test/isolation/specscanner.l b/src/test/isolation/specscanner.l
new file mode 100644
index 0000000..21d3acc
--- /dev/null
+++ b/src/test/isolation/specscanner.l
@@ -0,0 +1,157 @@
+%{
+/*-------------------------------------------------------------------------
+ *
+ * specscanner.l
+ * a lexical scanner for an isolation test specification
+ *
+ * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static int yyline = 1; /* line number for error reporting */
+
+#define LITBUF_INIT 1024 /* initial size of litbuf */
+static char *litbuf = NULL;
+static size_t litbufsize = 0;
+static size_t litbufpos = 0;
+
+static void addlitchar(char c);
+
+/* LCOV_EXCL_START */
+
+%}
+
+%option 8bit
+%option never-interactive
+%option nodefault
+%option noinput
+%option nounput
+%option noyywrap
+%option warn
+%option prefix="spec_yy"
+
+
+%x sql
+%x qident
+
+non_newline [^\n\r]
+space [ \t\r\f]
+
+comment ("#"{non_newline}*)
+
+digit [0-9]
+ident_start [A-Za-z\200-\377_]
+ident_cont [A-Za-z\200-\377_0-9\$]
+
+identifier {ident_start}{ident_cont}*
+
+self [,()*]
+
+%%
+
+%{
+ /* Allocate litbuf in first call of yylex() */
+ if (litbuf == NULL)
+ {
+ litbuf = pg_malloc(LITBUF_INIT);
+ litbufsize = LITBUF_INIT;
+ }
+%}
+
+ /* Keywords (must appear before the {identifier} rule!) */
+notices { return NOTICES; }
+permutation { return PERMUTATION; }
+session { return SESSION; }
+setup { return SETUP; }
+step { return STEP; }
+teardown { return TEARDOWN; }
+
+ /* Whitespace and comments */
+[\n] { yyline++; }
+{comment} { /* ignore */ }
+{space} { /* ignore */ }
+
+ /* Plain identifiers */
+{identifier} {
+ yylval.str = pg_strdup(yytext);
+ return(identifier);
+ }
+
+ /* Quoted identifiers: "foo" */
+\" {
+ litbufpos = 0;
+ BEGIN(qident);
+ }
+<qident>\"\" { addlitchar(yytext[0]); }
+<qident>\" {
+ litbuf[litbufpos] = '\0';
+ yylval.str = pg_strdup(litbuf);
+ BEGIN(INITIAL);
+ return(identifier);
+ }
+<qident>. { addlitchar(yytext[0]); }
+<qident>\n { yyerror("unexpected newline in quoted identifier"); }
+<qident><<EOF>> { yyerror("unterminated quoted identifier"); }
+
+ /* SQL blocks: { UPDATE ... } */
+ /* We trim leading/trailing whitespace, otherwise they're unprocessed */
+"{"{space}* {
+
+ litbufpos = 0;
+ BEGIN(sql);
+ }
+<sql>{space}*"}" {
+ litbuf[litbufpos] = '\0';
+ yylval.str = pg_strdup(litbuf);
+ BEGIN(INITIAL);
+ return(sqlblock);
+ }
+<sql>. {
+ addlitchar(yytext[0]);
+ }
+<sql>\n {
+ yyline++;
+ addlitchar(yytext[0]);
+ }
+<sql><<EOF>> {
+ yyerror("unterminated sql block");
+ }
+
+ /* Numbers and punctuation */
+{digit}+ {
+ yylval.integer = atoi(yytext);
+ return INTEGER;
+ }
+
+{self} { return yytext[0]; }
+
+ /* Anything else is an error */
+. {
+ fprintf(stderr, "syntax error at line %d: unexpected character \"%s\"\n", yyline, yytext);
+ exit(1);
+ }
+%%
+
+/* LCOV_EXCL_STOP */
+
+static void
+addlitchar(char c)
+{
+ /* We must always leave room to add a trailing \0 */
+ if (litbufpos >= litbufsize - 1)
+ {
+ /* Double the size of litbuf if it gets full */
+ litbufsize += litbufsize;
+ litbuf = pg_realloc(litbuf, litbufsize);
+ }
+ litbuf[litbufpos++] = c;
+}
+
+void
+yyerror(const char *message)
+{
+ fprintf(stderr, "%s at line %d\n", message, yyline);
+ exit(1);
+}