From ad2574332cb32561f8c7268c5befeb5f561e05fb Mon Sep 17 00:00:00 2001 From: "Andrei V. Lepikhov" Date: Mon, 6 Apr 2026 10:53:47 +0200 Subject: [PATCH] Adopt the code to Instrumentation changes introduced by the 5a79e78 --- pg_track_optimizer.c | 5 +++++ plan_error.c | 25 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/pg_track_optimizer.c b/pg_track_optimizer.c index 7007001..87d34fd 100644 --- a/pg_track_optimizer.c +++ b/pg_track_optimizer.c @@ -24,6 +24,7 @@ #include "commands/explain_state.h" #endif #include "executor/executor.h" +#include "executor/instrument.h" #include "funcapi.h" #include "lib/dshash.h" #include "miscadmin.h" @@ -292,7 +293,11 @@ explain_ExecutorStart(QueryDesc *queryDesc, int eflags) MemoryContext oldcxt; oldcxt = MemoryContextSwitchTo(queryDesc->estate->es_query_cxt); +#if PG_VERSION_NUM >= 190000 + queryDesc->totaltime = InstrAlloc(INSTRUMENT_ALL); +#else queryDesc->totaltime = InstrAlloc(1, INSTRUMENT_ALL, false); +#endif MemoryContextSwitchTo(oldcxt); } } diff --git a/plan_error.c b/plan_error.c index 9e505ea..5fb70f7 100644 --- a/plan_error.c +++ b/plan_error.c @@ -55,10 +55,14 @@ prediction_walker(PlanState *pstate, void *context) */ foreach_node(SubPlanState, sps, pstate->subPlan) { - Instrumentation *instr = sps->planstate->instrument; - double subplan_time; - double loop_factor; - double cost_factor; +#if PG_VERSION_NUM >= 190000 + NodeInstrumentation *instr = sps->planstate->instrument; +#else + Instrumentation *instr = sps->planstate->instrument; +#endif + double subplan_time; + double loop_factor; + double cost_factor; /* * TODO: @@ -76,7 +80,7 @@ prediction_walker(PlanState *pstate, void *context) nloops = instr->nloops; #if PG_VERSION_NUM >= 190000 - subplan_time = INSTR_TIME_GET_MILLISEC(instr->total); + subplan_time = INSTR_TIME_GET_MILLISEC(instr->instr.total); #else subplan_time = instr->total * 1000.; #endif @@ -116,8 +120,8 @@ prediction_walker(PlanState *pstate, void *context) InstrEndLoop(pstate->instrument); nloops = pstate->instrument->nloops; #if PG_VERSION_NUM >= 190000 - node_time = INSTR_TIME_IS_ZERO(pstate->instrument->total) ? 0.0 : - INSTR_TIME_GET_MILLISEC(pstate->instrument->total); + node_time = INSTR_TIME_IS_ZERO(pstate->instrument->instr.total) ? 0.0 : + INSTR_TIME_GET_MILLISEC(pstate->instrument->instr.total); #else node_time = pstate->instrument->total * 1000.; #endif @@ -178,8 +182,11 @@ prediction_walker(PlanState *pstate, void *context) */ for (i = 0; i < pstate->worker_instrument->num_workers; i++) { - Instrumentation *instr = &pstate->worker_instrument->instrument[i]; - +#if PG_VERSION_NUM >= 190000 + NodeInstrumentation *instr = &pstate->worker_instrument->instrument[i]; +#else + Instrumentation *instr = &pstate->worker_instrument->instrument[i]; +#endif if (instr->nloops <= 0.0) { /*