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 <[email protected]> Co-authored-by: Alexander Korotkov <[email protected]> Co-authored-by: Gleb Kashkin <[email protected]> Co-authored-by: Etsuro Fujita <[email protected]> Reviewed-by: Alexander Pyhalov <[email protected]> Reviewed-by: Gleb Kashkin <[email protected]> Discussion: https://postgr.es/m/CAPpHfduMOTnV5Zj2KGJ7zanL_10QvccZHtPUaDfJvBhsh9axnQ%40mail.gmail.com Backpatch-through: 14 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4ea497a9263efe17d809b844a8cc0c71e99f5cc4 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(-)
