From 85ccd09759b06a383c89b985b45827e0c631186e Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Sat, 1 Aug 2026 18:30:22 -0400 Subject: [PATCH] Add isolation test for SET NOT NULL with an older snapshot --- .../expected/alter-table-set-not-null.out | 18 ++++++++++++ src/test/isolation/isolation_schedule | 1 + .../specs/alter-table-set-not-null.spec | 29 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/test/isolation/expected/alter-table-set-not-null.out create mode 100644 src/test/isolation/specs/alter-table-set-not-null.spec diff --git a/src/test/isolation/expected/alter-table-set-not-null.out b/src/test/isolation/expected/alter-table-set-not-null.out new file mode 100644 index 000000000..592b849e9 --- /dev/null +++ b/src/test/isolation/expected/alter-table-set-not-null.out @@ -0,0 +1,18 @@ +Parsed test spec with 2 sessions + +starting permutation: s1snap s2del s2nn s1read s1c +step s1snap: SELECT 1 AS snapshot_taken; +snapshot_taken +-------------- + 1 +(1 row) + +step s2del: DELETE FROM nn WHERE a IS NULL; +step s2nn: ALTER TABLE nn ALTER COLUMN a SET NOT NULL; +step s1read: SELECT a, b, c FROM nn; +a| b| c +-+--+-- + |42|43 +(1 row) + +step s1c: COMMIT; diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule index df8ce44ed..949cae989 100644 --- a/src/test/isolation/isolation_schedule +++ b/src/test/isolation/isolation_schedule @@ -95,6 +95,7 @@ test: alter-table-1 test: alter-table-2 test: alter-table-3 test: alter-table-4 +test: alter-table-set-not-null test: create-trigger test: sequence-ddl test: async-notify diff --git a/src/test/isolation/specs/alter-table-set-not-null.spec b/src/test/isolation/specs/alter-table-set-not-null.spec new file mode 100644 index 000000000..37f3dc03e --- /dev/null +++ b/src/test/isolation/specs/alter-table-set-not-null.spec @@ -0,0 +1,29 @@ +# ALTER TABLE - SET NOT NULL with an older snapshot +# +# SET NOT NULL validates the column by scanning only the rows visible to its +# own snapshot, and does not rewrite the table. A transaction holding an +# older snapshot can therefore still see a row whose column is null, and must +# continue to read that row correctly. + +setup +{ + CREATE TABLE nn (a int, b int, c int); + INSERT INTO nn VALUES (NULL, 42, 43); +} + +teardown +{ + DROP TABLE nn; +} + +session s1 +setup { BEGIN ISOLATION LEVEL REPEATABLE READ; } +step s1snap { SELECT 1 AS snapshot_taken; } +step s1read { SELECT a, b, c FROM nn; } +step s1c { COMMIT; } + +session s2 +step s2del { DELETE FROM nn WHERE a IS NULL; } +step s2nn { ALTER TABLE nn ALTER COLUMN a SET NOT NULL; } + +permutation s1snap s2del s2nn s1read s1c -- 2.53.0