Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 45AF49FB225 for ; Tue, 6 Mar 2007 14:45:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 08666-02 for ; Tue, 6 Mar 2007 14:44:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id 5A5DA9FB3A4 for ; Tue, 6 Mar 2007 14:45:00 -0400 (AST) Received: (qmail 6668 invoked from network); 6 Mar 2007 18:44:58 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.14?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 6 Mar 2007 18:44:58 -0000 In-Reply-To: <6706.1173204882@sss.pgh.pa.us> References: <6080.1173201777@sss.pgh.pa.us> <87fy8i9rkv.fsf@stark.xeocode.com> <6706.1173204882@sss.pgh.pa.us> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <32534E13-296F-4694-AC28-45F8DBEDA480@fastcrypt.com> Cc: Gregory Stark , pgsql-hackers@postgreSQL.org, pgsql-jdbc@postgreSQL.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: [JDBC] Plan invalidation vs. unnamed prepared statements Date: Tue, 6 Mar 2007 13:45:10 -0500 To: Tom Lane X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/428 X-Sequence-Number: 99912 I think C is how the JDBC driver is written. We name the statements if they have been used more than prepareThreshold times. So we have a mechanism by which to allow statements to be cached, or not. Dave On 6-Mar-07, at 1:14 PM, 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. > > 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. > > regards, tom lane > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster >