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

sessionctx: add testcase for set_var hint #46784

Merged
merged 2 commits into from
Sep 8, 2023
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
7 changes: 6 additions & 1 deletion sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,12 @@
if err != nil {
return "", err
}
oldV := sv.Value
// The map s.systems[sv.Name] is lazy initialized. If we directly read it, we might read empty result.
// Since this code path is not a hot path, we directly call GetSessionOrGlobalSystemVar to get the value safely.
oldV, err := s.GetSessionOrGlobalSystemVar(context.Background(), sv.Name)
if err != nil {
return "", err
}

Check warning on line 2544 in sessionctx/variable/session.go

View check run for this annotation

Codecov / codecov/patch

sessionctx/variable/session.go#L2543-L2544

Added lines #L2543 - L2544 were not covered by tests
return oldV, sv.SetSessionFromHook(s, val)
}

Expand Down
20 changes: 20 additions & 0 deletions sessionctx/variable/setvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ func TestSetVarNonStringOrEnum(t *testing.T) {
tk.MustQuery(fmt.Sprintf("select @@%v", c.varName)).Check(r)
}
}

tk.MustQuery("select @@max_execution_time").Check(testkit.Rows("0"))
tk.MustExec("set @@max_execution_time=1000")
tk.MustQuery("select @@max_execution_time").Check(testkit.Rows("1000"))
tk.MustQuery("select /*+ set_var(max_execution_time=100) */ @@max_execution_time").Check(testkit.Rows("100"))
// The value is the changed value 1000, not the default value 0.
tk.MustQuery("select @@max_execution_time").Check(testkit.Rows("1000"))

tk.MustExec("set @@global.max_execution_time=1000")

tk2 := testkit.NewTestKit(t, store)
tk2.MustQuery("select @@max_execution_time").Check(testkit.Rows("1000"))
tk2.MustQuery("select /*+ set_var(max_execution_time=100) */ @@max_execution_time").Check(testkit.Rows("100"))
// The value is the global value 1000, not the default value 0.
tk2.MustQuery("select @@max_execution_time").Check(testkit.Rows("1000"))
tk2.MustExec("set @@max_execution_time=2000")
tk2.MustQuery("select @@max_execution_time").Check(testkit.Rows("2000"))
tk2.MustQuery("select /*+ set_var(max_execution_time=100) */ @@max_execution_time").Check(testkit.Rows("100"))
// The value is the changed value 2000, not the default value 0 or the global value 1000.
tk2.MustQuery("select @@max_execution_time").Check(testkit.Rows("2000"))
}

func TestSetVarStringOrEnum(t *testing.T) {
Expand Down