problem with create function and drop type - Mailing list pgsql-bugs

From chenyanfei
Subject problem with create function and drop type
Date
Msg-id 1605198256689-0.post@n3.nabble.com
Whole thread Raw
List pgsql-bugs
【Version】 I use the source code compile the database. [postgres@bogon ~]$ psql postgres psql (14devel) Type "help" for help. postgres=# select version(); version -------------------------------------------------------------------------------- PostgreSQL 14devel on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit 【Problem】 When we test the concurrent commands, we encounter a problem about the the function. The test case like this: drop function if exists test_function; drop type if exists test_type; create type test_type as (a varchar); create or replace function test_function(t1 test_type[]) returns integer as $$ begin end; $$ LANGUAGE plpgsql; We get the error when we query the function definition postgres=# drop function if exists test_function; DROP FUNCTION postgres=# drop type if exists test_type; NOTICE: type "test_type" does not exist, skipping DROP TYPE postgres=# create type test_type as (a varchar); CREATE TYPE postgres=# create or replace function test_function(t1 test_type[]) postgres-# returns integer as $$ postgres$# begin postgres$# end; postgres$# $$ LANGUAGE plpgsql; CREATE FUNCTION postgres=# \df 2020-11-13 00:18:49.567 CST [11000] ERROR: cache lookup failed for type 16389 2020-11-13 00:18:49.567 CST [11000] STATEMENT: SELECT n.nspname as "Schema", p.proname as "Name", pg_catalog.pg_get_function_result(p.oid) as "Result data type", pg_catalog.pg_get_function_arguments(p.oid) as "Argument data types", CASE p.prokind WHEN 'a' THEN 'agg' WHEN 'w' THEN 'window' WHEN 'p' THEN 'proc' ELSE 'func' END as "Type" FROM pg_catalog.pg_proc p LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace WHERE pg_catalog.pg_function_is_visible(p.oid) AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' ORDER BY 1, 2, 4; ERROR: cache lookup failed for type 16389 【Analyze】 To reprocedure the problem, we anlayze our scripts like below. Accounting for the concurrent commands, we use the gdb tool to simulate two sessions. So we set a break point at pl_handler.c:514 /* Test-compile the function */ plpgsql_compile(fake_fcinfo, true); /* * Disconnect from SPI manager */ if ((rc = SPI_finish()) != SPI_OK_FINISH) elog(ERROR, "SPI_finish failed: %s", SPI_result_code_string(rc)); When the create command execute success afeter plpgsql_compile function, in other session we execute "drop type if exists test_type;" The drop command is success postgres=# drop function if exists test_function; NOTICE: function test_function() does not exist, skipping DROP FUNCTION postgres=# drop type if exists test_type; DROP TYPE I think the problem is that the drop type command can not query any depend informations through the pg_depend because the create command doesnot commit now, so it can drop the type. But the create command has done the last check work through plpgsql_compile function and will commit it now. However, because of the depend type has been dropped, so the function can not work now. But it also shows create successfully.

Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #16713: Can't load server
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #16713: Can't load server