diff options
author | Michael Paquier <michael@paquier.xyz> | 2021-06-28 11:17:25 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2021-06-28 11:17:25 +0900 |
commit | 5160d5bb16625e154857ad7f717ddaee118b3fd3 (patch) | |
tree | 9fc03c8e2f856b73975310f10e77482d6e3cadf9 /src | |
parent | 3c465883b8a6828006978b43658c1b528a59a959 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/test/regress/expected/create_index.out | 12 | ||||
-rw-r--r-- | src/test/regress/sql/create_index.sql | 13 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index 0950f99f86c..c0a30a0396f 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -2472,6 +2472,18 @@ BEGIN; CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1); ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block COMMIT; +-- test where predicate is able to do a transactional update during +-- a concurrent build before switching pg_index state flags. +CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE +LANGUAGE plpgsql AS $$ +BEGIN + EXECUTE 'SELECT txid_current()'; + RETURN true; +END; $$; +CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1) + WHERE predicate_stable(); +DROP INDEX concur_index8; +DROP FUNCTION predicate_stable(); -- But you can do a regular index build in a transaction BEGIN; CREATE INDEX std_index on concur_heap(f2); diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql index a852e7a1dbf..9a18bfa458e 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -775,11 +775,22 @@ CREATE INDEX CONCURRENTLY concur_index4 on concur_heap(f2) WHERE f1='a'; CREATE INDEX CONCURRENTLY concur_index5 on concur_heap(f2) WHERE f1='x'; -- here we also check that you can default the index name CREATE INDEX CONCURRENTLY on concur_heap((f2||f1)); - -- You can't do a concurrent index build in a transaction BEGIN; CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1); COMMIT; +-- test where predicate is able to do a transactional update during +-- a concurrent build before switching pg_index state flags. +CREATE FUNCTION predicate_stable() RETURNS bool IMMUTABLE +LANGUAGE plpgsql AS $$ +BEGIN + EXECUTE 'SELECT txid_current()'; + RETURN true; +END; $$; +CREATE INDEX CONCURRENTLY concur_index8 ON concur_heap (f1) + WHERE predicate_stable(); +DROP INDEX concur_index8; +DROP FUNCTION predicate_stable(); -- But you can do a regular index build in a transaction BEGIN; |