From faac9b968d7a0d031d85a7947592d2db3853a387 Mon Sep 17 00:00:00 2001 From: Karina Litskevich Date: Mon, 23 Jun 2025 18:55:42 +0300 Subject: [PATCH] Do not remove totaltime instrumentation from queryDesc --- .../distributed/executor/multi_executor.c | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/backend/distributed/executor/multi_executor.c b/src/backend/distributed/executor/multi_executor.c index e257b80c6..c8dbcb3f9 100644 --- a/src/backend/distributed/executor/multi_executor.c +++ b/src/backend/distributed/executor/multi_executor.c @@ -167,23 +167,19 @@ CitusExecutorRun(QueryDesc *queryDesc, */ executorBoundParams = queryDesc->params; - /* - * We do some potentially time consuming operations ourself now before we hand off - * control to postgres' executor. To make sure that time spent is accurately measured - * we remove the totaltime instrumentation from the queryDesc. Instead we will start - * and stop the instrumentation of the total time and put it back on the queryDesc - * before returning (or rethrowing) from this function. - */ - Instrumentation *volatile totalTime = queryDesc->totaltime; - queryDesc->totaltime = NULL; - PG_TRY(); { ExecutorLevel++; - if (totalTime) + /* + * We do some potentially time consuming operations our self now before we hand of + * control to postgres' executor. To make sure that time spent is accurately measured + * we start and stop totaltime instrumentation from the queryDesc to mesure this + * time consuming operations before postgres' executor. + */ + if (queryDesc->totaltime) { - InstrStartNode(totalTime); + InstrStartNode(queryDesc->totaltime); } /* @@ -202,13 +198,16 @@ CitusExecutorRun(QueryDesc *queryDesc, */ if (AlterTableConstraintCheck(queryDesc)) { - EState *estate = queryDesc->estate; - - estate->es_processed = 0; - /* start and shutdown tuple receiver to simulate empty result */ dest->rStartup(queryDesc->dest, CMD_SELECT, queryDesc->tupDesc); dest->rShutdown(dest); + + queryDesc->estate->es_processed = 0; + + if (queryDesc->totaltime) + { + InstrStopNode(queryDesc->totaltime, 0); + } } else { @@ -235,13 +234,12 @@ CitusExecutorRun(QueryDesc *queryDesc, /* postgres will switch here again and will restore back on its own */ MemoryContextSwitchTo(oldcontext); - standard_ExecutorRun(queryDesc, direction, count, execute_once); - } + if (queryDesc->totaltime) + { + InstrStopNode(queryDesc->totaltime, 0); + } - if (totalTime) - { - InstrStopNode(totalTime, queryDesc->estate->es_processed); - queryDesc->totaltime = totalTime; + standard_ExecutorRun(queryDesc, direction, count, execute_once); } executorBoundParams = savedBoundParams; @@ -269,11 +267,6 @@ CitusExecutorRun(QueryDesc *queryDesc, } PG_CATCH(); { - if (totalTime) - { - queryDesc->totaltime = totalTime; - } - executorBoundParams = savedBoundParams; ExecutorLevel--;