Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B9756D7B2C4 for ; Mon, 5 Dec 2011 02:24:11 -0400 (AST) Received: from mail-qy0-f174.google.com ([209.85.216.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RXRyD-0006Xy-5a for pgsql-bugs@postgresql.org; Mon, 05 Dec 2011 06:24:11 +0000 Received: by qcqz2 with SMTP id z2so1245848qcq.19 for ; Sun, 04 Dec 2011 22:23:55 -0800 (PST) Received: by 10.229.65.3 with SMTP id g3mr1689253qci.23.1323066235796; Sun, 04 Dec 2011 22:23:55 -0800 (PST) Received: from tornado.leadboat.com (ip68-230-222-48.rd.hr.cox.net. [68.230.222.48]) by mx.google.com with ESMTPS id 8sm23655892qaf.9.2011.12.04.22.23.54 (version=SSLv3 cipher=OTHER); Sun, 04 Dec 2011 22:23:55 -0800 (PST) Date: Mon, 5 Dec 2011 01:23:52 -0500 From: Noah Misch To: Tom Lane Cc: Jeff Davis , pgsql-bugs@postgresql.org Subject: Re: possible bug seen with -DCLOBBER_CACHE_ALWAYS and changing GUCs Message-ID: <20111205062352.GC10035@tornado.leadboat.com> References: <4161.1322701822@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4161.1322701822@sss.pgh.pa.us> User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201112/40 X-Sequence-Number: 31851 On Wed, Nov 30, 2011 at 08:10:22PM -0500, Tom Lane wrote: > Jeff Davis writes: > > SQL: > > set datestyle to postgres,us; > > prepare stmt as select '02-01-2011'::date::text; > > execute stmt; > > set datestyle to postgres,euro; > > execute stmt; > > deallocate stmt; > > > The results I get with normal debug compilation are: > > > SET > > PREPARE > > text > > ------------ > > 02-01-2011 > > (1 row) > > > SET > > text > > ------------ > > 01-02-2011 > > (1 row) > > > DEALLOCATE > > But with -DCLOBBER_CACHE_ALWAYS and -DRELCACHE_FORCE_RELEASE, I get: > > > SET > > PREPARE > > text > > ------------ > > 02-01-2011 > > (1 row) > > > SET > > text > > ------------ > > 02-01-2011 > > (1 row) > > > DEALLOCATE > > > Which one of those results is correct? > > I believe what is happening in the second case is that the query is > getting re-parse-analyzed, from scratch, and since now datestyle is > different (DMY not MDY), the date literal gets interpreted differently. > You could argue it either way as to which result is "more correct", > but I doubt we're going to try to do something about that. Best advice > is to avoid ambiguous input, or if you can't, at least avoid flipping > your datestyle on the fly. One could defend consistent use of either the PREPARE-time DateStyle or the EXECUTE-time DateStyle to interpret literals. However, using the value as of the last RevalidateCachedQuery(), its timing independent of any GUC change, is an implementation artifact with no redeeming value for the user. This hazard also arises around IntervalStyle, TimeZone, sql_inheritance, transform_null_equals, and array_nulls. Implementation challenges aside, I'd contend for always using PREPARE-time values during parse analysis. That's more consistent with the user-visible consequences of changing search_path or standard_conforming_strings. That said, I don't have in mind a cure clearly less ugly than the disease. nm