From d0335ec818ec8195cb498ccf09002bd783c754fa Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Tue, 5 Dec 2017 15:35:13 +0100 Subject: [PATCH] Send BEGIN for SELECTs in the router executor --- .../distributed/executor/multi_router_executor.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/backend/distributed/executor/multi_router_executor.c b/src/backend/distributed/executor/multi_router_executor.c index 3261fcc4a..f29ea279b 100644 --- a/src/backend/distributed/executor/multi_router_executor.c +++ b/src/backend/distributed/executor/multi_router_executor.c @@ -615,6 +615,20 @@ ExecuteSingleSelectTask(CitusScanState *scanState, Task *task) connection = GetPlacementListConnection(connectionFlags, placementAccessList, NULL); + /* + * Make sure we open a transaction block and assign a distributed transaction + * ID if we are in a coordinated transaction. + * + * This can happen when the SELECT goes to a node that was not involved in + * the transaction so far, or when existing connections to the node are + * claimed exclusively, e.g. the connection might be claimed to copy the + * intermediate result of a CTE to the node. Especially in the latter case, + * we want to make sure that we open a transaction block and assign a + * distributed transaction ID, such that the query can read intermediate + * results. + */ + RemoteTransactionBeginIfNecessary(connection); + queryOK = SendQueryInSingleRowMode(connection, queryString, paramListInfo); if (!queryOK) {