postgresql/src/include/optimizer
Tom Lane 9057ddbefe Ensure we preprocess expressions before checking their volatility.
contain_mutable_functions and contain_volatile_functions give
reliable answers only after expression preprocessing (specifically
eval_const_expressions).  Some places understand this, but some did
not get the memo --- which is not entirely their fault, because the
problem is documented only in places far away from those functions.
Introduce wrapper functions that allow doing the right thing easily,
and add commentary in hopes of preventing future mistakes from
copy-and-paste of code that's only conditionally safe.

Two actual bugs of this ilk are fixed here.  We failed to preprocess
column GENERATED expressions before checking mutability, so that the
code could fail to detect the use of a volatile function
default-argument expression, or it could reject a polymorphic function
that is actually immutable on the datatype of interest.  Likewise,
column DEFAULT expressions weren't preprocessed before determining if
it's safe to apply the attmissingval mechanism.  A false negative
would just result in an unnecessary table rewrite, but a false
positive could allow the attmissingval mechanism to be used in a case
where it should not be, resulting in unexpected initial values in a
new column.

In passing, re-order the steps in ComputePartitionAttrs so that its
checks for invalid column references are done before applying
expression_planner, rather than after.  The previous coding would
not complain if a partition expression contains a disallowed column
reference that gets optimized away by constant folding, which seems
to me to be a behavior we do not want.

Per bug #18097 from Jim Keener.  Back-patch to all supported versions.

Discussion: https://postgr.es/m/18097-ebb179674f22932f@postgresql.org
2023-11-16 10:05:14 -05:00
..
appendinfo.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
clauses.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
cost.h Revert "Optimize order of GROUP BY keys". 2022-10-03 10:56:16 -04:00
geqo.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
geqo_copy.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
geqo_gene.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
geqo_misc.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
geqo_mutation.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
geqo_pool.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
geqo_random.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
geqo_recombination.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
geqo_selection.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
inherit.h Fix calculation of which GENERATED columns need to be updated. 2023-01-05 14:12:17 -05:00
joininfo.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
optimizer.h Ensure we preprocess expressions before checking their volatility. 2023-11-16 10:05:14 -05:00
orclauses.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
paramassign.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pathnode.h Teach planner and executor about monotonic window funcs 2022-04-08 10:34:36 +12:00
paths.h Revert "Optimize order of GROUP BY keys". 2022-10-03 10:56:16 -04:00
placeholder.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
plancat.h Fix calculation of which GENERATED columns need to be updated. 2023-01-05 14:12:17 -05:00
planmain.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
planner.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
prep.h Add support for MERGE SQL command 2022-03-28 16:47:48 +02:00
restrictinfo.h Disallow replacing joins with scans in problematic cases. 2023-07-28 15:45:02 +09:00
subselect.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
tlist.h Update copyright for 2022 2022-01-07 19:04:57 -05:00