Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38ca11a

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 usetransactional updates when updating pg_index state flags, but there wasnot really a test case which stressed directly the possibility it fixed.This commit adds such a test, using a predicate that looks valid inappearance but calls a stable function.Author: Andrey LepikhovDiscussion:https://postgr.es/m/9b905019-5297-7372-0ad2-e1a4bb66a719@postgrespro.ruBackpatch-through: 9.6
1 parent08acba5 commit38ca11a

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
CREATEINDEXCONCURRENTLY concur_index5on concur_heap(f2)WHERE f1='x';
806806
-- here we also check that you can default the index name
807807
CREATEINDEXCONCURRENTLYon concur_heap((f2||f1));
808-
809808
-- You can't do a concurrent index build in a transaction
810809
BEGIN;
811810
CREATEINDEXCONCURRENTLY concur_index7ON 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+
CREATEFUNCTIONpredicate_stable() RETURNS bool IMMUTABLE
815+
LANGUAGE plpgsqlAS $$
816+
BEGIN
817+
EXECUTE'SELECT txid_current()';
818+
RETURN true;
819+
END; $$;
820+
CREATEINDEXCONCURRENTLY concur_index8ON concur_heap (f1)
821+
WHERE predicate_stable();
822+
DROPINDEX concur_index8;
823+
DROPFUNCTION predicate_stable();
813824

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp