Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 699B79FB6AF; Tue, 6 Mar 2007 14:14:51 -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 95190-07; Tue, 6 Mar 2007 14:14:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D898D9FB9CE; Tue, 6 Mar 2007 14:14:44 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l26IEgf4006707; Tue, 6 Mar 2007 13:14:43 -0500 (EST) To: Gregory Stark cc: pgsql-hackers@postgreSQL.org, pgsql-jdbc@postgreSQL.org Subject: Re: Plan invalidation vs. unnamed prepared statements In-reply-to: <87fy8i9rkv.fsf@stark.xeocode.com> References: <6080.1173201777@sss.pgh.pa.us> <87fy8i9rkv.fsf@stark.xeocode.com> Comments: In-reply-to Gregory Stark message dated "Tue, 06 Mar 2007 18:04:16 +0000" Date: Tue, 06 Mar 2007 13:14:42 -0500 Message-ID: <6706.1173204882@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.06 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200703/421 X-Sequence-Number: 99905 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