Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 95C559FB25F for ; Tue, 6 Mar 2007 15:20:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 16616-09 for ; Tue, 6 Mar 2007 15:19:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from core.softwarium.net (core.softwarium.net [212.110.147.5]) by postgresql.org (Postfix) with ESMTP id ACCB19FB256 for ; Tue, 6 Mar 2007 15:20:00 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by core.softwarium.net (Postfix) with ESMTP id A2286198099; Tue, 6 Mar 2007 21:19:14 +0200 (EET) Received: from core.softwarium.net ([127.0.0.1]) by localhost (core [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 22706-05; Tue, 6 Mar 2007 21:19:11 +0200 (EET) Received: from [212.110.147.73] (gwynn.cris.net [212.110.147.73]) by core.softwarium.net (Postfix) with ESMTP id 2DA55198096; Tue, 6 Mar 2007 21:19:11 +0200 (EET) Message-ID: <45EDC010.2050508@commandprompt.com> Date: Tue, 06 Mar 2007 21:25:04 +0200 From: andyk User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: pgsql-hackers@postgresql.org, tgl@sss.pgh.pa.us Subject: Re: Plan invalidation vs. unnamed prepared statements References: <6080.1173201777@sss.pgh.pa.us> <87fy8i9rkv.fsf@stark.xeocode.com> <6706.1173204882@sss.pgh.pa.us> In-Reply-To: <6706.1173204882@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at softwarium.net X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.061 tagged_above=0 required=5 tests=AWL, BAYES_50 X-Spam-Level: X-Archive-Number: 200703/432 X-Sequence-Number: 99916 Tom Lane wrote: > Gregory Stark writes: > >> Can we forcibly discard it if *any* messages are received that might >> invalidate a plan? So basically it would work fine unless anyone in the system >> does any DDL at all? I guess that has the downside of introducing random >> unpredictable failures. >> > > Ugh :-( > > >> Or stash the query string and replan it (possibly in the query cache this >> time) if someone executes it a second time? >> > > I think that's either my plan A or C. > > The main problem with uncontrolled replanning is that there's no way to > detect a change in the query properties. For example suppose the query > is "SELECT * FROM foo" and we've already told the client (via Describe > Statement) that that returns two integer columns. If an inval now > arrives because of "ALTER TABLE foo ADD COLUMN" (or perhaps worse, ALTER > COLUMN TYPE), we've got a problem. If we just blindly replan then we'll > return tuples that do not match the previously given row description, > which will certainly break most clients. > It will always be a good question what user expects as a result of 'SELECT * FROM...'. For example, client may use ODBC or some other interface for DB communication. One the first step he retrieves information about the table and it's datatypes, on the second tries to fetch rows (using interface functions). Client application won't even guess that table could be changed between these two steps. It's impossible to avoid such situations, because we can't know how the user retrieves information about results he will expect. > The plan caching module has enough infrastructure to detect and complain > about these sorts of situations, and it also knows how to manage lock > acquisition so that once we've decided a plan is still good, the tables > won't change underneath us while we use the plan. I don't see any way > to make comparable guarantees without the overhead that goes with the > cache manager. > It's a required overhead. Result should be valid on the execution time, not on prepare. Cache manager is the best for this. > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster >