Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bb684c8

Browse files
author
Etsuro Fujita
committed
Minor code cleanup in asynchronous execution support.
This is cleanup for commit 27e1f14: * ExecAppendAsyncEventWait(), which was modified a bit further by commit a8af856, 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
1 parent d479d00 commit bb684c8

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

contrib/postgres_fdw/postgres_fdw.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -5835,7 +5835,10 @@ merge_fdw_options(PgFdwRelationInfo *fpinfo,
58355835

58365836
/*
58375837
* We'll prefer to consider this join async-capable if any table from
5838-
* either side of the join is considered async-capable.
5838+
* either side of the join is considered async-capable. This would be
5839+
* reasonable because in that case the foreign server would have its
5840+
* own resources to scan that table asynchronously, and the join could
5841+
* also be computed asynchronously using the resources.
58395842
*/
58405843
fpinfo->async_capable = fpinfo_o->async_capable ||
58415844
fpinfo_i->async_capable;
@@ -6893,6 +6896,9 @@ produce_tuple_asynchronously(AsyncRequest *areq, bool fetch)
68936896
/*
68946897
* Begin an asynchronous data fetch.
68956898
*
6899+
* Note: this function assumes there is no currently-in-progress asynchronous
6900+
* data fetch.
6901+
*
68966902
* Note: fetch_more_data must be called to fetch the result.
68976903
*/
68986904
static void

src/backend/executor/nodeAppend.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,10 @@ ExecAppendAsyncRequest(AppendState *node, TupleTableSlot **result)
952952

953953
/* Nothing to do if there are no async subplans needing a new request. */
954954
if (bms_is_empty(node->as_needrequest))
955+
{
956+
Assert(node->as_nasyncresults == 0);
955957
return false;
958+
}
956959

957960
/*
958961
* If there are any asynchronously-generated results that have not yet
@@ -998,17 +1001,16 @@ ExecAppendAsyncRequest(AppendState *node, TupleTableSlot **result)
9981001
static void
9991002
ExecAppendAsyncEventWait(AppendState *node)
10001003
{
1004+
int nevents = node->as_nasyncplans + 1;
10011005
long timeout = node->as_syncdone ? -1 : 0;
10021006
WaitEvent occurred_event[EVENT_BUFFER_SIZE];
10031007
int noccurred;
1004-
int nevents;
10051008
int i;
10061009

10071010
/* We should never be called when there are no valid async subplans. */
10081011
Assert(node->as_nasyncremain > 0);
10091012

1010-
node->as_eventset = CreateWaitEventSet(CurrentMemoryContext,
1011-
node->as_nasyncplans + 1);
1013+
node->as_eventset = CreateWaitEventSet(CurrentMemoryContext, nevents);
10121014
AddWaitEventToSet(node->as_eventset, WL_EXIT_ON_PM_DEATH, PGINVALID_SOCKET,
10131015
NULL, NULL);
10141016

@@ -1022,8 +1024,14 @@ ExecAppendAsyncEventWait(AppendState *node)
10221024
ExecAsyncConfigureWait(areq);
10231025
}
10241026

1025-
/* Wait for at least one event to occur. */
1026-
nevents = Min(node->as_nasyncplans + 1, EVENT_BUFFER_SIZE);
1027+
/* We wait on at most EVENT_BUFFER_SIZE events. */
1028+
if (nevents > EVENT_BUFFER_SIZE)
1029+
nevents = EVENT_BUFFER_SIZE;
1030+
1031+
/*
1032+
* If the timeout is -1, wait until at least one event occurs. If the
1033+
* timeout is 0, poll for events, but do not wait at all.
1034+
*/
10271035
noccurred = WaitEventSetWait(node->as_eventset, timeout, occurred_event,
10281036
nevents, WAIT_EVENT_APPEND_READY);
10291037
FreeWaitEventSet(node->as_eventset);

0 commit comments

Comments
 (0)