postgresql/src/include/executor
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
..
execAsync.h Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
execExpr.h Redesign the caching done by get_cached_rowtype(). 2021-04-13 13:37:07 -04:00
execParallel.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
execPartition.h Postpone some stuff out of ExecInitModifyTable. 2021-04-06 15:57:11 -04:00
execdebug.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
execdesc.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
executor.h Fix misbehavior of EvalPlanQual checks with multiple result relations. 2023-05-19 14:26:34 -04:00
functions.h Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
hashjoin.h Fix race in parallel hash join batch cleanup, take II. 2023-03-21 14:37:33 +13:00
instrument.h Fix issues in pg_stat_wal. 2021-05-19 11:38:34 +09:00
nodeAgg.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeAppend.h Add support for asynchronous execution. 2021-03-31 18:45:00 +09:00
nodeBitmapAnd.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeBitmapHeapscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeBitmapIndexscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeBitmapOr.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeCtescan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeCustom.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeForeignscan.h Add support for asynchronous execution. 2021-03-31 18:45:00 +09:00
nodeFunctionscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeGather.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeGatherMerge.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeGroup.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeHash.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeHashjoin.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeIncrementalSort.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeIndexonlyscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeIndexscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeLimit.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeLockRows.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeMaterial.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeMemoize.h Change the name of the Result Cache node to Memoize 2021-07-14 12:45:00 +12:00
nodeMergeAppend.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeMergejoin.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeModifyTable.h Make new GENERATED-expressions code more bulletproof. 2023-01-15 14:06:46 -05:00
nodeNamedtuplestorescan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeNestloop.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeProjectSet.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeRecursiveunion.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeResult.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeSamplescan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeSeqscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeSetOp.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeSort.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeSubplan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeSubqueryscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeTableFuncscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeTidrangescan.h Add TID Range Scans to support efficient scanning ranges of TIDs 2021-02-27 22:59:36 +13:00
nodeTidscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeUnique.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeValuesscan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeWindowAgg.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodeWorktablescan.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
spi.h Re-add SPICleanup for ABI compatibility in stable branch 2022-07-18 16:23:48 +02:00
spi_priv.h Improve performance of repeated CALLs within plpgsql procedures. 2021-01-25 22:28:29 -05:00
tablefunc.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tqueue.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tstoreReceiver.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tuptable.h Update copyright for 2021 2021-01-02 13:06:25 -05:00