postgresql/src/backend
Tom Lane 743ddafc71 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
..
access Retire MemoryContextResetAndDeleteChildren() macro. 2023-11-15 13:42:30 -06:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Change how a base backup decides which files have checksums. 2023-11-14 10:51:05 -05:00
bootstrap Remove distprep 2023-11-06 15:18:04 +01:00
catalog Ensure we preprocess expressions before checking their volatility. 2023-11-16 10:05:14 -05:00
commands Ensure we preprocess expressions before checking their volatility. 2023-11-16 10:05:14 -05:00
executor Retire MemoryContextResetAndDeleteChildren() macro. 2023-11-15 13:42:30 -06:00
foreign Expand some more uses of "deleg" to "delegation" or "delegated". 2023-05-21 10:55:18 -04:00
jit Make ResourceOwners more easily extensible. 2023-11-08 13:30:50 +02:00
lib Make binaryheap available to frontend code. 2023-09-18 12:18:33 -07:00
libpq Add trailing commas to enum definitions 2023-10-26 09:20:54 +02:00
main Remove obsolete defense against strxfrm() bugs. 2023-04-20 13:20:14 +12:00
nodes Remove distprep 2023-11-06 15:18:04 +01:00
optimizer Ensure we preprocess expressions before checking their volatility. 2023-11-16 10:05:14 -05:00
parser Compute aggregate argument types correctly in transformAggregateCall(). 2023-11-06 10:38:00 -05:00
partitioning Add trailing commas to enum definitions 2023-10-26 09:20:54 +02:00
po Translation updates 2023-08-07 12:39:30 +02:00
port Remove distprep 2023-11-06 15:18:04 +01:00
postmaster Retire MemoryContextResetAndDeleteChildren() macro. 2023-11-15 13:42:30 -06:00
regex Add trailing commas to enum definitions 2023-10-26 09:20:54 +02:00
replication Retire MemoryContextResetAndDeleteChildren() macro. 2023-11-15 13:42:30 -06:00
rewrite Add TupleDescGetDefault() 2023-09-27 18:52:40 +01:00
snowball Remove distprep 2023-11-06 15:18:04 +01:00
statistics Retire MemoryContextResetAndDeleteChildren() macro. 2023-11-15 13:42:30 -06:00
storage Remove incorrect file reference in comment. 2023-11-13 19:05:00 +09:00
tcop Retire MemoryContextResetAndDeleteChildren() macro. 2023-11-15 13:42:30 -06:00
tsearch Limit to_tsvector_byid's initial array allocation to something sane. 2023-09-25 11:50:28 -04:00
utils Add target "slru" to pg_stat_reset_shared() 2023-11-16 15:41:34 +09:00
.gitignore
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
meson.build Add win32ver data to meson-built postgres.exe. 2023-06-12 07:40:38 -07:00
nls.mk Remove distprep 2023-11-06 15:18:04 +01:00