Re: Removing const-false IS NULL quals and redundant IS NOT NULL quals

From: Andy Fan <zhihuifan1213(at)163(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, Andrei Lepikhov <a(dot)lepikhov(at)postgrespro(dot)ru>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Removing const-false IS NULL quals and redundant IS NOT NULL quals
Date: 2023-12-29 01:25:09
Message-ID: 87edf5vl6u.fsf@163.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers


Richard Guo <guofenglinux(at)gmail(dot)com> writes:
>
> The detection of self-inconsistent restrictions already exists in
> planner.
>
> # set constraint_exclusion to on;
> SET
> # explain (costs off) select * from a where a > 3 and a is null;
> QUERY PLAN
> --------------------------
> Result
> One-Time Filter: false
> (2 rows)

It has a different scope and cost from what I suggested. I'd suggest
to detect the notnull constraint only with lower cost and it can be used
in another user case. the constaint_exclusion can covers more user
cases but more expensivly and default off.

Apart from the abve topic, I'm thinking if we should think about the
case like this:

create table t1(a int);
create table t2(a int);

explain (costs off) select * from t1 join t2 using(a) where a is NULL;
QUERY PLAN
-----------------------------------
Hash Join
Hash Cond: (t2.a = t1.a)
-> Seq Scan on t2
-> Hash
-> Seq Scan on t1
Filter: (a IS NULL)

Here a is nullable at the base relation side, but we know that the query
would not return anything at last. IIUC, there is no good place to
handle this in our current infrastructure, I still raise this up in case
I missed anything.

--
Best Regards
Andy Fan

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2023-12-30 10:17:40 BUG #18264: Table has type text, but query expects integer.attribute 1 of type record has wrong type
Previous Message aa 2023-12-28 17:15:04 Re: Out of the box, full text search feature suggestion for postgresql

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2023-12-29 01:29:21 Re: Synchronizing slots from primary to standby
Previous Message Tomas Vondra 2023-12-29 01:16:08 Re: Fix Brin Private Spool Initialization (src/backend/access/brin/brin.c)