pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Rashid Abzalov <rashid.abzalov@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Prepared statement is not re-parsed after used type is re-created - ERROR: cache lookup failed for type NNN
Date: Tue, 30 Apr 2019 17:00:27 -0400
Message-ID: <25213.1556658027@sss.pgh.pa.us> (raw)
In-Reply-To: <CACrSCdHQndjyWQVAO9Ksh_SASHtoWqWnkG1WkPWvHstbetzPQg@mail.gmail.com>
References: <CACrSCdHQndjyWQVAO9Ksh_SASHtoWqWnkG1WkPWvHstbetzPQg@mail.gmail.com>

Rashid Abzalov <rashid.abzalov@gmail.com> writes:
> Steps to reproduce:
> *1)* Create type and function:
> create type pg_temp.temp_type AS (field varchar(64));

> create function pg_temp.test_func(param pg_temp.temp_type) returns
> temp_type as $$
> begin
>   param.field = 'qqq';
>   return param;
> end;
> $$ language plpgsql;

> *2)* Prepare and use them:
> PREPARE testplan (pg_temp.temp_type) AS
>     select * from pg_temp.test_func($1);
> EXECUTE testplan(('(qqq)')::pg_temp.temp_type);

> *3)* Drop type and function:
> drop function pg_temp.test_func(param pg_temp.temp_type);
> drop type pg_temp.temp_type;

So at this point you've deleted the type that is declared to be the
argument type of the prepared statement.  I don't think "reparse" is what
is called for here.  The prepared statement is busted and we shouldn't be
willing to execute it anymore.  As indeed we don't, though I'll grant you
that "cache lookup failed" is not the world's best error message for that.

If prepared statements were full-fledged database objects, we could
imagine hooking them into the DROP CASCADE logic so that you couldn't drop
the type without (implicitly or explicitly) doing "DEALLOCATE testplan".
I doubt anyone will care to do that though, as it'd make them far
heavier-weight than they are now.

My inclination, if we do anything at all about this, is just to add
something like

	if (!SearchSysCacheExists1(TYPEOID, ObjectIdGetDatum(expected_type_id)))
		ereport(ERROR, ... "prepared statement's argument type no longer exists");

in EvaluateParams.  But I can't get too excited about that.

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <25213.1556658027@sss.pgh.pa.us>
Permalink:  ../25213.1556658027@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25213.1556658027@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rashid.abzalov@gmail.com
  Subject: Re: Prepared statement is not re-parsed after used type is re-created - ERROR: cache lookup failed for type NNN
  In-Reply-To: <25213.1556658027@sss.pgh.pa.us>
  References: <CACrSCdHQndjyWQVAO9Ksh_SASHtoWqWnkG1WkPWvHstbetzPQg@mail.gmail.com> <25213.1556658027@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox