From 78a6de18ce831e53a85cc525dd59294207e38721 Mon Sep 17 00:00:00 2001 From: zhangwenchao <656540940@qq.com> Date: Thu, 23 Nov 2023 10:39:47 +0800 Subject: [PATCH] Judge whether commands need to be dispatched to QEs in QD --- src/backend/utils/misc/guc.c | 60 +++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index e9881d2bc7d..6b0f9548101 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -252,6 +252,7 @@ static double defunct_double = 0; static ConfigVariable *ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel); +static bool CdbDoesNeedDispatchCommand(VariableSetStmt *stmt); /* * Options for enum values defined in this module. @@ -8943,7 +8944,9 @@ void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel) { GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET; + bool need_dispatch = false; + need_dispatch = CdbDoesNeedDispatchCommand(stmt); /* * Workers synchronize these parameters at the start of the parallel * operation; then, we block SET during the operation. @@ -8969,7 +8972,8 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel) (superuser() ? PGC_SUSET : PGC_USERSET), PGC_S_SESSION, action, true, 0, false); - DispatchSetPGVariable(stmt->name, stmt->args, stmt->is_local); + if (need_dispatch) + DispatchSetPGVariable(stmt->name, stmt->args, stmt->is_local); break; case VAR_SET_MULTI: @@ -8992,14 +8996,14 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel) DefElem *item = (DefElem *) lfirst(head); if (strcmp(item->defname, "transaction_isolation") == 0) - SetPGVariable("transaction_isolation", - list_make1(item->arg), stmt->is_local); + SetPGVariableOptDispatch("transaction_isolation", + list_make1(item->arg), stmt->is_local, need_dispatch); else if (strcmp(item->defname, "transaction_read_only") == 0) - SetPGVariable("transaction_read_only", - list_make1(item->arg), stmt->is_local); + SetPGVariableOptDispatch("transaction_read_only", + list_make1(item->arg), stmt->is_local, need_dispatch); else if (strcmp(item->defname, "transaction_deferrable") == 0) - SetPGVariable("transaction_deferrable", - list_make1(item->arg), stmt->is_local); + SetPGVariableOptDispatch("transaction_deferrable", + list_make1(item->arg), stmt->is_local, need_dispatch); else elog(ERROR, "unexpected SET TRANSACTION element: %s", item->defname); @@ -9014,14 +9018,14 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel) DefElem *item = (DefElem *) lfirst(head); if (strcmp(item->defname, "transaction_isolation") == 0) - SetPGVariable("default_transaction_isolation", - list_make1(item->arg), stmt->is_local); + SetPGVariableOptDispatch("default_transaction_isolation", + list_make1(item->arg), stmt->is_local, need_dispatch); else if (strcmp(item->defname, "transaction_read_only") == 0) - SetPGVariable("default_transaction_read_only", - list_make1(item->arg), stmt->is_local); + SetPGVariableOptDispatch("default_transaction_read_only", + list_make1(item->arg), stmt->is_local, need_dispatch); else if (strcmp(item->defname, "transaction_deferrable") == 0) - SetPGVariable("default_transaction_deferrable", - list_make1(item->arg), stmt->is_local); + SetPGVariableOptDispatch("default_transaction_deferrable", + list_make1(item->arg), stmt->is_local, need_dispatch); else elog(ERROR, "unexpected SET SESSION element: %s", item->defname); @@ -9069,7 +9073,7 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel) stmt->kind == VAR_RESET || stmt->kind == VAR_RESET_ALL) { - if (Gp_role == GP_ROLE_DISPATCH) + if (Gp_role == GP_ROLE_DISPATCH && need_dispatch) { /* * RESET must be dispatched different, because it can't @@ -13020,4 +13024,32 @@ check_default_with_oids(bool *newval, void **extra, GucSource source) return true; } +static bool +CdbDoesNeedDispatchCommand(VariableSetStmt *stmt) +{ + bool need_dispatch = true; + + switch (stmt->kind) + { + case VAR_SET_VALUE: + case VAR_SET_CURRENT: + case VAR_SET_DEFAULT: + if (strcmp(stmt->name, "hashdata.warehouse") == 0) + need_dispatch = false; + break; + case VAR_SET_MULTI: + if (strcmp(stmt->name, "TRANSACTION") == 0) + need_dispatch = false; + else if (strcmp(stmt->name, "SESSION CHARACTERISTICS") == 0) + need_dispatch = false; + else if ((strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)) + need_dispatch = false; + break; + default: + break; + } + + return need_dispatch; +} + #include "guc-file.c"