postgresql/src/backend
Tom Lane 87f3667ec0 Fix MULTIEXPR_SUBLINK with partitioned target tables, yet again.
We already tried to fix this in commits 3f7323cbb et al (and follow-on
fixes), but now it emerges that there are still unfixed cases;
moreover, these cases affect all branches not only pre-v14.  I thought
we had eliminated all cases of making multiple clones of an UPDATE's
target list when we nuked inheritance_planner.  But it turns out we
still do that in some partitioned-UPDATE cases, notably including
INSERT ... ON CONFLICT UPDATE, because ExecInitPartitionInfo thinks
it's okay to clone and modify the parent's targetlist.

This fix is based on a suggestion from Andres Freund: let's stop
abusing the ParamExecData.execPlan mechanism, which was only ever
meant to handle initplans, and instead solve the execution timing
problem by having the expression compiler move MULTIEXPR_SUBLINK steps
to the front of their expression step lists.  This is feasible because
(a) all branches still in support compile the entire targetlist of
an UPDATE into a single ExprState, and (b) we know that all
MULTIEXPR_SUBLINKs do need to be evaluated --- none could be buried
inside a CASE, for example.  There is a minor semantics change
concerning the order of execution of the MULTIEXPR's subquery versus
other parts of the parent targetlist, but that seems like something
we can get away with.  By doing that, we no longer need to worry
about whether different clones of a MULTIEXPR_SUBLINK share output
Params; their usage of that data structure won't overlap.

Per bug #17800 from Alexander Lakhin.  Back-patch to all supported
branches.  In v13 and earlier, we can revert 3f7323cbb and follow-on
fixes; however, I chose to keep the SubPlan.subLinkId field added
in ccbb54c72.  We don't need that anymore in the core code, but it's
cheap enough to fill, and removing a plan node field in a minor
release seems like it'd be asking for trouble.

Andres Freund and Tom Lane

Discussion: https://postgr.es/m/17800-ff90866b3906c964@postgresql.org
2023-02-25 14:44:14 -05:00
..
access Remove unnecessary #ifdef USE_ICU and branch. 2023-02-23 11:20:00 -08:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Improve TimestampDifferenceMilliseconds to cope with overflow sanely. 2023-01-26 17:09:12 -05:00
bootstrap Update copyright for 2023 2023-01-02 15:00:37 -05:00
catalog Disallow NULLS NOT DISTINCT indexes for primary keys 2023-02-24 11:09:50 +01:00
commands Fix corruption of templates after CREATE DATABASE .. STRATEGY WAL_LOG 2023-02-22 10:14:52 +09:00
executor Fix MULTIEXPR_SUBLINK with partitioned target tables, yet again. 2023-02-25 14:44:14 -05:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit Fix various typos in code and tests 2023-02-09 14:43:53 +09:00
lib Fix ILIST_DEBUG build 2023-01-18 10:26:15 -08:00
libpq Add description for new patterns supported in HBA and ident sample files 2023-02-16 07:38:52 +09:00
main Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodes Mark more nodes with attribute no_query_jumble 2023-02-13 09:07:33 +09:00
optimizer Fix mis-handling of outer join quals generated by EquivalenceClasses. 2023-02-23 11:05:58 -05:00
parser Fix incorrect format placeholder 2023-02-10 12:00:51 +01:00
partitioning Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
po Update copyright for 2023 2023-01-02 15:00:37 -05:00
port Update copyright for 2023 2023-01-02 15:00:37 -05:00
postmaster Redesign archive modules 2023-02-17 14:26:42 +09:00
regex Refactor to introduce pg_locale_deterministic(). 2023-02-23 11:17:41 -08:00
replication Don't repeatedly register cache callbacks in pgoutput plugin. 2023-02-23 15:40:42 -05:00
rewrite Fix mishandling of OLD/NEW references in subqueries in rule actions. 2023-02-25 14:41:12 +00:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Fix incorrect format placeholders 2023-02-24 08:02:48 +01:00
storage Remove obsolete coding for early macOS. 2023-02-22 09:55:43 +13:00
tcop Speedup and increase usability of set proc title functions 2023-02-20 16:18:27 +13:00
tsearch Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
utils Silence compiler warnings introduced by d87d548cd0. 2023-02-24 09:11:35 -08:00
.gitignore
Makefile Redesign archive modules 2023-02-17 14:26:42 +09:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build Redesign archive modules 2023-02-17 14:26:42 +09:00
nls.mk NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00