pgsql: Drain pending asynchronous requests during ExecReScanAppend. - Mailing list pgsql-committers

From Etsuro Fujita
Subject pgsql: Drain pending asynchronous requests during ExecReScanAppend.
Date
Msg-id E1wsG0Z-00000000Ybk-225A@gemulon.postgresql.org
Whole thread
List pgsql-committers
Drain pending asynchronous requests during ExecReScanAppend.

The logic for asynchronous Append assumes that pending requests made for
subplans of an Append are drained during ExecReScanAppend.  To ensure
that, commit 9e283fc85 modified postgresReScanForeignScan to drain such
a request if any, but failed to take into account that if such a request
was made for a subplan that is re-scanned with parameter changes or
pruned in the next round by runtime pruning, the postgres_fdw callback
function is called after ExecReScanAppend or never called, respectively.
This would cause such a request to remain even after ExecReScanAppend,
leading to incorrect results, an infinite loop, or an assertion failure.

To fix, modify ExecReScanAppend to, for each of the pending requests,
give the FDW a chance to drain that request using the existing
ForeignAsyncConfigureWait/ForeignAsyncNotify callback functions.  This
makes the change made to postgresReScanForeignScan useless, so remove it
as well.

Back-patch to v14 where asynchronous Append was added.

Reported-by: Alexander Korotkov <aekorotkov@gmail.com>
Co-authored-by: Alexander Korotkov <aekorotkov@gmail.com>
Co-authored-by: Gleb Kashkin <g.kashkin@postgrespro.ru>
Co-authored-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Alexander Pyhalov <a.pyhalov@postgrespro.ru>
Reviewed-by: Gleb Kashkin <g.kashkin@postgrespro.ru>
Discussion: https://postgr.es/m/CAPpHfduMOTnV5Zj2KGJ7zanL_10QvccZHtPUaDfJvBhsh9axnQ%40mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7d74b26447229cccc2005d8b48b36bcd8bd17f33

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 70 ++++++++++++++++++-
contrib/postgres_fdw/postgres_fdw.c            | 15 ++--
contrib/postgres_fdw/sql/postgres_fdw.sql      | 14 +++-
src/backend/executor/nodeAppend.c              | 97 +++++++++++++++++++++-----
4 files changed, 163 insertions(+), 33 deletions(-)


pgsql-committers by date:

Previous
From: Amit Langote
Date:
Subject: pgsql: Fire fast-path FK batches inside the deferred trigger loop
Next
From: Melanie Plageman
Date:
Subject: pgsql: Only clear VACUUM's read stream strategy once in failsafe mode