From b0804f3bc9268d7929488ce9f259154ad4874b38 Mon Sep 17 00:00:00 2001 From: Sami Imseih Date: Wed, 24 Apr 2024 01:24:56 +0000 Subject: [PATCH 1/1] Fix Extended QUery Protocol handling of queryId Unlike simple query protocol, extended query protocol requires 3 routines to execute a command: parse/bind/execute. In each one of these routines, the queryId is reset due to pgstat_report_activity(STATE_RUNNING) being called at the start of each routine. This fix adds pgstat_report_query_id during the bind and execution calls, after the reset of the queryId. --- src/backend/tcop/postgres.c | 6 ++++++ src/backend/tcop/pquery.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 76f48b13d2..3c3298d758 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -1679,6 +1679,12 @@ exec_bind_message(StringInfo input_message) pgstat_report_activity(STATE_RUNNING, psrc->query_string); + /* + * Report the query_id as it was reset by pgstat_report_activity. + */ + if (psrc->query_list) + pgstat_report_query_id(linitial_node(Query, psrc->query_list)->queryId, false); + set_ps_display("BIND"); if (save_log_statement_stats) diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index 0c45fcf318..729fc44c3b 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -24,6 +24,7 @@ #include "pg_trace.h" #include "tcop/pquery.h" #include "tcop/utility.h" +#include "utils/backend_status.h" #include "utils/memutils.h" #include "utils/snapmgr.h" @@ -891,6 +892,9 @@ PortalRunSelect(Portal portal, if (queryDesc) queryDesc->dest = dest; + if (queryDesc) + pgstat_report_query_id(queryDesc->plannedstmt->queryId, false); + /* * Determine which direction to go in, and check to see if we're already * at the end of the available tuples in that direction. If so, set the @@ -1218,6 +1222,8 @@ PortalRunMulti(Portal portal, { PlannedStmt *pstmt = lfirst_node(PlannedStmt, stmtlist_item); + pgstat_report_query_id(pstmt->queryId, false); + /* * If we got a cancel signal in prior command, quit */ -- 2.40.1