From 04d38aebcf68a4cb7057b49a6ca171f65d785f8b Mon Sep 17 00:00:00 2001 From: zhenjinyang Date: Mon, 18 Mar 2024 16:24:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90bugfix=E3=80=91=E4=BF=AE=E5=A4=8Dbug?= =?UTF-8?q?=5Fremote=5Fexecute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/process/tcop/postgres.cpp | 5 +++-- src/gausskernel/storage/replication/libpqsw.cpp | 6 +++++- src/include/replication/libpqsw.h | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index 8d63ca90a..fabdf2d53 100755 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -2733,7 +2733,7 @@ static void exec_simple_query(const char* query_string, MessageType messageType, } if (libpqsw_get_redirect()) { - if (libpqsw_process_query_message(commandTag, NULL, querystringForLibpqsw)) { + if (libpqsw_process_query_message(commandTag, NULL, querystringForLibpqsw, is_multistmt, lnext(parsetree_item) == NULL)) { libpqsw_trace_q_msg(commandTag, querystringForLibpqsw); if (snapshot_set) { PopActiveSnapshot(); @@ -2854,7 +2854,8 @@ static void exec_simple_query(const char* query_string, MessageType messageType, break; } - if (libpqsw_process_query_message(commandTag, querytree_list, querystringForLibpqsw)) { + // Mixed statement judgments + if (libpqsw_process_query_message(commandTag, querytree_list, querystringForLibpqsw, is_multistmt, lnext(parsetree_item) == NULL)) { libpqsw_trace_q_msg(commandTag, querystringForLibpqsw); if (libpqsw_begin_command(commandTag) || libpqsw_end_command(commandTag)) { libpqsw_trace("libpq send sql at my side as well:%s", commandTag); diff --git a/src/gausskernel/storage/replication/libpqsw.cpp b/src/gausskernel/storage/replication/libpqsw.cpp index 57f30fcd6..1373ebbb8 100644 --- a/src/gausskernel/storage/replication/libpqsw.cpp +++ b/src/gausskernel/storage/replication/libpqsw.cpp @@ -1034,7 +1034,7 @@ bool libpqsw_process_parse_message(const char* commandTag, List* query_list) } /* process Q type msg, true if need in redirect mode*/ -bool libpqsw_process_query_message(const char* commandTag, List* query_list, const char* query_string) +bool libpqsw_process_query_message(const char* commandTag, List* query_list, const char* query_string, bool is_multistmt, bool is_last) { if (IsAbortedTransactionBlockState()) { return false; @@ -1048,6 +1048,10 @@ bool libpqsw_process_query_message(const char* commandTag, List* query_list, con appendStringInfoString(curMsg, query_string); appendStringInfoChar(curMsg, 0); RedirectType type = RT_NORMAL; + // If the SQL statement is mixed and the current SQL statement is not the last statement in the mixed statement, the status is set to RT_MULTI*/ + if (is_multistmt && !is_last) { + type = RT_MULTI; + } if (libpqsw_begin_command(commandTag) || libpqsw_end_command(commandTag)) { type = RT_TXN_STATUS; } diff --git a/src/include/replication/libpqsw.h b/src/include/replication/libpqsw.h index 8365743ff..511d93593 100644 --- a/src/include/replication/libpqsw.h +++ b/src/include/replication/libpqsw.h @@ -46,7 +46,7 @@ bool libpqsw_process_message(int qtype, const StringInfo msg); /* process P type msg, true if need redirect*/ bool libpqsw_process_parse_message(const char* commandTag, List* query_list); /* process Q type msg, true if need in redirect mode*/ -bool libpqsw_process_query_message(const char* commandTag, List* query_list, const char* query_string); +bool libpqsw_process_query_message(const char* commandTag, List* query_list, const char* query_string, bool is_multistmt, bool is_last); /* is need send ready_for_query messge to front, if in redirect then false*/ bool libpqsw_need_end(); /* udpate if need ready_for_query messge flag */ @@ -136,6 +136,7 @@ typedef struct { enum RedirectType { RT_NORMAL, //transfer to standby RT_TXN_STATUS, + RT_MULTI, // multi stmt RT_SET //not transfer to standby,set props=xxx or 'C' close msg };