Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Global #6957

Merged
merged 3 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions go/vt/vtgate/executor_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ func TestExecutorSet(t *testing.T) {
}, {
in: "set client_found_rows = false",
out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}},
}, {
in: "set @@global.client_found_rows = 1",
err: "unsupported global scope in set: global client_found_rows = 1",
}, {
in: "set global client_found_rows = 1",
err: "unsupported global scope in set: global client_found_rows = 1",
}, {
in: "set global @@session.client_found_rows = 1",
err: "cannot use scope and @@",
Expand Down Expand Up @@ -269,6 +263,8 @@ func TestExecutorSetOp(t *testing.T) {
sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("client_found_rows", "int64")),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("client_found_rows", "int64")),
})

testcases := []struct {
Expand Down Expand Up @@ -312,6 +308,10 @@ func TestExecutorSetOp(t *testing.T) {
in: "set character_set_results='latin1'",
}, {
in: "set character_set_results='abcd'",
}, {
in: "set @@global.client_found_rows = 1",
}, {
in: "set global client_found_rows = 1",
}}
for _, tcase := range testcases {
t.Run(tcase.in, func(t *testing.T) {
Expand Down
20 changes: 11 additions & 9 deletions go/vt/vtgate/planbuilder/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,38 @@ var sysVarPlanningFunc = map[string]planFunc{}

func buildSetPlan(stmt *sqlparser.Set, vschema ContextVSchema) (engine.Primitive, error) {
var setOps []engine.SetOp
var setOp engine.SetOp
var err error

ec := new(expressionConverter)

for _, expr := range stmt.Exprs {
// AST struct has been prepared before getting here, so no scope here means that
// we have a UDV. If the original query didn't explicitly specify the scope, it
// would have been explictly set to sqlparser.SessionStr before reaching this
// phase of planning
switch expr.Scope {
case sqlparser.GlobalScope:
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "unsupported global scope in set: %s", sqlparser.String(expr))
// AST struct has been prepared before getting here, so no scope here means that
// we have a UDV. If the original query didn't explicitly specify the scope, it
// would have been explictly set to sqlparser.SessionStr before reaching this
// phase of planning
setOp, err := planSysVarCheckIgnore(expr, vschema, true)
if err != nil {
return nil, err
}
setOps = append(setOps, setOp)
case sqlparser.ImplicitScope:
evalExpr, err := ec.convert(expr.Expr /*boolean*/, false /*identifierAsString*/, false)
if err != nil {
return nil, err
}
setOp = &engine.UserDefinedVariable{
setOp := &engine.UserDefinedVariable{
Name: expr.Name.Lowered(),
Expr: evalExpr,
}

setOps = append(setOps, setOp)
case sqlparser.SessionScope:
planFunc, ok := sysVarPlanningFunc[expr.Name.Lowered()]
if !ok {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "unsupported construct in set: %s", sqlparser.String(expr))
}
setOp, err = planFunc(expr, vschema, ec)
setOp, err := planFunc(expr, vschema, ec)
if err != nil {
return nil, err
}
Expand Down
27 changes: 27 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/set_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,30 @@
]
}
}

# set global autocommit to default
"set global autocommit = off"
{
"QueryType": "SET",
"Original": "set global autocommit = off",
"Instructions": {
"OperatorType": "Set",
"Ops": [
{
"Type": "SysVarCheckAndIgnore",
"Name": "autocommit",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetDestination": {},
"Expr": "0"
}
],
"Inputs": [
{
"OperatorType": "SingleRow"
}
]
}
}