problem with create function and drop type

From: chenyanfei <postgresql_2016(at)163(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: problem with create function and drop type
Date: 2020-11-12 16:24:16
Message-ID: 1605198256689-0.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

【Version】I use the source code compile the database(dot)[postgres(at)bogon ~]$ psql
postgrespsql (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 $$beginend;$$ LANGUAGE plpgsql;We get the error when we query the
function definitionpostgres=# drop function if exists test_function;DROP
FUNCTIONpostgres=# drop type if exists test_type;NOTICE: type "test_type"
does not exist, skippingDROP TYPEpostgres=# create type test_type as (a
varchar);CREATE TYPEpostgres=# create or replace function test_function(t1
test_type[])postgres-# returns integer as $$postgres$# beginpostgres$#
end;postgres$# $$ LANGUAGE plpgsql;CREATE FUNCTIONpostgres=# \df2020-11-13
00:18:49.567 CST [11000] ERROR: cache lookup failed for type
163892020-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
successpostgres=# drop function if exists test_function;NOTICE: function
test_function() does not exist, skippingDROP FUNCTIONpostgres=# drop type if
exists test_type;DROP TYPEI 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: https://www.postgresql-archive.org/PostgreSQL-bugs-f2117394.html

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2020-11-12 17:29:12 Re: BUG #16713: Can't load server
Previous Message PG Bug reporting form 2020-11-12 15:59:21 BUG #16713: Can't load server