Skip to content

Commit 5d82109

Browse files
Merge pull request #2984 from dolthub/nathan/lock-warnings
Add lock_warnings system variable.
2 parents e865d1c + 421019f commit 5d82109

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

engine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ func clearWarnings(ctx *sql.Context, node sql.Node) {
268268
case *plan.Offset, *plan.Limit:
269269
// `show warning limit x offset y` is valid, so we need to recurse
270270
clearWarnings(ctx, n.Children()[0])
271+
case *plan.Set:
272+
// We want to maintain warnings when setting the warnings_lock variable.
273+
// Set statements also can't produce warnings, so we don't care about clearing them.
271274
case plan.ShowWarnings:
272275
// ShowWarnings should not clear the warnings, but should still reset the warning count.
273276
ctx.ClearWarningCount()

enginetest/queries/variable_queries.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,64 @@ var VariableQueries = []ScriptTest{
575575
},
576576
},
577577
},
578+
{
579+
Name: "locked warnings stay after query",
580+
SetUpScript: []string{
581+
"set @@lock_warnings = 1",
582+
"select 1/0,1/0",
583+
"select 1/1",
584+
},
585+
Assertions: []ScriptTestAssertion{
586+
{
587+
Query: "show warnings",
588+
Expected: []sql.Row{
589+
{"Warning", 1365, "Division by 0"},
590+
{"Warning", 1365, "Division by 0"}},
591+
},
592+
{
593+
Query: "select 1/0",
594+
SkipResultsCheck: true,
595+
},
596+
{
597+
Query: "show warnings",
598+
Expected: []sql.Row{
599+
{"Warning", 1365, "Division by 0"},
600+
{"Warning", 1365, "Division by 0"},
601+
{"Warning", 1365, "Division by 0"},
602+
},
603+
},
604+
},
605+
},
606+
{
607+
Name: "unlocked warnings clear after query",
608+
SetUpScript: []string{
609+
"set @@lock_warnings = 0",
610+
"select 1/0,1/0",
611+
"select 1/1",
612+
},
613+
Assertions: []ScriptTestAssertion{
614+
{
615+
Query: "show warnings",
616+
Expected: []sql.Row{},
617+
},
618+
},
619+
},
620+
{
621+
Name: "warnings persist after locking between queries",
622+
SetUpScript: []string{
623+
"select 1/0",
624+
"set @@lock_warnings = 1",
625+
"select 1/1",
626+
},
627+
Assertions: []ScriptTestAssertion{
628+
{
629+
Query: "show warnings",
630+
Expected: []sql.Row{
631+
{"Warning", 1365, "Division by 0"},
632+
},
633+
},
634+
},
635+
},
578636
//TODO: do not override tables with user-var-like names...but why would you do this??
579637
//{
580638
// Name: "user var table name no conflict",

sql/variables/system_variables.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,23 @@ var systemVars = map[string]sql.SystemVariable{
12531253
Type: types.NewSystemIntType("lock_wait_timeout", 1, 31536000, false),
12541254
Default: int64(31536000),
12551255
},
1256+
"lock_warnings": &sql.MysqlSystemVariable{
1257+
Name: "lock_warnings",
1258+
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Session),
1259+
Dynamic: true,
1260+
SetVarHintApplies: false,
1261+
Type: types.NewSystemBoolType("lock_warnings"),
1262+
Default: int8(0),
1263+
NotifyChanged: func(ctx *sql.Context, _ sql.SystemVariableScope, value sql.SystemVarValue) error {
1264+
switch value.Val.(int8) {
1265+
case 0:
1266+
ctx.UnlockWarnings()
1267+
case 1:
1268+
ctx.LockWarnings()
1269+
}
1270+
return nil
1271+
},
1272+
},
12561273
"log_bin": &sql.MysqlSystemVariable{
12571274
Name: "log_bin",
12581275
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Persist),

0 commit comments

Comments
 (0)