From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Lewis <mlewis@entrata.com>
Cc: v.brusa@joinsnc.com, PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: temp table same name real table
Date: Wed, 30 Sep 2020 10:41:29 -0400
Message-ID: <841734.1601476889@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHOFxGrLCS9S4Ds0eaH5m_NOmEDxpNjwGz=TzB96034riy+ihA@mail.gmail.com>
References: <30bcf5f9-239c-ced7-1518-1c4709c0e697@joinsnc.com>
<CAHOFxGrLCS9S4Ds0eaH5m_NOmEDxpNjwGz=TzB96034riy+ihA@mail.gmail.com>
Michael Lewis <mlewis@entrata.com> writes:
> IMO, you are asking for strange behavior when you overload a table name.
> I expect that one of the people who work down deep down in the code will
> say it is a caching thing that saves system table lookups.
Yeah, I think that on the second call, plpgsql caches a query plan that
references the permanent table, and then it sees no reason to reconsider
that plan on the third call. (Change of search_path is one of the
conditions that would prompt throwing away the cached plan, which
fits that part of the report. But creating a temp table that happens
to shadow a real table is not one.)
If you really really need to do this, I'd counsel using EXECUTE to
ensure no caching happens. But I concur with Michael that it's
fundamentally a bad idea.
regards, tom lane
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, mlewis@entrata.com
Subject: Re: temp table same name real table
In-Reply-To: <841734.1601476889@sss.pgh.pa.us>
References: <30bcf5f9-239c-ced7-1518-1c4709c0e697@joinsnc.com> <CAHOFxGrLCS9S4Ds0eaH5m_NOmEDxpNjwGz=TzB96034riy+ihA@mail.gmail.com> <841734.1601476889@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