diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 5285c3f7faa..68215bb2e39 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1060,7 +1060,7 @@ pgss_ExecutorEnd(QueryDesc *queryDesc) queryDesc->plannedstmt->stmt_len, PGSS_EXEC, queryDesc->totaltime->total * 1000.0, /* convert to msec */ - queryDesc->estate->es_processed, + queryDesc->estate->es_total_processed, &queryDesc->totaltime->bufusage, &queryDesc->totaltime->walusage, queryDesc->estate->es_jit ? &queryDesc->estate->es_jit->instr : NULL, diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 1b007dc32cd..eaf6f31a154 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -289,7 +289,8 @@ standard_ExecutorStart(QueryDesc *queryDesc, int eflags) * There is no return value, but output tuples (if any) are sent to * the destination receiver specified in the QueryDesc; and the number * of tuples processed at the top level can be found in - * estate->es_processed. + * estate->es_processed. The total number of tuples processed in all + * the ExecutorRun calls can be found in estate->es_total_processed. * * We provide a function hook variable that lets loadable plugins * get control when ExecutorRun is called. Such a plugin would @@ -372,6 +373,12 @@ standard_ExecutorRun(QueryDesc *queryDesc, execute_once); } + /* + * Update es_total_processed to keep track of the number of tuples + * processed across multiple ExecutorRun() calls. + */ + estate->es_total_processed += estate->es_processed; + /* * shutdown tuple receiver, if we started it */ diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 012dbb69653..5ce8a0831b1 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -147,6 +147,7 @@ CreateExecutorState(void) estate->es_tupleTable = NIL; estate->es_processed = 0; + estate->es_total_processed = 0; estate->es_top_eflags = 0; estate->es_instrument = 0; diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index b0def732ca6..695ff056ba8 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -661,7 +661,10 @@ typedef struct EState List *es_tupleTable; /* List of TupleTableSlots */ - uint64 es_processed; /* # of tuples processed */ + uint64 es_processed; /* # of tuples processed during one + * ExecutorRun() call. */ + uint64 es_total_processed; /* total # of tuples aggregated across all + * ExecutorRun() calls. */ int es_top_eflags; /* eflags passed to ExecutorStart */ int es_instrument; /* OR of InstrumentOption flags */