diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 299512b5d4d..741bae206b0 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -824,11 +824,14 @@ DefineIndex(Oid relationId, * doing CREATE INDEX CONCURRENTLY, which would see our snapshot as one * they must wait for. But first, save the snapshot's xmin to use as * limitXmin for GetCurrentVirtualXIDs(). + * + * Our catalog snapshot could have the same effect, so drop that one too. */ limitXmin = snapshot->xmin; PopActiveSnapshot(); UnregisterSnapshot(snapshot); + InvalidateCatalogSnapshot(); /* * The index is now valid in the sense that it contains all currently diff --git a/src/test/isolation/expected/multiple-cic.out b/src/test/isolation/expected/multiple-cic.out new file mode 100644 index 00000000000..cc579403925 --- /dev/null +++ b/src/test/isolation/expected/multiple-cic.out @@ -0,0 +1,19 @@ +Parsed test spec with 2 sessions + +starting permutation: s2l s1i s2i +step s2l: SELECT pg_advisory_lock(281457); +pg_advisory_lock + + +step s1i: + CREATE INDEX CONCURRENTLY mcic_one_pkey ON mcic_one (id) + WHERE lck_shr(281457); + +step s2i: + CREATE INDEX CONCURRENTLY mcic_two_pkey ON mcic_two (id) + WHERE unlck(); + +step s1i: <... completed> +s1 + + diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule index f1af282853f..413cf028f16 100644 --- a/src/test/isolation/isolation_schedule +++ b/src/test/isolation/isolation_schedule @@ -52,6 +52,7 @@ test: skip-locked-2 test: skip-locked-3 test: skip-locked-4 test: drop-index-concurrently-1 +test: multiple-cic test: alter-table-1 test: alter-table-2 test: alter-table-3 diff --git a/src/test/isolation/specs/multiple-cic.spec b/src/test/isolation/specs/multiple-cic.spec new file mode 100644 index 00000000000..a7ba4eb4fd1 --- /dev/null +++ b/src/test/isolation/specs/multiple-cic.spec @@ -0,0 +1,40 @@ +# 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 pg_advisory_unlock_all() AS "s1"; } + + +session "s2" +step "s2l" { SELECT pg_advisory_lock(281457); } +step "s2i" { + CREATE INDEX CONCURRENTLY mcic_two_pkey ON mcic_two (id) + WHERE unlck(); + } + +permutation "s2l" "s1i" "s2i"