Skip to content

Commit 09a69f6

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 642c069 commit 09a69f6

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
@@ -1397,6 +1397,18 @@ BEGIN;
13971397
CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1);
13981398
ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
13991399
COMMIT;
1400+
-- test where predicate is able to do a transactional update during
1401+
-- a concurrent build before switching pg_index state flags.
1402+
CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE
1403+
LANGUAGE plpgsql AS $$
1404+
BEGIN
1405+
EXECUTE 'SELECT txid_current()';
1406+
RETURN true;
1407+
END; $$;
1408+
CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1)
1409+
WHERE predicate_stable();
1410+
DROP INDEX concur_index8;
1411+
DROP FUNCTION predicate_stable();
14001412
-- But you can do a regular index build in a transaction
14011413
BEGIN;
14021414
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy