On Thu, May 22, 2025 at 10:25 AM jian he <jian.universal...@gmail.com> wrote: > hi. earlier, i didn't check patch 0002.
i think in AlterFunction add /* Lock the function so nobody else can do anything with it. */ LockDatabaseObject(ProcedureRelationId, funcOid, 0, AccessExclusiveLock); right after funcOid = LookupFuncWithArgs(stmt->objtype, stmt->func, false); should be fine. attached are some simple isolation tests for CREATE OR REPLACE FUNCTION, ALTER FUNCTION, DROP FUNCTION.
From 040c5f739dbd4e5640ba40ae7c30b86d312bd004 Mon Sep 17 00:00:00 2001 From: jian he <jian.universal...@gmail.com> Date: Fri, 23 May 2025 10:33:39 +0800 Subject: [PATCH v1 1/1] isolation tests for concurrent change FUNCTION definition discussion: https://postgr.es/m/20250331200057.00a62760966a821d484ea...@sraoss.co.jp --- .../isolation/expected/change-function.out | 39 +++++++++++++++++++ src/test/isolation/isolation_schedule | 1 + src/test/isolation/specs/change-function.spec | 29 ++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/test/isolation/expected/change-function.out create mode 100644 src/test/isolation/specs/change-function.spec diff --git a/src/test/isolation/expected/change-function.out b/src/test/isolation/expected/change-function.out new file mode 100644 index 00000000000..812346f2fc1 --- /dev/null +++ b/src/test/isolation/expected/change-function.out @@ -0,0 +1,39 @@ +unused step name: r1 +Parsed test spec with 2 sessions + +starting permutation: b1 b2 create_f1 alter_f s1 c1 r2 +step b1: BEGIN; +step b2: BEGIN; +step create_f1: CREATE OR REPLACE FUNCTION f1() RETURNS INT LANGUAGE sql AS $$ SELECT 2;$$; +step alter_f: ALTER FUNCTION f1() COST 71; <waiting ...> +step s1: SELECT pg_get_functiondef(oid) FROM pg_proc pp WHERE proname = 'f1'; +pg_get_functiondef +-------------------------------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION public.f1() + RETURNS integer + LANGUAGE sql +AS $function$ SELECT 2;$function$ + +(1 row) + +step c1: COMMIT; +step alter_f: <... completed> +step r2: ROLLBACK; + +starting permutation: b1 b2 drop_f create_f1 c2 c1 +step b1: BEGIN; +step b2: BEGIN; +step drop_f: DROP FUNCTION f1; +step create_f1: CREATE OR REPLACE FUNCTION f1() RETURNS INT LANGUAGE sql AS $$ SELECT 2;$$; <waiting ...> +step c2: COMMIT; +step create_f1: <... completed> +step c1: COMMIT; + +starting permutation: b1 b2 create_f2 create_f1 c2 c1 +step b1: BEGIN; +step b2: BEGIN; +step create_f2: CREATE OR REPLACE FUNCTION f1() RETURNS INT LANGUAGE sql AS $$ SELECT 3;$$; +step create_f1: CREATE OR REPLACE FUNCTION f1() RETURNS INT LANGUAGE sql AS $$ SELECT 2;$$; <waiting ...> +step c2: COMMIT; +step create_f1: <... completed> +step c1: COMMIT; diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule index e3c669a29c7..99e3ce780a7 100644 --- a/src/test/isolation/isolation_schedule +++ b/src/test/isolation/isolation_schedule @@ -116,3 +116,4 @@ test: serializable-parallel-2 test: serializable-parallel-3 test: matview-write-skew test: lock-nowait +test: change-function diff --git a/src/test/isolation/specs/change-function.spec b/src/test/isolation/specs/change-function.spec new file mode 100644 index 00000000000..987e1ee7cf1 --- /dev/null +++ b/src/test/isolation/specs/change-function.spec @@ -0,0 +1,29 @@ +setup +{ + CREATE OR REPLACE FUNCTION f1() RETURNS INT LANGUAGE sql AS $$ SELECT 1;$$; +} + +teardown +{ + DROP FUNCTION IF EXISTS f1; +} + +session "s1" +step b1 { BEGIN;} +step create_f1 { CREATE OR REPLACE FUNCTION f1() RETURNS INT LANGUAGE sql AS $$ SELECT 2;$$; } +step c1 { COMMIT; } +step s1 { SELECT pg_get_functiondef(oid) FROM pg_proc pp WHERE proname = 'f1'; } +step r1 { ROLLBACK; } + +session "s2" +step b2 { BEGIN;} +step alter_f { ALTER FUNCTION f1() COST 71; } +step create_f2 { CREATE OR REPLACE FUNCTION f1() RETURNS INT LANGUAGE sql AS $$ SELECT 3;$$; } +step drop_f { DROP FUNCTION f1; } +step c2 { COMMIT; } +step r2 { ROLLBACK; } + +# Basic effects +permutation b1 b2 create_f1 alter_f s1 c1 r2 +permutation b1 b2 drop_f create_f1 c2 c1 +permutation b1 b2 create_f2 create_f1 c2 c1 -- 2.34.1