Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WFpa7-0007hF-2Z for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Feb 2014 18:39:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WFpa5-0005Yt-MG for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Feb 2014 18:39:45 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WFpa4-0005Yl-N5 for pgsql-bugs@postgresql.org; Tue, 18 Feb 2014 18:39:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WFpa2-0003xb-B4 for pgsql-bugs@postgresql.org; Tue, 18 Feb 2014 18:39:44 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s1IIdfAU008503; Tue, 18 Feb 2014 13:39:41 -0500 From: Tom Lane To: Joshua Yanovski cc: pgsql-bugs@postgresql.org Subject: Re: BUG #9227: Error on SELECT ROW OVERLAPS ROW with single ROW argument In-reply-to: <7822.1392746510@sss.pgh.pa.us> References: <20140215035549.24618.37927@wrigleys.postgresql.org> <10303.1392683593@sss.pgh.pa.us> <7547.1392745766@sss.pgh.pa.us> <7822.1392746510@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 18 Feb 2014 13:01:50 -0500" Date: Tue, 18 Feb 2014 13:39:41 -0500 Message-ID: <8502.1392748781@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org I wrote: > Joshua Yanovski writes: >> Great, thanks. Yeah, I was thinking about that too--I am not sure if >> there are any other examples of a time where Postgres deliberately >> duplicates an argument like that (maybe there could be a check for it >> to be a constexpr or something? But that information isn't available >> at this point in the analysis process). > Yeah, BETWEEN is like that. I'd like to fix it sometime, but it's > kind of problematic because of the risk of losing index optimizations > (which only understand x >= y and x <= z, not a hypothetical combined > node). Actually, it suddenly strikes me that there's a pretty simple answer to that. Have the parser generate a node representing BETWEEN, with three arguments. In the planner, *if* the first argument is non-volatile, replace the BETWEEN with "x >= y AND x <= z"; otherwise, leave it alone, and execute it as-is. This transformation is semantically correct and will still expose index-optimizable comparisons in all cases of interest (since a volatile expression isn't indexable). Moreover we get rid of the double evaluation risk for volatile first arguments, as well as the incredible inefficiency of the BETWEEN SYMMETRIC cases. There are some other issues still to be thought about, since the parser is currently willing to cast "x" differently in the two comparisons --- but frankly I think any case where that matters is probably erroneous SQL code in the first place. (See the thread referenced in the comment in the grammar for more info.) regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs