pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Albrecht Dreß <albrecht.dress@arcor.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Error “cache lookup failed for function”
Date: Thu, 20 Feb 2020 13:57:07 -0500
Message-ID: <17817.1582225027@sss.pgh.pa.us> (raw)
In-Reply-To: <16784.1582223573@sss.pgh.pa.us>
References: <NX26BD7O.SQ6NCQDL.Z4KK4FBY@HXCHZXMY.EBBFSJQH.OUMOBSJN>
	<16784.1582223573@sss.pgh.pa.us>

I wrote:
> It does seem a bit annoying that something in plpgsql is apparently
> doing a fresh catalog lookup to find information that likely was
> already cached at the start of function execution.  But I think that's
> a performance deficiency, not a bug per se.

I reproduced this issue locally (to avoid race conditions, I just had the
function drop itself ;-)) and traced the site of the failure to this
bit in plpgsql function exit:

                /*
                 * Need to look up the expected result type.  XXX would be
                 * better to cache the tupdesc instead of repeating
                 * get_call_result_type(), but the only easy place to save it
                 * is in the PLpgSQL_function struct, and that's too
                 * long-lived: composite types could change during the
                 * existence of a PLpgSQL_function.
                 */
                switch (get_call_result_type(fcinfo, &resultTypeId, &tupdesc))

The catalog access inside get_call_result_type is fairly essential,
because this function has OUT parameters, so its pg_proc row is the
ultimate source of truth about what it returns.  We could imagine
caching the info earlier during function execution, but as the comment
says, that has its own failure modes ... and they're more important
ones in practice.  So I'm afraid there's not much to be done to
improve this.

			regards, tom lane





view thread (11+ messages)  latest in thread

Message-ID: <17817.1582225027@sss.pgh.pa.us>
Permalink:  ../17817.1582225027@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17817.1582225027@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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, albrecht.dress@arcor.de
  Subject: Re: Error “cache lookup failed for function”
  In-Reply-To: <17817.1582225027@sss.pgh.pa.us>
  References: <NX26BD7O.SQ6NCQDL.Z4KK4FBY@HXCHZXMY.EBBFSJQH.OUMOBSJN> <16784.1582223573@sss.pgh.pa.us> <17817.1582225027@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