Re: Check each of base restriction clauses for constant-FALSE-or-NULL

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Check each of base restriction clauses for constant-FALSE-or-NULL
Date: 2023-10-10 09:10:12
Message-ID: CAApHDvoYfnHCxfEUayqhf-jiV=kO-J7Oh6Zd9Zq9DDYw27PHeg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 7 Oct 2023 at 22:44, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>
> In relation_excluded_by_constraints() when we're trying to figure out
> whether the relation need not be scanned, one of the checks we do is to
> detect constant-FALSE-or-NULL restriction clauses. Currently we perform
> this check only when there is exactly one baserestrictinfo entry, and
> the comment explains this as below.
>
> * Regardless of the setting of constraint_exclusion, detect
> * constant-FALSE-or-NULL restriction clauses. Because const-folding will
> * reduce "anything AND FALSE" to just "FALSE", any such case should
> * result in exactly one baserestrictinfo entry.

Coincidentally (?), I saw the same thing just a few weeks ago while
working on [1]. I made the exact same adjustment to the code in
relation_excluded_by_constraints() as you have.

I wasn't really expecting the baserestrictinfo list to be excessively
long, and if it ever was, I think looking at things like selectivity
estimations would by far drown out looping over the entire list in
relation_excluded_by_constraints() rather than just looking at the
first item in the list.

After making the change, I saw the same regression test change as you
did, but didn't really feel like it was worth tackling separately from
the patch that we were working on.

David

[1] https://postgr.es/m/CAApHDvpkfS1hY3P4DWbOw6WCgRrja=yDLoEz+5g+E2z19Upsrg@mail.gmail.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aleksander Alekseev 2023-10-10 09:14:26 Re: Add const to values and nulls arguments
Previous Message Esteban Zimanyi 2023-10-10 08:58:57 Fwd: Advice about preloaded libraries