Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 3F9C71337B8B for ; Wed, 11 May 2011 01:17:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 79473-08 for ; Wed, 11 May 2011 04:17:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 2BDAB1337B69 for ; Wed, 11 May 2011 01:17:28 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p4B4HOnb019016; Wed, 11 May 2011 00:17:24 -0400 (EDT) To: "" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6019: invalid cached plan on inherited table In-reply-to: <201105101229.p4ACTpnU013375@wwwmaster.postgresql.org> References: <201105101229.p4ACTpnU013375@wwwmaster.postgresql.org> Comments: In-reply-to "" message dated "Tue, 10 May 2011 12:29:51 +0000" Date: Wed, 11 May 2011 00:17:24 -0400 Message-ID: <19015.1305087444@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/79 X-Sequence-Number: 30218 "" 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