From f0cf4fb884e3a75940300691ce0c7908f2f39cad Mon Sep 17 00:00:00 2001 From: Sami Imseih Date: Wed, 14 Aug 2024 20:50:37 +0000 Subject: [PATCH v4 2/2] Report new queryId after plancache re-validation --- src/backend/utils/cache/plancache.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index 5af1a168ec..aa507846d6 100644 --- a/src/backend/utils/cache/plancache.c +++ b/src/backend/utils/cache/plancache.c @@ -66,6 +66,7 @@ #include "storage/lmgr.h" #include "tcop/pquery.h" #include "tcop/utility.h" +#include "utils/backend_status.h" #include "utils/inval.h" #include "utils/memutils.h" #include "utils/resowner.h" @@ -590,6 +591,7 @@ RevalidateCachedQuery(CachedPlanSource *plansource, TupleDesc resultDesc; MemoryContext querytree_context; MemoryContext oldcxt; + ListCell *lc; /* * For one-shot plans, we do not support revalidation checking; it's @@ -805,6 +807,21 @@ RevalidateCachedQuery(CachedPlanSource *plansource, plansource->is_valid = true; + /* + * Override the current queryId with the one from the re-validated + * query tree. + */ + foreach(lc, tlist) + { + Query *stmt = lfirst_node(Query, lc); + + if (stmt->queryId != UINT64CONST(0)) + { + pgstat_report_query_id(stmt->queryId, true); + break; + } + } + /* Return transient copy of querytrees for possible use in planning */ return tlist; } -- 2.43.0