postgresql/src/include
David Rowley b262ad440e Add better handling of redundant IS [NOT] NULL quals
Until now PostgreSQL has not been very smart about optimizing away IS
NOT NULL base quals on columns defined as NOT NULL.  The evaluation of
these needless quals adds overhead.  Ordinarily, anyone who came
complaining about that would likely just have been told to not include
the qual in their query if it's not required.  However, a recent bug
report indicates this might not always be possible.

Bug 17540 highlighted that when we optimize Min/Max aggregates the IS NOT
NULL qual that the planner adds to make the rewritten plan ignore NULLs
can cause issues with poor index choice.  That particular case
demonstrated that other quals, especially ones where no statistics are
available to allow the planner a chance at estimating an approximate
selectivity for can result in poor index choice due to cheap startup paths
being prefered with LIMIT 1.

Here we take generic approach to fixing this by having the planner check
for NOT NULL columns and just have the planner remove these quals (when
they're not needed) for all queries, not just when optimizing Min/Max
aggregates.

Additionally, here we also detect IS NULL quals on a NOT NULL column and
transform that into a gating qual so that we don't have to perform the
scan at all.  This also works for join relations when the Var is not
nullable by any outer join.

This also helps with the self-join removal work as it must replace
strict join quals with IS NOT NULL quals to ensure equivalence with the
original query.

Author: David Rowley, Richard Guo, Andy Fan
Reviewed-by: Richard Guo, David Rowley
Discussion: https://postgr.es/m/CAApHDvqg6XZDhYRPz0zgOcevSMo0d3vxA9DvHrZtKfqO30WTnw@mail.gmail.com
Discussion: https://postgr.es/m/17540-7aa1855ad5ec18b4%40postgresql.org
2024-01-23 18:09:18 +13:00
..
access Add stratnum GiST support function 2024-01-19 15:42:13 +01:00
archive
backup
bootstrap
catalog Add planner support functions for range operators <@ and @>. 2024-01-20 13:57:54 -05:00
commands Rename COPY option from SAVE_ERROR_TO to ON_ERROR 2024-01-19 15:15:51 +02:00
common Fixed misspelled byteswap function for big endian machines 2024-01-19 13:26:18 +07:00
datatype
executor
fe_utils
foreign
jit
lib
libpq Make dblink interruptible, via new libpqsrv APIs. 2024-01-08 11:39:56 -08:00
mb
nodes Add better handling of redundant IS [NOT] NULL quals 2024-01-23 18:09:18 +13:00
optimizer Add better handling of redundant IS [NOT] NULL quals 2024-01-23 18:09:18 +13:00
parser
partitioning
pch
port
portability
postmaster Add missing PGDLLIMPORT markings 2024-01-16 13:53:28 +02:00
regex
replication
rewrite
snowball
statistics
storage Introduce the dynamic shared memory registry. 2024-01-19 14:24:36 -06:00
tcop
tsearch
utils Add backend support for injection points 2024-01-22 10:15:50 +09:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h
fmgr.h
funcapi.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
getopt_long.h
Makefile
meson.build
miscadmin.h
pg_config_ext.h.in
pg_config_ext.h.meson
pg_config_manual.h
pg_config.h.in Add backend support for injection points 2024-01-22 10:15:50 +09:00
pg_getopt.h
pg_trace.h
pgstat.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pgtar.h
pgtime.h
port.h
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h
postgres.h
varatt.h
windowapi.h