Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 6B9A31337B81 for ; Wed, 11 May 2011 03:22:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 60024-01 for ; Wed, 11 May 2011 06:22:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pw0-f46.google.com (mail-pw0-f46.google.com [209.85.160.46]) by mail.postgresql.org (Postfix) with ESMTP id 9AAAA1337B6E for ; Wed, 11 May 2011 03:22:00 -0300 (ADT) Received: by pwi15 with SMTP id 15so108160pwi.19 for ; Tue, 10 May 2011 23:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=IfouEzGnLQDNVVun8t+MhrWjZ9Zxz74EKW7HsrvslZI=; b=UKJQbzWVC1JumWbzM1Z4tEWo8jYe07klvQGZjFoSArCon0zL2mO9gtySsrzqqWRVLc vyUw/dRm72iW31sQ2WX7bXboLZ2XTyaxU9hWn6ld84FwnnhKpU/2KOO31HtmN7O3EewD jvSCT7TKDGdNVsbNDyn8wESER1Ta3qtkxbwsA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=B6wt5hn0Qu1kn6GtyMyzE9i/ktGKvvY7rW8PWgnCXlLYy+Y+isLBGfw5e6ErzieHgj GkoRFJG70HCRYLHKB8wnJCYr1fGa732yiqZjATZBSNrrjax8FAXr/QWOnW8DFiJAhBL2 kHOgsASH1Vy7VMyqrpPyvH5FFeee0t5jpcMMU= MIME-Version: 1.0 Received: by 10.143.21.38 with SMTP id y38mr3420867wfi.342.1305094919542; Tue, 10 May 2011 23:21:59 -0700 (PDT) Received: by 10.142.57.17 with HTTP; Tue, 10 May 2011 23:21:59 -0700 (PDT) In-Reply-To: <19015.1305087444@sss.pgh.pa.us> References: <201105101229.p4ACTpnU013375@wwwmaster.postgresql.org> <19015.1305087444@sss.pgh.pa.us> Date: Wed, 11 May 2011 08:21:59 +0200 Message-ID: Subject: Re: BUG #6019: invalid cached plan on inherited table From: Maxo EtDirloth To: Tom Lane Cc: pgsql-bugs@postgresql.org Content-Type: multipart/alternative; boundary=00504502cb1f13d6d204a2fa1799 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.897 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201105/88 X-Sequence-Number: 30227 --00504502cb1f13d6d204a2fa1799 Content-Type: text/plain; charset=ISO-8859-1 No big deal to me, I just couldn't verify that it may occur only within single transaction - not even in documentation. thanks for the answer .et. On Wed, May 11, 2011 at 6:17 AM, Tom Lane wrote: > "" writes: > > Cached execution plan of SQL stored procedure (which select from > inherited > > table) executed from within PLPGSQL function is used even when > inheritance > > descendant is already removed. > > Don't hold your breath waiting for a fix for that :-(. There isn't any > support for detecting plan-invalidation events for SQL-language > functions, and in most situations it would be overkill because the plans > are only cached for the lifespan of one calling query anyway. The only > case where the plan could survive longer is this specific example of a > SQL function called from a "simple expression" in a plpgsql function, > and even then it only survives for one complete transaction. > > I've thought for some time that SQL functions should be reimplemented > to cache information more the way plpgsql functions do, ie, with a > session-lifespan data structure for each function. If we did that > and made the individual query plans be stored in plancache, then > invalidation of this type would occur automatically --- and, not > insignificantly, the plans would survive long enough to pay back the > added overhead of tracking invalidation causes for them. > > A somewhat related point is that people have occasionally complained > because all the queries in a SQL function are run through parse analysis > at once, causing things like > > CREATE TABLE foo ... ; > INSERT INTO foo ... ; > > to not work because the second command is analyzed before the first is > executed. If we were reimplementing SQL functions then it'd make sense > to try to do something about that at the same time. > > None of this is on the TODO list, but I'll go fix that momentarily. > > regards, tom lane > --00504502cb1f13d6d204a2fa1799 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable No big deal to me, I just couldn't verify that it may occur only within= single transaction - not even in documentation.

thanks for the answ= er
.et.


On Wed, May 11, 2011 at 6:= 17 AM, Tom Lane <= tgl@sss.pgh.pa.us> wrote:
"" <= etdirloth@gmail.com> writes:<= br> > Cached execution plan of SQL stored procedure (which select from inher= ited
> table) executed from within PLPGSQL function is used even when inherit= ance
> descendant is already removed.

Don't hold your breath waiting for a fix for that :-(. =A0There isn'= ;t any
support for detecting plan-invalidation events for SQL-language
functions, and in most situations it would be overkill because the plans are only cached for the lifespan of one calling query anyway. =A0The only case where the plan could survive longer is this specific example of a
SQL function called from a "simple expression" in a plpgsql funct= ion,
and even then it only survives for one complete transaction.

I've thought for some time that SQL functions should be reimplemented to cache information more the way plpgsql functions do, ie, with a
session-lifespan data structure for each function. =A0If we did that
and made the individual query plans be stored in plancache, then
invalidation of this type would occur automatically --- and, not
insignificantly, the plans would survive long enough to pay back the
added overhead of tracking invalidation causes for them.

A somewhat related point is that people have occasionally complained
because all the queries in a SQL function are run through parse analysis at once, causing things like

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0CREATE TABLE foo ... ;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0INSERT INTO foo ... ;

to not work because the second command is analyzed before the first is
executed. =A0If we were reimplementing SQL functions then it'd make sen= se
to try to do something about that at the same time.

None of this is on the TODO list, but I'll go fix that momentarily.

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0regards, tom lane

--00504502cb1f13d6d204a2fa1799--