diff options
author | Etsuro Fujita <efujita@postgresql.org> | 2021-04-23 12:00:00 +0900 |
---|---|---|
committer | Etsuro Fujita <efujita@postgresql.org> | 2021-04-23 12:00:00 +0900 |
commit | bb684c82f73316b88f9bcb321128a4347b5206fe (patch) | |
tree | 510fc2a7ece07b3df91815242e857aa0d3974a4b /src/backend/executor/nodeAppend.c | |
parent | d479d00285255d422a2b38f1cfaa35808968a08c (diff) | |
download | postgresql-bb684c82f73316b88f9bcb321128a4347b5206fe.tar.gz postgresql-bb684c82f73316b88f9bcb321128a4347b5206fe.zip |
Minor code cleanup in asynchronous execution support.
This is cleanup for commit 27e1f1456:
* ExecAppendAsyncEventWait(), which was modified a bit further by commit
a8af856d3, duplicated the same nevents calculation. Simplify the code
a little bit to avoid the duplication. Update comments there.
* Add an assertion to ExecAppendAsyncRequest().
* Update a comment about merging the async_capable options from input
relations in merge_fdw_options(), per complaint from Kyotaro Horiguchi.
* Add a comment for fetch_more_data_begin().
Author: Etsuro Fujita
Discussion: https://postgr.es/m/CAPmGK1637W30Wx3MnrReewhafn6F_0J76mrJGoFXFnpPq4QfvA%40mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeAppend.c')
-rw-r--r-- | src/backend/executor/nodeAppend.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c index c2527572686..3c1f12adafb 100644 --- a/src/backend/executor/nodeAppend.c +++ b/src/backend/executor/nodeAppend.c @@ -952,7 +952,10 @@ ExecAppendAsyncRequest(AppendState *node, TupleTableSlot **result) /* Nothing to do if there are no async subplans needing a new request. */ if (bms_is_empty(node->as_needrequest)) + { + Assert(node->as_nasyncresults == 0); return false; + } /* * If there are any asynchronously-generated results that have not yet @@ -998,17 +1001,16 @@ ExecAppendAsyncRequest(AppendState *node, TupleTableSlot **result) static void ExecAppendAsyncEventWait(AppendState *node) { + int nevents = node->as_nasyncplans + 1; long timeout = node->as_syncdone ? -1 : 0; WaitEvent occurred_event[EVENT_BUFFER_SIZE]; int noccurred; - int nevents; int i; /* We should never be called when there are no valid async subplans. */ Assert(node->as_nasyncremain > 0); - node->as_eventset = CreateWaitEventSet(CurrentMemoryContext, - node->as_nasyncplans + 1); + node->as_eventset = CreateWaitEventSet(CurrentMemoryContext, nevents); AddWaitEventToSet(node->as_eventset, WL_EXIT_ON_PM_DEATH, PGINVALID_SOCKET, NULL, NULL); @@ -1022,8 +1024,14 @@ ExecAppendAsyncEventWait(AppendState *node) ExecAsyncConfigureWait(areq); } - /* Wait for at least one event to occur. */ - nevents = Min(node->as_nasyncplans + 1, EVENT_BUFFER_SIZE); + /* We wait on at most EVENT_BUFFER_SIZE events. */ + if (nevents > EVENT_BUFFER_SIZE) + nevents = EVENT_BUFFER_SIZE; + + /* + * If the timeout is -1, wait until at least one event occurs. If the + * timeout is 0, poll for events, but do not wait at all. + */ noccurred = WaitEventSetWait(node->as_eventset, timeout, occurred_event, nevents, WAIT_EVENT_APPEND_READY); FreeWaitEventSet(node->as_eventset); |