Skip to content

Commit

Permalink
added set sys var unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Jul 24, 2020
1 parent 1c8771d commit 05dd2fe
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 13 deletions.
3 changes: 3 additions & 0 deletions go/test/endtoend/vtgate/setstatement/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func TestSetSystemVariable(t *testing.T) {
checkedExec(t, conn, "set @@sql_mode = ''")

assertMatches(t, conn, q, `[[DATE("0000-00-00")]]`)

checkedExec(t, conn, "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483")
assertMatches(t, conn, "select @@sql_mode", `[[VARCHAR("NO_AUTO_VALUE_ON_ZERO,STRICT_ALL_TABLES")]]`)
}

func TestSetSystemVarWithTxFailure(t *testing.T) {
Expand Down
26 changes: 15 additions & 11 deletions go/vt/vtgate/executor_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,17 @@ func TestExecutorSet(t *testing.T) {
in: "set skip_query_plan_cache = 0",
out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}},
}, {
in: "set sql_auto_is_null = 0",
out: &vtgatepb.Session{Autocommit: true}, // no effect
}, {
in: "set sql_auto_is_null = 1",
err: "sql_auto_is_null is not currently supported",
in: "set sql_auto_is_null = 0",
out: &vtgatepb.Session{Autocommit: true, Warnings: []*querypb.QueryWarning{{
Code: 1235,
Message: "Ignored inapplicable SET sql_auto_is_null = 0",
}}},
}, {
in: "set sql_auto_is_null = 1",
out: &vtgatepb.Session{Autocommit: true, Warnings: []*querypb.QueryWarning{{
Code: 1235,
Message: "Ignored inapplicable SET sql_auto_is_null = 1",
}}},
}, {
in: "set tx_read_only = 2",
err: "unexpected value for tx_read_only: 2",
Expand Down Expand Up @@ -303,12 +309,10 @@ func TestExecutorSetOp(t *testing.T) {
executor, _, _, sbclookup := createLegacyExecutorEnv()

sbclookup.SetResults([]*sqltypes.Result{
sqltypes.MakeTestResult(sqltypes.MakeTestFields("'STRICT_ALL_TABLES'", "varchar"), "STRICT_ALL_TABLES"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("'STRICT_ALL_TABLES,NO_AUTO_UPDATES'", "varchar"), "STRICT_ALL_TABLES,NO_AUTO_UPDATES"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("1", "int64"), "1"),
})
//sbc1.SetResults([]*sqltypes.Result{
// sqltypes.MakeTestResult(sqltypes.MakeTestFields("1", "int64"), "1"),
//})

testcases := []struct {
in string
warning []*querypb.QueryWarning
Expand All @@ -320,8 +324,8 @@ func TestExecutorSetOp(t *testing.T) {
Message: "Ignored inapplicable SET big_tables = 1",
}},
}, {
in: "set sql_mode = 'STRICT_ALL_TABLES'",
sysVars: map[string]string{"sql_mode": "STRICT_ALL_TABLES"},
in: "set sql_mode = 'STRICT_ALL_TABLES,NO_AUTO_UPDATES'",
sysVars: map[string]string{"sql_mode": "'STRICT_ALL_TABLES,NO_AUTO_UPDATES'"},
}, {
in: "set sql_safe_updates = 1",
sysVars: map[string]string{"sql_safe_updates": "1"},
Expand Down
2 changes: 2 additions & 0 deletions go/vt/vtgate/planbuilder/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ var ignoreThese = []string{
"query_prealloc_size",
"sql_buffer_result",
"transaction_alloc_block_size",
"sql_auto_is_null",
"wait_timeout",
}

var saveSettingsToSession = []string{
Expand Down
62 changes: 62 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/set_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,65 @@
# only allow whitelisted functions
"set @foo = BAD_FUNC()"
"expression not supported for SET: BAD_FUNC()"

# single sysvar cases
"SET sql_mode = 'STRICT_ALL_TABLES,NO_AUTO_VALUE_ON_ZERO'"
{
"QueryType": "SET",
"Original": "SET sql_mode = 'STRICT_ALL_TABLES,NO_AUTO_VALUE_ON_ZERO'",
"Instructions": {
"OperatorType": "Set",
"Ops": [
{
"Type": "SysVarSet",
"Name": "sql_mode",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"Expr": "'STRICT_ALL_TABLES,NO_AUTO_VALUE_ON_ZERO'"
}
],
"Inputs": [
{
"OperatorType": "SingleRow"
}
]
}
}

# multiple sysvar cases
"SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483"
{
"QueryType": "SET",
"Original": "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483",
"Instructions": {
"OperatorType": "Set",
"Ops": [
{
"Type": "SysVarSet",
"Name": "sql_mode",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"Expr": "CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO')"
},
{
"Type": "SysVarIgnore",
"Name": "sql_auto_is_null",
"Expr": "0"
},
{
"Type": "SysVarIgnore",
"Name": "wait_timeout",
"Expr": "2147483"
}
],
"Inputs": [
{
"OperatorType": "SingleRow"
}
]
}
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"plan building not supported"

# set user defined and system variable
"set @foo = 42, @bar = @foo, @@wait_timeout = 28800"
"set @foo = 42, @bar = @foo, @@xyz = 28800"
"plan building not supported"

# SHOW
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/stateful_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (sc *StatefulConnection) Exec(ctx context.Context, query string, maxrows in
default:
sc.env.CheckMySQL()
}
return nil, vterrors.Wrap(err, "lost connection to database server")
return nil, err
}
return nil, err
}
Expand Down

0 comments on commit 05dd2fe

Please sign in to comment.