From: Tom Lane <tgl@sss.pgh.pa.us>
To: Phil Florent <philflorent@hotmail.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Strange (and good) side effect of partitioning ?
Date: Thu, 14 Jan 2021 20:56:14 -0500
Message-ID: <1621761.1610675774@sss.pgh.pa.us> (raw)
In-Reply-To: <DBAP195MB08742B862E2473EFD0D969A2BAA80@DBAP195MB0874.EURP195.PROD.OUTLOOK.COM>
References: <DBAP195MB08742B862E2473EFD0D969A2BAA80@DBAP195MB0874.EURP195.PROD.OUTLOOK.COM>
Phil Florent <philflorent@hotmail.com> writes:
> I read that on Jonathan Lewis' blog :
> (I believe that there may be some RDBMS which will treat (e.g.) "X between 20 and 10" as being identical to "X between 10 and 20" )
FWIW, I hope not, because the SQL spec is perfectly clear that it's
not supposed to work like that. As rob stone noted nearby, you're
supposed to say BETWEEN SYMMETRIC if you want that behavior.
"X between 20 and 10" should always be false (well, unless it's
null because X is null). But I think that's not really what
your question is.
> I am puzzled. PostgreSQL seems NOT to treat X between 20 and 10" as being identical to "X between 10 and 20" but it's complicated.
There's no specific mechanism in Postgres that would cause "X between 20
and 10" to be reduced to constant-false (and I kind of think it would
be a waste of effort to add one). So that's why in simple cases you
get a plan like
> Seq Scan on t1a (cost=0.00..1167.00 rows=1 width=33) (actual time=6.553..6.553 rows=0 loops=1)
> Filter: ((rn >= 20) AND (rn <= 10))
I think that the other cases you show work as they do because the
code for excluding irrelevant range-based partitions is able to
conclude that no partition need be scanned. That is, the
constant-false-one-time-filter plan arises when we have no
partitions remaining to scan, not because the plan for any one
partition would have looked different from what's above.
regards, tom lane
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-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, philflorent@hotmail.com
Subject: Re: Strange (and good) side effect of partitioning ?
In-Reply-To: <1621761.1610675774@sss.pgh.pa.us>
References: <DBAP195MB08742B862E2473EFD0D969A2BAA80@DBAP195MB0874.EURP195.PROD.OUTLOOK.COM> <1621761.1610675774@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