Skip to content

Commit 3783573

Browse files
committed
Making SHOW VARIABLES show boolean values as ON/OFF to match MySQL.
1 parent 3d7fa0e commit 3783573

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

enginetest/queries/queries.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5076,19 +5076,19 @@ SELECT * FROM cte WHERE d = 2;`,
50765076
{
50775077
Query: `SHOW VARIABLES WHERE Variable_name = 'version' || variable_name = 'autocommit'`,
50785078
Expected: []sql.Row{
5079-
{"autocommit", 1}, {"version", "8.0.31"},
5079+
{"autocommit", "ON"}, {"version", "8.0.31"},
50805080
},
50815081
},
50825082
{
50835083
Query: `SHOW VARIABLES WHERE Variable_name > 'version' and variable_name like '%_%'`,
50845084
Expected: []sql.Row{
5085-
{"version_comment", "Dolt"}, {"version_compile_machine", ""}, {"version_compile_os", ""}, {"version_compile_zlib", ""}, {"wait_timeout", 28800}, {"windowing_use_high_precision", 1},
5085+
{"version_comment", "Dolt"}, {"version_compile_machine", ""}, {"version_compile_os", ""}, {"version_compile_zlib", ""}, {"wait_timeout", 28800}, {"windowing_use_high_precision", "ON"},
50865086
},
50875087
},
50885088
{
50895089
Query: `SHOW VARIABLES WHERE "1" and variable_name = 'autocommit'`,
50905090
Expected: []sql.Row{
5091-
{"autocommit", 1},
5091+
{"autocommit", "ON"},
50925092
},
50935093
},
50945094
{
@@ -5105,8 +5105,8 @@ SELECT * FROM cte WHERE d = 2;`,
51055105
{"block_encryption_mode", "aes-128-ecb"},
51065106
{"gtid_mode", "OFF"},
51075107
{"innodb_autoinc_lock_mode", int64(2)},
5108-
{"offline_mode", int64(0)},
5109-
{"pseudo_slave_mode", int64(0)},
5108+
{"offline_mode", "OFF"},
5109+
{"pseudo_slave_mode", "OFF"},
51105110
{"rbr_exec_mode", "STRICT"},
51115111
{"sql_mode", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"},
51125112
{"ssl_fips_mode", "OFF"},

sql/rowexec/show.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,20 @@ func (b *BaseBuilder) buildShowVariables(ctx *sql.Context, n *plan.ShowVariables
557557
continue
558558
}
559559
}
560-
rows = append(rows, sql.NewRow(k, v))
560+
561+
// SHOW VARIABLES displays boolean values as "ON" or "OFF".
562+
if boolVal, isBoolVal := v.(int8); isBoolVal {
563+
switch boolVal {
564+
case 0:
565+
rows = append(rows, sql.NewRow(k, "OFF"))
566+
case 1:
567+
rows = append(rows, sql.NewRow(k, "ON"))
568+
default:
569+
rows = append(rows, sql.NewRow(k, v))
570+
}
571+
} else {
572+
rows = append(rows, sql.NewRow(k, v))
573+
}
561574
}
562575

563576
sort.Slice(rows, func(i, j int) bool {

sql/rowexec/showvariables_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ func TestShowVariables(t *testing.T) {
4444

4545
t.Logf("key: %s\tval: %v\n", key, val)
4646

47-
require.Equal(vars[key], val)
47+
// int8 values are interpreted as boolean values
48+
if int8Val, isInt8 := vars[key].(int8); isInt8 {
49+
if int8Val == 0 {
50+
require.Equal("OFF", val)
51+
} else if int8Val == 1 {
52+
require.Equal("ON", val)
53+
} else {
54+
require.Failf("unexpected value for int8 system variable: %s: %v", key, val)
55+
}
56+
} else {
57+
require.Equal(vars[key], val)
58+
}
59+
4860
delete(vars, key)
4961
}
5062
if err != io.EOF {

sql/variables/system_variables.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,24 @@ var systemVars = map[string]sql.SystemVariable{
12861286
// Integrators who provide binary logging may change this default.
12871287
Default: int8(0),
12881288
},
1289+
"log_replica_updates": &sql.MysqlSystemVariable{
1290+
Name: "log_replica_updates",
1291+
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Persist),
1292+
Dynamic: true,
1293+
SetVarHintApplies: false,
1294+
Type: types.NewSystemBoolType("log_replica_updates"),
1295+
Default: int8(1),
1296+
},
1297+
"log_slave_updates": &sql.MysqlSystemVariable{
1298+
// TODO: This var should be an *alias* for log_replica_updates, but
1299+
// we don't support system variable aliases yet.
1300+
Name: "log_slave_updates",
1301+
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Persist),
1302+
Dynamic: true,
1303+
SetVarHintApplies: false,
1304+
Type: types.NewSystemBoolType("log_slave_updates"),
1305+
Default: int8(1),
1306+
},
12891307
"log_error": &sql.MysqlSystemVariable{
12901308
Name: "log_error",
12911309
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global),
@@ -2041,7 +2059,7 @@ var systemVars = map[string]sql.SystemVariable{
20412059
Dynamic: true,
20422060
SetVarHintApplies: false,
20432061
Type: types.NewSystemUintType("query_cache_size", 0, 18446744073709551615),
2044-
Default: int8(1),
2062+
Default: 1,
20452063
},
20462064
"query_cache_type": &sql.MysqlSystemVariable{
20472065
Name: "query_cache_type",
@@ -2933,31 +2951,31 @@ var systemVars = map[string]sql.SystemVariable{
29332951
Dynamic: true,
29342952
SetVarHintApplies: false,
29352953
Type: types.NewSystemIntType("validate_password.length", 0, 2147483647, false),
2936-
Default: int8(8),
2954+
Default: 8,
29372955
},
29382956
"validate_password.number_count": &sql.MysqlSystemVariable{
29392957
Name: "validate_password.number_count",
29402958
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global),
29412959
Dynamic: true,
29422960
SetVarHintApplies: false,
29432961
Type: types.NewSystemIntType("validate_password.number_count", 0, 2147483647, false),
2944-
Default: int8(1),
2962+
Default: 1,
29452963
},
29462964
"validate_password.mixed_case_count": &sql.MysqlSystemVariable{
29472965
Name: "validate_password.mixed_case_count",
29482966
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global),
29492967
Dynamic: true,
29502968
SetVarHintApplies: false,
29512969
Type: types.NewSystemIntType("validate_password.mixed_case_count", 0, 2147483647, false),
2952-
Default: int8(1),
2970+
Default: 1,
29532971
},
29542972
"validate_password.special_char_count": &sql.MysqlSystemVariable{
29552973
Name: "validate_password.special_char_count",
29562974
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global),
29572975
Dynamic: true,
29582976
SetVarHintApplies: false,
29592977
Type: types.NewSystemIntType("validate_password.special_char_count", 0, 2147483647, false),
2960-
Default: int8(1),
2978+
Default: 1,
29612979
},
29622980
"validate_user_plugins": &sql.MysqlSystemVariable{
29632981
Name: "validate_user_plugins",

0 commit comments

Comments
 (0)