Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0Eb9-0002sb-JK for pgsql-general@arkaria.postgresql.org; Fri, 15 Jan 2021 02:12:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l0Eb8-0004Ye-Df for pgsql-general@arkaria.postgresql.org; Fri, 15 Jan 2021 02:12:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0Eb8-0004YX-5k for pgsql-general@lists.postgresql.org; Fri, 15 Jan 2021 02:12:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0Eb6-0004Cn-82 for pgsql-general@postgresql.org; Fri, 15 Jan 2021 02:12:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 10F2CHue1622466; Thu, 14 Jan 2021 21:12:17 -0500 From: Tom Lane To: Phil Florent cc: "pgsql-general@postgresql.org" Subject: Re: Strange (and good) side effect of partitioning ? In-reply-to: <1621761.1610675774@sss.pgh.pa.us> References: <1621761.1610675774@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 14 Jan 2021 20:56:14 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1622464.1610676737.1@sss.pgh.pa.us> Date: Thu, 14 Jan 2021 21:12:17 -0500 Message-ID: <1622465.1610676737@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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