From 1b3d20388ef829df7df9b2f3ea70becbdd9e6291 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Tue, 17 Feb 2026 23:41:38 +0500 Subject: [PATCH] Reset current_hostgroup to default when no query rule matches In the extended query protocol flow (Parse/Bind/Execute/Sync messages), queries without matching query rules were incorrectly retaining the current_hostgroup value from the previous query instead of being reset to the default_hostgroup. This happened because: - Simple query protocol goes through STATE_SLEEP between queries, which resets current_hostgroup to default_hostgroup - Extended query protocol does NOT go through STATE_SLEEP between Parse/Bind/Execute messages, so current_hostgroup was never reset --- lib/PgSQL_Session.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/PgSQL_Session.cpp b/lib/PgSQL_Session.cpp index 086148c38..b4846038c 100644 --- a/lib/PgSQL_Session.cpp +++ b/lib/PgSQL_Session.cpp @@ -4470,8 +4470,13 @@ __exit_set_destination_hostgroup: next_query_flagIN = qpo->next_query_flagIN; } - if (qpo->destination_hostgroup >= 0 && transaction_persistent_hostgroup == -1) { - current_hostgroup = qpo->destination_hostgroup; + if (transaction_persistent_hostgroup == -1) { + if (qpo->destination_hostgroup >= 0) { + current_hostgroup = qpo->destination_hostgroup; + } else { + // No query rule matched - use default hostgroup + current_hostgroup = default_hostgroup; + } } // Hostgroup locking check