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 21:12:17 -0500
Message-ID: <1622465.1610676737@sss.pgh.pa.us> (raw)
In-Reply-To: <1621761.1610675774@sss.pgh.pa.us>
References: <DBAP195MB08742B862E2473EFD0D969A2BAA80@DBAP195MB0874.EURP195.PROD.OUTLOOK.COM>
<1621761.1610675774@sss.pgh.pa.us>
I wrote:
> There's no specific mechanism in Postgres that would cause "X between 20
> and 10" to be reduced to constant-false
Wait, I take that back. There is a mechanism that can conclude that
"X >= 20" and "X <= 10" are contradictory, but it's not applied by
default. Observe:
regression=# set constraint_exclusion = default;
SET
regression=# explain select * from tenk1 where unique1 between 20 and 10;
QUERY PLAN
-----------------------------------------------------------------------------
Index Scan using tenk1_unique1 on tenk1 (cost=0.29..8.30 rows=1 width=244)
Index Cond: ((unique1 >= 20) AND (unique1 <= 10))
(2 rows)
regression=# set constraint_exclusion = on;
SET
regression=# explain select * from tenk1 where unique1 between 20 and 10;
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.00 rows=0 width=0)
One-Time Filter: false
(2 rows)
The default value of constraint_exclusion is "partition", which means
(you guessed it) that it's applied only to potential partitioning
constraints. This is a heuristic based on the typical payoff of
excluding whole partitions versus skipping an empty index scan.
But if you have a workload where it's really worth spending
planner cycles looking for self-contradictory queries, you can
turn it on.
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: <1622465.1610676737@sss.pgh.pa.us>
References: <DBAP195MB08742B862E2473EFD0D969A2BAA80@DBAP195MB0874.EURP195.PROD.OUTLOOK.COM> <1621761.1610675774@sss.pgh.pa.us> <1622465.1610676737@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