Skip to content

Commit

Permalink
Judge whether commands need to be dispatched to QEs in QD
Browse files Browse the repository at this point in the history
  • Loading branch information
wenchaozhang-123 committed Nov 23, 2023
1 parent bee51f5 commit 78a6de1
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions src/backend/utils/misc/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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:

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"

0 comments on commit 78a6de1

Please sign in to comment.