Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ce8949c

Browse files
committed
Add test for CREATE INDEX CONCURRENTLY with not-so-immutable predicate
83158f7 has improved index_set_state_flags() so as it is possible to use transactional updates when updating pg_index state flags, but there was not really a test case which stressed directly the possibility it fixed. This commit adds such a test, using a predicate that looks valid in appearance but calls a stable function. Author: Andrey Lepikhov Discussion: https://postgr.es/m/9b905019-5297-7372-0ad2-e1a4bb66a719@postgrespro.ru Backpatch-through: 9.6
1 parent e52f7cb commit ce8949c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/test/regress/expected/create_index.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,18 @@ BEGIN;
13931393
CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1);
13941394
ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
13951395
COMMIT;
1396+
-- test where predicate is able to do a transactional update during
1397+
-- a concurrent build before switching pg_index state flags.
1398+
CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE
1399+
LANGUAGE plpgsql AS $$
1400+
BEGIN
1401+
EXECUTE 'SELECT txid_current()';
1402+
RETURN true;
1403+
END; $$;
1404+
CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1)
1405+
WHERE predicate_stable();
1406+
DROP INDEX concur_index8;
1407+
DROP FUNCTION predicate_stable();
13961408
-- But you can do a regular index build in a transaction
13971409
BEGIN;
13981410
CREATE INDEX std_index on concur_heap(f2);

src/test/regress/sql/create_index.sql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,22 @@ CREATE INDEX CONCURRENTLY concur_index4 on concur_heap(f2) WHERE f1='a';
481481
CREATE INDEX CONCURRENTLY concur_index5 on concur_heap(f2) WHERE f1='x';
482482
-- here we also check that you can default the index name
483483
CREATE INDEX CONCURRENTLY on concur_heap((f2||f1));
484-
485484
-- You can't do a concurrent index build in a transaction
486485
BEGIN;
487486
CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1);
488487
COMMIT;
488+
-- test where predicate is able to do a transactional update during
489+
-- a concurrent build before switching pg_index state flags.
490+
CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE
491+
LANGUAGE plpgsql AS $$
492+
BEGIN
493+
EXECUTE 'SELECT txid_current()';
494+
RETURN true;
495+
END; $$;
496+
CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1)
497+
WHERE predicate_stable();
498+
DROP INDEX concur_index8;
499+
DROP FUNCTION predicate_stable();
489500

490501
-- But you can do a regular index build in a transaction
491502
BEGIN;

0 commit comments

Comments
 (0)