pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joshua Yanovski <pythonesque@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #9227: Error on SELECT ROW OVERLAPS ROW with single ROW argument
Date: Tue, 18 Feb 2014 13:39:41 -0500
Message-ID: <8502.1392748781@sss.pgh.pa.us> (raw)
In-Reply-To: <7822.1392746510@sss.pgh.pa.us>
References: <20140215035549.24618.37927@wrigleys.postgresql.org>
	<10303.1392683593@sss.pgh.pa.us>
	<CABz-M-EGDwHUmG7G0rPEL3KzgauoL99F7f7EcWYt1gAst2MMMw@mail.gmail.com>
	<CABz-M-Hs7eGjvQQ_jPx4=7yrkg8-u2q79EBUpydGXhTznvMqzw@mail.gmail.com>
	<CABz-M-FwbWJ06QCER+-oJLyQz9JW7jXY3PcwF3HdGi5W751P1w@mail.gmail.com>
	<7547.1392745766@sss.pgh.pa.us>
	<CABz-M-EYhQj7ONdJ1RO6NRE4MSp33d+R0aXpkRyrC=ScAUMA3w@mail.gmail.com>
	<7822.1392746510@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

I wrote:
> Joshua Yanovski <pythonesque@gmail.com> 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



view thread (13+ messages)  latest in thread

Message-ID: <8502.1392748781@sss.pgh.pa.us>
Permalink:  ../8502.1392748781@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/8502.1392748781@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pythonesque@gmail.com
  Subject: Re: BUG #9227: Error on SELECT ROW OVERLAPS ROW with single ROW argument
  In-Reply-To: <8502.1392748781@sss.pgh.pa.us>
  References: <20140215035549.24618.37927@wrigleys.postgresql.org> <10303.1392683593@sss.pgh.pa.us> <CABz-M-EGDwHUmG7G0rPEL3KzgauoL99F7f7EcWYt1gAst2MMMw@mail.gmail.com> <CABz-M-Hs7eGjvQQ_jPx4=7yrkg8-u2q79EBUpydGXhTznvMqzw@mail.gmail.com> <CABz-M-FwbWJ06QCER+-oJLyQz9JW7jXY3PcwF3HdGi5W751P1w@mail.gmail.com> <7547.1392745766@sss.pgh.pa.us> <CABz-M-EYhQj7ONdJ1RO6NRE4MSp33d+R0aXpkRyrC=ScAUMA3w@mail.gmail.com> <7822.1392746510@sss.pgh.pa.us> <8502.1392748781@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox