Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei committed Mar 7, 2024
1 parent 815221b commit e84c73c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions pkg/bindinfo/tests/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ func TestBindingSymbolList(t *testing.T) {
require.NoError(t, err)

_, fuzzyDigest := norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select `a` , `b` from `test` . `t` where `a` = ? limit ...", binding.OriginalSQL)
require.Equal(t, "SELECT `a`,`b` FROM `test`.`t` USE INDEX (`ib`) WHERE `a` = 1 LIMIT 0,1", binding.BindSQL)
require.Equal(t, "test", binding.Db)
Expand Down Expand Up @@ -368,8 +369,9 @@ func TestBindingInListWithSingleLiteral(t *testing.T) {
require.NoError(t, err)

_, fuzzyDigest := norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select `a` , `b` from `test` . `t` where `a` in ( ... )", binding.OriginalSQL)
require.Equal(t, "SELECT `a`,`b` FROM `test`.`t` USE INDEX (`ib`) WHERE `a` IN (1,2,3)", binding.BindSQL)
require.Equal(t, "test", binding.Db)
Expand Down Expand Up @@ -404,8 +406,9 @@ func TestBestPlanInBaselines(t *testing.T) {
stmt, _, _ := internal.UtilNormalizeWithDefaultDB(t, "select a, b from t where a = 1 limit 0, 1")

_, fuzzyDigest := norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select `a` , `b` from `test` . `t` where `a` = ? limit ...", binding.OriginalSQL)
require.Equal(t, "SELECT /*+ use_index(@`sel_1` `test`.`t` `ia`)*/ `a`,`b` FROM `test`.`t` WHERE `a` = 1 LIMIT 0,1", binding.BindSQL)
require.Equal(t, "test", binding.Db)
Expand Down Expand Up @@ -451,8 +454,9 @@ func TestErrorBind(t *testing.T) {
stmt, err := parser.New().ParseOneStmt("select * from test . t where i > ?", "", "")
require.NoError(t, err)
_, fuzzyDigest := norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select * from `test` . `t` where `i` > ?", binding.OriginalSQL)
require.Equal(t, "SELECT * FROM `test`.`t` USE INDEX (`index_t`) WHERE `i` > 100", binding.BindSQL)
require.Equal(t, "test", binding.Db)
Expand Down Expand Up @@ -508,40 +512,44 @@ func TestHintsSetID(t *testing.T) {
stmt, err := parser.New().ParseOneStmt("select * from t where a > ?", "", "")
require.NoError(t, err)
_, fuzzyDigest := norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed := dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.Equal(t, "select * from `test` . `t` where `a` > ?", binding.OriginalSQL)
require.Equal(t, "use_index(@`sel_1` `test`.`t` `idx_a`)", binding.ID)

internal.UtilCleanBindingEnv(tk, dom)
tk.MustExec("create global binding for select * from t where a > 10 using select /*+ use_index(t, idx_a) */ * from t where a > 10")
_, fuzzyDigest = norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select * from `test` . `t` where `a` > ?", binding.OriginalSQL)
require.Equal(t, "use_index(@`sel_1` `test`.`t` `idx_a`)", binding.ID)

internal.UtilCleanBindingEnv(tk, dom)
tk.MustExec("create global binding for select * from t where a > 10 using select /*+ use_index(@sel_1 t, idx_a) */ * from t where a > 10")
_, fuzzyDigest = norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select * from `test` . `t` where `a` > ?", binding.OriginalSQL)
require.Equal(t, "use_index(@`sel_1` `test`.`t` `idx_a`)", binding.ID)

internal.UtilCleanBindingEnv(tk, dom)
tk.MustExec("create global binding for select * from t where a > 10 using select /*+ use_index(@qb1 t, idx_a) qb_name(qb1) */ * from t where a > 10")
_, fuzzyDigest = norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select * from `test` . `t` where `a` > ?", binding.OriginalSQL)
require.Equal(t, "use_index(@`sel_1` `test`.`t` `idx_a`)", binding.ID)

internal.UtilCleanBindingEnv(tk, dom)
tk.MustExec("create global binding for select * from t where a > 10 using select /*+ use_index(T, IDX_A) */ * from t where a > 10")
_, fuzzyDigest = norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select * from `test` . `t` where `a` > ?", binding.OriginalSQL)
require.Equal(t, "use_index(@`sel_1` `test`.`t` `idx_a`)", binding.ID)

Expand All @@ -550,8 +558,9 @@ func TestHintsSetID(t *testing.T) {
require.True(t, terror.ErrorEqual(err, parser.ErrParse))
tk.MustExec("create global binding for select * from t where a > 10 using select * from t where a > 10")
_, fuzzyDigest = norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true))
binding, matched = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
binding, matched, isMissed = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt))
require.True(t, matched)
require.False(t, isMissed)
require.Equal(t, "select * from `test` . `t` where `a` > ?", binding.OriginalSQL)
require.Equal(t, "", binding.ID)
}
Expand Down

0 comments on commit e84c73c

Please sign in to comment.