On Sat, 7 Oct 2023 at 22:44, Richard Guo <[email protected]> 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+e2z19up...@mail.gmail.com
