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

parser: restore set_var value to string instead of plain text (#50515) #50536

Merged
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
2 changes: 1 addition & 1 deletion pkg/bindinfo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ go_test(
embed = [":bindinfo"],
flaky = True,
race = "on",
shard_count = 42,
shard_count = 43,
deps = [
"//pkg/bindinfo/internal",
"//pkg/config",
Expand Down
26 changes: 26 additions & 0 deletions pkg/bindinfo/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,29 @@ func TestReloadBindings(t *testing.T) {
rows = tk.MustQuery("show global bindings").Rows()
require.Equal(t, 0, len(rows))
}

func TestSetVarFixControlWithBinding(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

tk.MustExec(`create table t(id int, a varchar(100), b int, c int, index idx_ab(a, b))`)
tk.MustQuery(`explain select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1))`).Check(
testkit.Rows(
`IndexLookUp_12 0.01 root `,
`├─Selection_10(Build) 0.02 cop[tikv] or(eq(test.t.a, "xx"), and(eq(test.t.a, "kk"), eq(test.t.b, 1)))`,
`│ └─IndexRangeScan_8 20.00 cop[tikv] table:t, index:idx_ab(a, b) range:["kk","kk"], ["xx","xx"], keep order:false, stats:pseudo`,
`└─Selection_11(Probe) 0.01 cop[tikv] eq(test.t.c, 10)`,
` └─TableRowIDScan_9 0.02 cop[tikv] table:t keep order:false, stats:pseudo`))

tk.MustExec(`create global binding for select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1)) using select /*+ set_var(tidb_opt_fix_control='44389:ON') */ * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1))`)
tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning

// the fix control can take effect
tk.MustQuery(`explain select * from t where c = 10 and (a = 'xx' or (a = 'kk' and b = 1))`).Check(
testkit.Rows(`IndexLookUp_11 0.01 root `,
`├─IndexRangeScan_8(Build) 10.10 cop[tikv] table:t, index:idx_ab(a, b) range:["kk" 1,"kk" 1], ["xx","xx"], keep order:false, stats:pseudo`,
`└─Selection_10(Probe) 0.01 cop[tikv] eq(test.t.c, 10)`,
` └─TableRowIDScan_9 10.10 cop[tikv] table:t keep order:false, stats:pseudo`))
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
}
2 changes: 1 addition & 1 deletion pkg/bindinfo/tests/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ func TestRuntimeHintsInEvolveTasks(t *testing.T) {
tk.MustExec("admin flush bindings")
rows := tk.MustQuery("show global bindings").Rows()
require.Len(t, rows, 2)
require.Equal(t, "SELECT /*+ use_index(@`sel_1` `test`.`t` `idx_c`), no_order_index(@`sel_1` `test`.`t` `idx_c`), max_execution_time(5000), set_var(tikv_client_read_timeout = 20)*/ * FROM `test`.`t` WHERE `a` >= 4 AND `b` >= 1 AND `c` = 0", rows[0][1])
require.Equal(t, "SELECT /*+ use_index(@`sel_1` `test`.`t` `idx_c`), no_order_index(@`sel_1` `test`.`t` `idx_c`), max_execution_time(5000), set_var(tikv_client_read_timeout = '20')*/ * FROM `test`.`t` WHERE `a` >= 4 AND `b` >= 1 AND `c` = 0", rows[0][1])
}

func TestCaptureBaselinesScope(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3788,7 +3788,7 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
hintData := n.HintData.(HintSetVar)
ctx.WritePlain(hintData.VarName)
ctx.WritePlain(" = ")
ctx.WritePlain(hintData.Value)
ctx.WriteString(hintData.Value)
}
ctx.WritePlain(")")
return nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,8 @@ AAAAAAAAAAAA5gm5Mg==
{"query watch add SQL TEXT SIMILAR 'select 1'", false, ""},
{"query watch remove 1", true, "QUERY WATCH REMOVE 1"},
{"query watch remove", false, ""},

// for issue 34325, "replace into" with hints
{"replace /*+ SET_VAR(sql_mode='ALLOW_INVALID_DATES') */ into t values ('2004-04-31');", true, "REPLACE /*+ SET_VAR(sql_mode = ALLOW_INVALID_DATES)*/ INTO `t` VALUES (_UTF8MB4'2004-04-31')"},
{"replace /*+ SET_VAR(sql_mode='ALLOW_INVALID_DATES') */ into t values ('2004-04-31');", true, "REPLACE /*+ SET_VAR(sql_mode = 'ALLOW_INVALID_DATES')*/ INTO `t` VALUES (_UTF8MB4'2004-04-31')"},
}
RunTest(t, table, false)
}
Expand Down