postgresql/src/include
Tom Lane f8320cc72d Fix misbehavior of EvalPlanQual checks with multiple result relations.
The idea of EvalPlanQual is that we replace the query's scan of the
result relation with a single injected tuple, and see if we get a
tuple out, thereby implying that the injected tuple still passes the
query quals.  (In join cases, other relations in the query are still
scanned normally.)  This logic was not updated when commit 86dc90056
made it possible for a single DML query plan to have multiple result
relations, when the query target relation has inheritance or partition
children.  We replaced the output for the current result relation
successfully, but other result relations were still scanned normally;
thus, if any other result relation contained a tuple satisfying the
quals, we'd think the EPQ check passed, even if it did not pass for
the injected tuple itself.  This would lead to update or delete
actions getting performed when they should have been skipped due to
a conflicting concurrent update in READ COMMITTED isolation mode.

Fix by blocking all sibling result relations from emitting tuples
during an EvalPlanQual recheck.  In the back branches, the fix is
complicated a bit by the need to not change the size of struct
EPQState (else we'd have ABI-breaking changes in offsets in
struct ModifyTableState).  Like the back-patches of 3f7836ff6
and 4b3e37993, add a separately palloc'd struct to avoid that.
The logic is the same as in HEAD otherwise.

This is only a live bug back to v14 where 86dc90056 came in.
However, I chose to back-patch the test cases further, on the
grounds that this whole area is none too well tested.  I skipped
doing so in v11 though because none of the test applied cleanly,
and it didn't quite seem worth extra work for a branch with only
six months to live.

Per report from Ante Krešić (via Aleksander Alekseev)

Discussion: https://postgr.es/m/CAJ7c6TMBTN3rcz4=AjYhLPD_w3FFT0Wq_C15jxCDn8U4tZnH1g@mail.gmail.com
2023-05-19 14:26:34 -04:00
..
access Fix handling of empty ranges and NULLs in BRIN 2023-05-19 00:15:00 +02:00
bootstrap Update copyright for 2021 2021-01-02 13:06:25 -05:00
catalog In extensions, don't replace objects not belonging to the extension. 2022-08-08 11:12:31 -04:00
commands Fix ENABLE/DISABLE TRIGGER to handle recursion correctly 2022-08-05 09:47:11 +02:00
common Expand palloc/pg_malloc API for more type safety 2022-09-14 06:08:34 +02:00
datatype Update copyright for 2021 2021-01-02 13:06:25 -05:00
executor Fix misbehavior of EvalPlanQual checks with multiple result relations. 2023-05-19 14:26:34 -04:00
fe_utils Allow db.schema.table patterns, but complain about random garbage. 2022-04-20 11:39:44 -04:00
foreign Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
jit jit: Do not try to shut down LLVM state in case of LLVM triggered errors. 2021-09-13 18:15:28 -07:00
lib Add casts to simplehash.h to silence C++ warnings. 2022-11-03 10:47:31 -04:00
libpq Fix handling of SCRAM-SHA-256's channel binding with RSA-PSS certificates 2023-02-15 10:12:33 +09:00
mb Fix incautious handling of possibly-miscoded strings in client code. 2021-06-07 14:15:25 -04:00
nodes Fix misbehavior of EvalPlanQual checks with multiple result relations. 2023-05-19 14:26:34 -04:00
optimizer Fix calculation of which GENERATED columns need to be updated. 2023-01-05 14:12:17 -05:00
parser Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements 2023-04-28 19:29:38 +09:00
partitioning Fix relcache inconsistency hazard in partition detach 2021-04-22 15:13:25 -04:00
port Fix detection of unseekable files for fseek() and ftello() with MSVC 2023-04-12 09:09:58 +09:00
portability Fix another portability bug in recent pgbench commit. 2021-03-10 23:20:41 +13:00
postmaster Remove temporary files after backend crash 2021-03-18 17:38:28 +01:00
regex Improve memory management in regex compiler. 2021-02-26 13:52:10 -05:00
replication Fix catalog lookup with the wrong snapshot during logical decoding. 2022-08-11 09:45:04 +05:30
rewrite Fix calculation of which GENERATED columns need to be updated. 2023-01-05 14:12:17 -05:00
snowball Update snowball 2021-02-19 08:10:15 +01:00
statistics Extended statistics on expressions 2021-03-27 00:01:11 +01:00
storage Improve heuristics for compressing the KnownAssignedXids array. 2022-11-29 15:43:17 -05:00
tcop Centralize the logic for protective copying of utility statements. 2021-06-18 11:22:58 -04:00
tsearch Add comments and a missing CHECK_FOR_INTERRUPTS in ts_headline. 2022-11-21 17:07:07 -05:00
utils pageinspect: Fix gist_page_items() with included columns 2023-05-19 12:38:18 +09:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
Makefile Build in some knowledge about foreign-key relationships in the catalogs. 2021-02-02 17:11:55 -05:00
c.h perl: Hide warnings inside perl.h when using gcc compatible compiler 2023-01-02 15:50:00 -08:00
fmgr.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
funcapi.h Reconsider the handling of procedure OUT parameters. 2021-06-10 17:11:36 -04:00
getaddrinfo.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
getopt_long.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
miscadmin.h Get rid of artificial restriction on hash table sizes on Windows. 2021-07-25 14:02:27 -04:00
pg_config.h.in Fix handling of SCRAM-SHA-256's channel binding with RSA-PSS certificates 2023-02-15 10:12:33 +09:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Rename debug_invalidate_system_caches_always to debug_discard_caches. 2021-07-13 15:01:01 -04:00
pg_getopt.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pg_trace.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgstat.h Fix performance regression from session statistics. 2021-09-16 02:10:57 -07:00
pgtar.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgtime.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
port.h Make EXEC_BACKEND more convenient on Linux and FreeBSD. 2023-02-08 13:09:27 +09:00
postgres.h Fix misleading comments about TOAST access macros. 2021-09-08 14:11:35 -04:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
rusagestub.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
windowapi.h Update copyright for 2021 2021-01-02 13:06:25 -05:00