postgresql/src
Richard Guo a1a9120c79 Ignore nullingrels when looking up statistics
When looking up statistical data about an expression, we do not need
to concern ourselves with the outer joins that could null the
Vars/PHVs contained in the expression.  Accounting for nullingrels in
the expression could cause estimate_num_groups to count the same Var
multiple times if it's marked with different nullingrels.  This is
incorrect, and could lead to "ERROR:  corrupt MVNDistinct entry" when
searching for multivariate n-distinct.

Furthermore, the nullingrels could prevent us from matching an
expression to expressional index columns or to the expressions in
extended statistics, leading to inaccurate estimates.

To fix, strip out all the nullingrels from the expression before we
look up statistical data about it.  There is one ensuing plan change
in the regression tests, but it looks reasonable and does not
compromise its original purpose.

This patch could result in plan changes, but it fixes an actual bug,
so back-patch to v16 where the outer-join-aware-Var infrastructure was
introduced.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4-2Z4k+nFTiZe0Qbu5n8juUWenDAtMzi98bAZQtwHx0-w@mail.gmail.com
2025-01-02 18:02:02 +09:00
..
backend Ignore nullingrels when looking up statistics 2025-01-02 18:02:02 +09:00
bin Fix memory leak in pg_restore with zstd-compressed data. 2024-12-17 22:31:26 -05:00
common meson: Export all libcommon functions in Windows builds 2024-12-25 18:14:30 +02:00
fe_utils Prevent mis-encoding of "trailing junk after numeric literal" errors. 2024-09-05 12:42:33 -04:00
include Exclude parallel workers from connection privilege/limit checks. 2024-12-28 16:08:50 -05:00
interfaces Fix broken list-munging in ecpg's remove_variables(). 2024-12-01 14:15:37 -05:00
makefiles Use --strip-unneeded when stripping static libraries with GNU strip. 2023-04-20 18:12:32 -04:00
pl Add support for Tcl 9 2024-11-25 12:27:19 +01:00
port meson: Export all libcommon functions in Windows builds 2024-12-25 19:22:41 +02:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test Ignore nullingrels when looking up statistics 2025-01-02 18:02:02 +09:00
timezone Update time zone data files to tzdata release 2024b. 2024-10-29 11:49:56 -04:00
tools Avoid mislabeling of lateral references, redux. 2024-11-30 12:42:20 -05:00
tutorial Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
.gitignore
DEVELOPERS
Makefile Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
Makefile.global.in Suppress macOS warnings about duplicate libraries in link commands. 2023-09-29 14:07:30 -04:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
meson.build Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00