8000 Add test for CREATE INDEX CONCURRENTLY with not-so-immutable predicate · postgrespro/postgres@38ca11a · GitHub
[go: up one dir, main page]

Skip to content

Commit 38ca11a

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 08acba5 commit 38ca11a

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
@@ -2529,6 +2529,18 @@ BEGIN;
25292529
CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1);
25302530
ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
25312531
COMMIT;
2532+
-- test where predicate is able to do a transactional update during
2533+
-- a concurrent build before switching pg_index state flags.
2534+
CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE
2535+
LANGUAGE plpgsql AS $$
2536+
BEGIN
2537+
EXECUTE 'SELECT txid_current()';
2538+
RETURN true;
2539+
END; $$;
2540+
CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1)
2541+
WHERE predicate_stable();
2542+
DROP INDEX concur_index8;
2543+
DROP FUNCTION predicate_stable();
25322544
-- But you can do a regular index build in a transaction
25332545
BEGIN;
25342546
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
@@ -805,11 +805,22 @@ CREATE INDEX CONCURRENTLY concur_index4 on concur_heap(f2) WHERE f1='a';
805805
CREATE INDEX CONCURRENTLY concur_index5 on concur_heap(f2) WHERE f1='x';
806806
-- here we also check that you can default the index name
807807
CREATE INDEX CONCURRENTLY on concur_heap((f2||f1));
808-
809808
-- You can't do a concurrent index build in a transaction
810809
BEGIN;
811810
CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1);
812811
COMMIT;
812+
-- test where predicate is able to do a transactional update during
813+
-- a concurrent build before switching pg_index state flags.
814+
CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE
815+
LANGUAGE plpgsql AS $$
816+
BEGIN
817+
EXECUTE 'SELECT txid_current()';
818+
RETURN true;
819+
END; $$;
820+
CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1)
821+
WHERE predicate_stable();
822+
DROP INDEX concur_index8;
823+
DROP FUNCTION predicate_stable();
813824

814825
-- But you can do a regular index build in a transaction
815826
BEGIN;

0 commit comments

Comments
 (0)
0