postgresql/src
Alexander Korotkov c0962a113d Convert 'x IN (VALUES ...)' to 'x = ANY ...' then appropriate
This commit implements the automatic conversion of 'x IN (VALUES ...)' into
ScalarArrayOpExpr.  That simplifies the query tree, eliminating the appearance
of an unnecessary join.

Since VALUES describes a relational table, and the value of such a list is
a table row, the optimizer will likely face an underestimation problem due to
the inability to estimate cardinality through MCV statistics.  The cardinality
evaluation mechanism can work with the array inclusion check operation.
If the array is small enough (< 100 elements), it will perform a statistical
evaluation element by element.

We perform the transformation in the convert_ANY_sublink_to_join() if VALUES
RTE is proper and the transformation is convertible.  The conversion is only
possible for operations on scalar values, not rows.  Also, we currently
support the transformation only when it ends up with a constant array.
Otherwise, the evaluation of non-hashed SAOP might be slower than the
corresponding Hash Join with VALUES.

Discussion: https://postgr.es/m/0184212d-1248-4f1f-a42d-f5cb1c1976d2%40tantorlabs.com
Author: Alena Rybakina <a.rybakina@postgrespro.ru>
Author: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: Ivan Kush <ivan.kush@tantorlabs.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
2025-04-04 16:01:50 +03:00
..
backend Convert 'x IN (VALUES ...)' to 'x = ANY ...' then appropriate 2025-04-04 16:01:50 +03:00
bin Extend ALTER DEFAULT PRIVILEGES to define default privileges for large objects. 2025-04-04 19:02:17 +09:00
common Update Unicode data to Unicode 16.0.0 2025-04-03 12:00:09 +02:00
fe_utils Fix accidentally-harmless thinko in psqlscan_test_variable(). 2025-03-31 12:16:32 -04:00
include Convert 'x IN (VALUES ...)' to 'x = ANY ...' then appropriate 2025-04-04 16:01:50 +03:00
interfaces oauth: Fix build on platforms without epoll/kqueue 2025-04-03 20:37:52 +02:00
makefiles aio: Add liburing dependency 2025-03-26 19:45:32 -04:00
pl plpython: Add test for returning Python set from SETOF function 2025-04-03 11:09:50 +02:00
port Add timingsafe_bcmp(), for constant-time memory comparison 2025-04-02 15:32:40 +03:00
template thread-safety: gmtime_r(), localtime_r() 2024-08-23 07:43:04 +02:00
test Convert 'x IN (VALUES ...)' to 'x = ANY ...' then appropriate 2025-04-04 16:01:50 +03:00
timezone pg_noreturn to replace pg_attribute_noreturn() 2025-03-13 12:37:26 +01:00
tools Make derived clause lookup in EquivalenceClass more efficient 2025-04-04 10:45:05 +09:00
tutorial Doc: simplify the tutorial's window-function examples. 2025-01-21 14:43:21 -05:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Update Unicode data to Unicode 16.0.0 2025-04-03 12:00:09 +02:00
Makefile.shlib Remove AIX support 2024-02-28 15:17:23 +04:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
nls-global.mk Remove distprep 2023-11-06 15:18:04 +01:00