diff --git a/pkg/executor/test/executor/executor_test.go b/pkg/executor/test/executor/executor_test.go index dfb7488e9615b..eaa31c582ced8 100644 --- a/pkg/executor/test/executor/executor_test.go +++ b/pkg/executor/test/executor/executor_test.go @@ -18,7 +18,6 @@ import ( "archive/zip" "context" "fmt" - "math" "path/filepath" "reflect" "runtime" @@ -115,14 +114,6 @@ func TestBind(t *testing.T) { tk.MustExec("drop session binding for select * from testbind") } -func TestLoadStats(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - require.Error(t, tk.ExecToErr("load stats")) - require.Error(t, tk.ExecToErr("load stats ./xxx.json")) -} - func TestPlanReplayer(t *testing.T) { require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/infoschema/mockTiFlashStoreCount", `return(true)`)) defer func() { @@ -222,545 +213,6 @@ func TestPlanReplayerContinuesCapture(t *testing.T) { tk.MustQuery("select count(*) from mysql.plan_replayer_status").Check(testkit.Rows("1")) } -func TestShow(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database test_show;") - tk.MustExec("use test_show") - - tk.MustQuery("show engines") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int primary key)") - require.Len(t, tk.MustQuery("show index in t").Rows(), 1) - require.Len(t, tk.MustQuery("show index from t").Rows(), 1) - require.Len(t, tk.MustQuery("show master status").Rows(), 1) - - tk.MustQuery("show create database test_show").Check(testkit.Rows("test_show CREATE DATABASE `test_show` /*!40100 DEFAULT CHARACTER SET utf8mb4 */")) - tk.MustQuery("show privileges").Check(testkit.Rows("Alter Tables To alter the table", - "Alter routine Functions,Procedures To alter or drop stored functions/procedures", - "Config Server Admin To use SHOW CONFIG and SET CONFIG statements", - "Create Databases,Tables,Indexes To create new databases and tables", - "Create routine Databases To use CREATE FUNCTION/PROCEDURE", - "Create role Server Admin To create new roles", - "Create temporary tables Databases To use CREATE TEMPORARY TABLE", - "Create view Tables To create new views", - "Create user Server Admin To create new users", - "Delete Tables To delete existing rows", - "Drop Databases,Tables To drop databases, tables, and views", - "Drop role Server Admin To drop roles", - "Event Server Admin To create, alter, drop and execute events", - "Execute Functions,Procedures To execute stored routines", - "File File access on server To read and write files on the server", - "Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess", - "Index Tables To create or drop indexes", - "Insert Tables To insert data into tables", - "Lock tables Databases To use LOCK TABLES (together with SELECT privilege)", - "Process Server Admin To view the plain text of currently executing queries", - "Proxy Server Admin To make proxy user possible", - "References Databases,Tables To have references on tables", - "Reload Server Admin To reload or refresh tables, logs and privileges", - "Replication client Server Admin To ask where the slave or master servers are", - "Replication slave Server Admin To read binary log events from the master", - "Select Tables To retrieve rows from table", - "Show databases Server Admin To see all databases with SHOW DATABASES", - "Show view Tables To see views with SHOW CREATE VIEW", - "Shutdown Server Admin To shut down the server", - "Super Server Admin To use KILL thread, SET GLOBAL, CHANGE MASTER, etc.", - "Trigger Tables To use triggers", - "Create tablespace Server Admin To create/alter/drop tablespaces", - "Update Tables To update existing rows", - "Usage Server Admin No privileges - allow connect only", - "BACKUP_ADMIN Server Admin ", - "RESTORE_ADMIN Server Admin ", - "SYSTEM_USER Server Admin ", - "SYSTEM_VARIABLES_ADMIN Server Admin ", - "ROLE_ADMIN Server Admin ", - "CONNECTION_ADMIN Server Admin ", - "PLACEMENT_ADMIN Server Admin ", - "DASHBOARD_CLIENT Server Admin ", - "RESTRICTED_TABLES_ADMIN Server Admin ", - "RESTRICTED_STATUS_ADMIN Server Admin ", - "RESTRICTED_VARIABLES_ADMIN Server Admin ", - "RESTRICTED_USER_ADMIN Server Admin ", - "RESTRICTED_CONNECTION_ADMIN Server Admin ", - "RESTRICTED_REPLICA_WRITER_ADMIN Server Admin ", - "RESOURCE_GROUP_ADMIN Server Admin ", - )) - require.Len(t, tk.MustQuery("show table status").Rows(), 1) -} - -// TestSelectBackslashN Issue 3685. -func TestSelectBackslashN(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - sql := `select \N;` - tk.MustQuery(sql).Check(testkit.Rows("")) - rs, err := tk.Exec(sql) - require.NoError(t, err) - fields := rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "NULL", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select "\N";` - tk.MustQuery(sql).Check(testkit.Rows("N")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `N`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - tk.MustExec("use test;") - tk.MustExec("create table test (`\\N` int);") - tk.MustExec("insert into test values (1);") - tk.CheckExecResult(1, 0) - sql = "select * from test;" - tk.MustQuery(sql).Check(testkit.Rows("1")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `\N`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select \N from test;` - tk.MustQuery(sql).Check(testkit.Rows("")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.NoError(t, err) - require.Len(t, fields, 1) - require.Equal(t, `NULL`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select (\N) from test;` - tk.MustQuery(sql).Check(testkit.Rows("")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `NULL`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = "select `\\N` from test;" - tk.MustQuery(sql).Check(testkit.Rows("1")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `\N`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = "select (`\\N`) from test;" - tk.MustQuery(sql).Check(testkit.Rows("1")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `\N`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select '\N' from test;` - tk.MustQuery(sql).Check(testkit.Rows("N")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `N`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select ('\N') from test;` - tk.MustQuery(sql).Check(testkit.Rows("N")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `N`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) -} - -// TestSelectNull Issue #4053. -func TestSelectNull(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - sql := `select nUll;` - tk.MustQuery(sql).Check(testkit.Rows("")) - rs, err := tk.Exec(sql) - require.NoError(t, err) - fields := rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `NULL`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select (null);` - tk.MustQuery(sql).Check(testkit.Rows("")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `NULL`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select null+NULL;` - tk.MustQuery(sql).Check(testkit.Rows("")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.NoError(t, err) - require.Len(t, fields, 1) - require.Equal(t, `null+NULL`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) -} - -// TestSelectStringLiteral Issue #3686. -func TestSelectStringLiteral(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - sql := `select 'abc';` - tk.MustQuery(sql).Check(testkit.Rows("abc")) - rs, err := tk.Exec(sql) - require.NoError(t, err) - fields := rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `abc`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select (('abc'));` - tk.MustQuery(sql).Check(testkit.Rows("abc")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `abc`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select 'abc'+'def';` - tk.MustQuery(sql).Check(testkit.Rows("0")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, `'abc'+'def'`, fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - // Below checks whether leading invalid chars are trimmed. - sql = "select '\n';" - tk.MustQuery(sql).Check(testkit.Rows("\n")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = "select '\t col';" // Lowercased letter is a valid char. - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "col", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = "select '\t Col';" // Uppercased letter is a valid char. - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "Col", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = "select '\n\t 中文 col';" // Chinese char is a valid char. - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "中文 col", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = "select ' \r\n .col';" // Punctuation is a valid char. - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, ".col", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = "select ' 😆col';" // Emoji is a valid char. - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "😆col", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - // Below checks whether trailing invalid chars are preserved. - sql = `select 'abc ';` - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "abc ", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select ' abc 123 ';` - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "abc 123 ", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - // Issue #4239. - sql = `select 'a' ' ' 'string';` - tk.MustQuery(sql).Check(testkit.Rows("a string")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "a", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select 'a' " " "string";` - tk.MustQuery(sql).Check(testkit.Rows("a string")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "a", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select 'string' 'string';` - tk.MustQuery(sql).Check(testkit.Rows("stringstring")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "string", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select "ss" "a";` - tk.MustQuery(sql).Check(testkit.Rows("ssa")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "ss", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select "ss" "a" "b";` - tk.MustQuery(sql).Check(testkit.Rows("ssab")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "ss", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select "ss" "a" ' ' "b";` - tk.MustQuery(sql).Check(testkit.Rows("ssa b")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "ss", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) - - sql = `select "ss" "a" ' ' "b" ' ' "d";` - tk.MustQuery(sql).Check(testkit.Rows("ssa b d")) - rs, err = tk.Exec(sql) - require.NoError(t, err) - fields = rs.Fields() - require.Len(t, fields, 1) - require.Equal(t, "ss", fields[0].Column.Name.O) - require.NoError(t, rs.Close()) -} - -func TestUpdateClustered(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - type resultChecker struct { - check string - assert []string - } - - for _, clustered := range []string{"", "clustered"} { - tests := []struct { - initSchema []string - initData []string - dml string - resultCheck []resultChecker - }{ - { // left join + update both + match & unmatched + pk - []string{ - "drop table if exists a, b", - "create table a (k1 int, k2 int, v int)", - fmt.Sprintf("create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) %s)", clustered), - }, - []string{ - "insert into a values (1, 1, 1), (2, 2, 2)", // unmatched + matched - "insert into b values (2, 2, 2, 2)", - }, - "update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2", - []resultChecker{ - { - "select * from b", - []string{"2 3 4 100"}, - }, - { - "select * from a", - []string{"2 3 20", "3 4 20"}, - }, - }, - }, - { // left join + update both + match & unmatched + pk - []string{ - "drop table if exists a, b", - "create table a (k1 int, k2 int, v int)", - fmt.Sprintf("create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) %s)", clustered), - }, - []string{ - "insert into a values (1, 1, 1), (2, 2, 2)", // unmatched + matched - "insert into b values (2, 2, 2, 2)", - }, - "update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100", - []resultChecker{ - { - "select * from b", - []string{"2 3 4 100"}, - }, - { - "select * from a", - []string{"2 3 20", "3 4 20"}, - }, - }, - }, - { // left join + update both + match & unmatched + prefix pk - []string{ - "drop table if exists a, b", - "create table a (k1 varchar(100), k2 varchar(100), v varchar(100))", - fmt.Sprintf("create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) %s, key kk1(k1(1), v(1)))", clustered), - }, - []string{ - "insert into a values ('11', '11', '11'), ('22', '22', '22')", // unmatched + matched - "insert into b values ('22', '22', '22', '22')", - }, - "update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100", - []resultChecker{ - { - "select * from b", - []string{"22 23 24 100"}, - }, - { - "select * from a", - []string{"12 13 20", "23 24 20"}, - }, - }, - }, - { // right join + update both + match & unmatched + prefix pk - []string{ - "drop table if exists a, b", - "create table a (k1 varchar(100), k2 varchar(100), v varchar(100))", - fmt.Sprintf("create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) %s, key kk1(k1(1), v(1)))", clustered), - }, - []string{ - "insert into a values ('11', '11', '11'), ('22', '22', '22')", // unmatched + matched - "insert into b values ('22', '22', '22', '22')", - }, - "update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100", - []resultChecker{ - { - "select * from b", - []string{"22 23 24 100"}, - }, - { - "select * from a", - []string{"12 13 20", "23 24 20"}, - }, - }, - }, - { // inner join + update both + match & unmatched + prefix pk - []string{ - "drop table if exists a, b", - "create table a (k1 varchar(100), k2 varchar(100), v varchar(100))", - fmt.Sprintf("create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) %s, key kk1(k1(1), v(1)))", clustered), - }, - []string{ - "insert into a values ('11', '11', '11'), ('22', '22', '22')", // unmatched + matched - "insert into b values ('22', '22', '22', '22')", - }, - "update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100", - []resultChecker{ - { - "select * from b", - []string{"22 23 24 100"}, - }, - { - "select * from a", - []string{"11 11 11", "23 24 20"}, - }, - }, - }, - { - []string{ - "drop table if exists a, b", - "create table a (k1 varchar(100), k2 varchar(100), v varchar(100))", - fmt.Sprintf("create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) %s, key kk1(k1(1), v(1)))", clustered), - }, - []string{ - "insert into a values ('11', '11', '11'), ('22', '22', '22')", // unmatched + matched - "insert into b values ('22', '22', '22', '22')", - }, - "update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2)", - []resultChecker{ - { - "select * from b", - []string{"22 22 22 22"}, - }, - { - "select * from a", - []string{"11 11 11", "23 24 20"}, - }, - }, - }, - } - - for _, test := range tests { - for _, s := range test.initSchema { - tk.MustExec(s) - } - for _, s := range test.initData { - tk.MustExec(s) - } - tk.MustExec(test.dml) - for _, checker := range test.resultCheck { - tk.MustQuery(checker.check).Check(testkit.Rows(checker.assert...)) - } - tk.MustExec("admin check table a") - tk.MustExec("admin check table b") - } - } -} - -func TestClusterIndexOuterJoinElimination(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - tk.MustExec("create table t (a int, b int, c int, primary key(a,b))") - rows := tk.MustQuery(`explain format = 'brief' select t1.a from t t1 left join t t2 on t1.a = t2.a and t1.b = t2.b`).Rows() - rowStrs := testdata.ConvertRowsToStrings(rows) - for _, row := range rowStrs { - // outer join has been eliminated. - require.NotContains(t, row, "Join") - } -} - func TestPlanReplayerDumpSingle(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -840,69 +292,6 @@ func TestNotFillCacheFlag(t *testing.T) { require.Equal(t, len(tests), count) // Make sure the hook function is called. } -func TestExecutorBit(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (c1 bit(2))") - tk.MustExec("insert into t values (0), (1), (2), (3)") - err := tk.ExecToErr("insert into t values (4)") - require.Error(t, err) - err = tk.ExecToErr("insert into t values ('a')") - require.Error(t, err) - r, err := tk.Exec("select * from t where c1 = 2") - require.NoError(t, err) - req := r.NewChunk(nil) - err = r.Next(context.Background(), req) - require.NoError(t, err) - require.Equal(t, types.NewBinaryLiteralFromUint(2, -1), types.BinaryLiteral(req.GetRow(0).GetBytes(0))) - require.NoError(t, r.Close()) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c1 bit(31))") - tk.MustExec("insert into t values (0x7fffffff)") - err = tk.ExecToErr("insert into t values (0x80000000)") - require.Error(t, err) - err = tk.ExecToErr("insert into t values (0xffffffff)") - require.Error(t, err) - tk.MustExec("insert into t values ('123')") - tk.MustExec("insert into t values ('1234')") - err = tk.ExecToErr("insert into t values ('12345)") - require.Error(t, err) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c1 bit(62))") - tk.MustExec("insert into t values ('12345678')") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c1 bit(61))") - err = tk.ExecToErr("insert into t values ('12345678')") - require.Error(t, err) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c1 bit(32))") - tk.MustExec("insert into t values (0x7fffffff)") - tk.MustExec("insert into t values (0xffffffff)") - err = tk.ExecToErr("insert into t values (0x1ffffffff)") - require.Error(t, err) - tk.MustExec("insert into t values ('1234')") - err = tk.ExecToErr("insert into t values ('12345')") - require.Error(t, err) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c1 bit(64))") - tk.MustExec("insert into t values (0xffffffffffffffff)") - tk.MustExec("insert into t values ('12345678')") - err = tk.ExecToErr("insert into t values ('123456789')") - require.Error(t, err) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c1 bit(64))") - tk.MustExec("insert into t values (0xffffffffffffffff)") - tk.MustExec("insert into t values ('12345678')") - tk.MustQuery("select * from t where c1").Check(testkit.Rows("\xff\xff\xff\xff\xff\xff\xff\xff", "12345678")) -} - func TestCheckIndex(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) @@ -1021,66 +410,6 @@ func setColValue(t *testing.T, txn kv.Transaction, key kv.Key, v types.Datum) { require.NoError(t, err) } -func TestTimestampTimeZone(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (ts timestamp)") - tk.MustExec("set time_zone = '+00:00'") - tk.MustExec("insert into t values ('2017-04-27 22:40:42')") - // The timestamp will get different value if time_zone session variable changes. - tests := []struct { - timezone string - expect string - }{ - {"+10:00", "2017-04-28 08:40:42"}, - {"-6:00", "2017-04-27 16:40:42"}, - } - for _, tt := range tests { - tk.MustExec(fmt.Sprintf("set time_zone = '%s'", tt.timezone)) - tk.MustQuery("select * from t").Check(testkit.Rows(tt.expect)) - } - - // For issue https://github.com/pingcap/tidb/issues/3467 - tk.MustExec("drop table if exists t1") - tk.MustExec(`CREATE TABLE t1 ( - id bigint(20) NOT NULL AUTO_INCREMENT, - uid int(11) DEFAULT NULL, - datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - ip varchar(128) DEFAULT NULL, - PRIMARY KEY (id), - KEY i_datetime (datetime), - KEY i_userid (uid) - );`) - tk.MustExec(`INSERT INTO t1 VALUES (123381351,1734,"2014-03-31 08:57:10","127.0.0.1");`) - r := tk.MustQuery("select datetime from t1;") // Cover TableReaderExec - r.Check(testkit.Rows("2014-03-31 08:57:10")) - r = tk.MustQuery("select datetime from t1 where datetime='2014-03-31 08:57:10';") - r.Check(testkit.Rows("2014-03-31 08:57:10")) // Cover IndexReaderExec - r = tk.MustQuery("select * from t1 where datetime='2014-03-31 08:57:10';") - r.Check(testkit.Rows("123381351 1734 2014-03-31 08:57:10 127.0.0.1")) // Cover IndexLookupExec - - // For issue https://github.com/pingcap/tidb/issues/3485 - tk.MustExec("set time_zone = 'Asia/Shanghai'") - tk.MustExec("drop table if exists t1") - tk.MustExec(`CREATE TABLE t1 ( - id bigint(20) NOT NULL AUTO_INCREMENT, - datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (id) - );`) - tk.MustExec(`INSERT INTO t1 VALUES (123381351,"2014-03-31 08:57:10");`) - r = tk.MustQuery(`select * from t1 where datetime="2014-03-31 08:57:10";`) - r.Check(testkit.Rows("123381351 2014-03-31 08:57:10")) - tk.MustExec(`alter table t1 add key i_datetime (datetime);`) - r = tk.MustQuery(`select * from t1 where datetime="2014-03-31 08:57:10";`) - r.Check(testkit.Rows("123381351 2014-03-31 08:57:10")) - r = tk.MustQuery(`select * from t1;`) - r.Check(testkit.Rows("123381351 2014-03-31 08:57:10")) - r = tk.MustQuery("select datetime from t1 where datetime='2014-03-31 08:57:10';") - r.Check(testkit.Rows("2014-03-31 08:57:10")) -} - func TestTimestampDefaultValueTimeZone(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1450,59 +779,6 @@ func TestPartitionHashCode(t *testing.T) { wg.Wait() } -// this is from jira issue #5856 -func TestInsertValuesWithSubQuery(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t2") - tk.MustExec("create table t2(a int, b int, c int)") - defer tk.MustExec("drop table if exists t2") - - // should not reference upper scope - require.Error(t, tk.ExecToErr("insert into t2 values (11, 8, (select not b))")) - require.Error(t, tk.ExecToErr("insert into t2 set a = 11, b = 8, c = (select b))")) - - // subquery reference target table is allowed - tk.MustExec("insert into t2 values(1, 1, (select b from t2))") - tk.MustQuery("select * from t2").Check(testkit.Rows("1 1 ")) - tk.MustExec("insert into t2 set a = 1, b = 1, c = (select b+1 from t2)") - tk.MustQuery("select * from t2").Check(testkit.Rows("1 1 ", "1 1 2")) - - // insert using column should work normally - tk.MustExec("delete from t2") - tk.MustExec("insert into t2 values(2, 4, a)") - tk.MustQuery("select * from t2").Check(testkit.Rows("2 4 2")) - tk.MustExec("insert into t2 set a = 3, b = 5, c = b") - tk.MustQuery("select * from t2").Check(testkit.Rows("2 4 2", "3 5 5")) - - // issue #30626 - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b int)") - // TODO: should insert success and get (81,1) from the table - tk.MustGetErrMsg( - "insert into t values ( 81, ( select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ) );", - "Insert's SET operation or VALUES_LIST doesn't support complex subqueries now") - tk.MustGetErrMsg( - "insert into t set a = 81, b = (select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` );", - "Insert's SET operation or VALUES_LIST doesn't support complex subqueries now") -} - -// fix issue https://github.com/pingcap/tidb/issues/32871 -func TestBitColumnIn(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (id bit(16), key id(id))") - tk.MustExec("insert into t values (65)") - tk.MustQuery("select * from t where id not in (-1,2)").Check(testkit.Rows("\x00A")) - tk.MustGetErrMsg( - "select * from t where id in (-1, -2)", - "[expression:1582]Incorrect parameter count in the call to native function 'in'") -} - func TestIndexLookupRuntimeStats(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1632,106 +908,6 @@ func TestTrackAggMemoryUsage(t *testing.T) { require.NotEqual(t, "N/A", rows[0][7]) } -func TestProjectionBitType(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) clustered);") - tk.MustExec("create table t1(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) nonclustered);") - tk.MustExec("insert into t(k1) select 1;") - tk.MustExec("insert into t1(k1) select 1;") - - tk.MustExec("set @@tidb_enable_vectorized_expression = 0;") - // following SQL should returns same result - tk.MustQuery("(select * from t where false) union(select * from t for update);").Check(testkit.Rows("1 \x01\xd5\xe4\xcf\u007f")) - tk.MustQuery("(select * from t1 where false) union(select * from t1 for update);").Check(testkit.Rows("1 \x01\xd5\xe4\xcf\u007f")) - - tk.MustExec("set @@tidb_enable_vectorized_expression = 1;") - tk.MustQuery("(select * from t where false) union(select * from t for update);").Check(testkit.Rows("1 \x01\xd5\xe4\xcf\u007f")) - tk.MustQuery("(select * from t1 where false) union(select * from t1 for update);").Check(testkit.Rows("1 \x01\xd5\xe4\xcf\u007f")) -} - -func TestExprBlackListForEnum(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a enum('a','b','c'), b enum('a','b','c'), c int, index idx(b,a));") - tk.MustExec("insert into t values(1,1,1),(2,2,2),(3,3,3);") - - checkFuncPushDown := func(rows [][]interface{}, keyWord string) bool { - for _, line := range rows { - // Agg/Expr push down - if line[2].(string) == "cop[tikv]" && strings.Contains(line[4].(string), keyWord) { - return true - } - // access index - if line[2].(string) == "cop[tikv]" && strings.Contains(line[3].(string), keyWord) { - return true - } - } - return false - } - - // Test agg(enum) push down - tk.MustExec("insert into mysql.expr_pushdown_blacklist(name) values('enum');") - tk.MustExec("admin reload expr_pushdown_blacklist;") - rows := tk.MustQuery("desc format='brief' select /*+ HASH_AGG() */ max(a) from t;").Rows() - require.False(t, checkFuncPushDown(rows, "max")) - rows = tk.MustQuery("desc format='brief' select /*+ STREAM_AGG() */ max(a) from t;").Rows() - require.False(t, checkFuncPushDown(rows, "max")) - - tk.MustExec("delete from mysql.expr_pushdown_blacklist;") - tk.MustExec("admin reload expr_pushdown_blacklist;") - rows = tk.MustQuery("desc format='brief' select /*+ HASH_AGG() */ max(a) from t;").Rows() - require.True(t, checkFuncPushDown(rows, "max")) - rows = tk.MustQuery("desc format='brief' select /*+ STREAM_AGG() */ max(a) from t;").Rows() - require.True(t, checkFuncPushDown(rows, "max")) - - // Test expr(enum) push down - tk.MustExec("insert into mysql.expr_pushdown_blacklist(name) values('enum');") - tk.MustExec("admin reload expr_pushdown_blacklist;") - rows = tk.MustQuery("desc format='brief' select * from t where a + b;").Rows() - require.False(t, checkFuncPushDown(rows, "plus")) - rows = tk.MustQuery("desc format='brief' select * from t where a + b;").Rows() - require.False(t, checkFuncPushDown(rows, "plus")) - - tk.MustExec("delete from mysql.expr_pushdown_blacklist;") - tk.MustExec("admin reload expr_pushdown_blacklist;") - rows = tk.MustQuery("desc format='brief' select * from t where a + b;").Rows() - require.True(t, checkFuncPushDown(rows, "plus")) - rows = tk.MustQuery("desc format='brief' select * from t where a + b;").Rows() - require.True(t, checkFuncPushDown(rows, "plus")) - - // Test enum index - tk.MustExec("insert into mysql.expr_pushdown_blacklist(name) values('enum');") - tk.MustExec("admin reload expr_pushdown_blacklist;") - rows = tk.MustQuery("desc format='brief' select * from t where b = 1;").Rows() - require.False(t, checkFuncPushDown(rows, "index:idx(b)")) - rows = tk.MustQuery("desc format='brief' select * from t where b = 'a';").Rows() - require.False(t, checkFuncPushDown(rows, "index:idx(b)")) - rows = tk.MustQuery("desc format='brief' select * from t where b > 1;").Rows() - require.False(t, checkFuncPushDown(rows, "index:idx(b)")) - rows = tk.MustQuery("desc format='brief' select * from t where b > 'a';").Rows() - require.False(t, checkFuncPushDown(rows, "index:idx(b)")) - - tk.MustExec("delete from mysql.expr_pushdown_blacklist;") - tk.MustExec("admin reload expr_pushdown_blacklist;") - rows = tk.MustQuery("desc format='brief' select * from t where b = 1 and a = 1;").Rows() - require.True(t, checkFuncPushDown(rows, "index:idx(b, a)")) - rows = tk.MustQuery("desc format='brief' select * from t where b = 'a' and a = 'a';").Rows() - require.True(t, checkFuncPushDown(rows, "index:idx(b, a)")) - rows = tk.MustQuery("desc format='brief' select * from t where b = 1 and a > 1;").Rows() - require.True(t, checkFuncPushDown(rows, "index:idx(b, a)")) - rows = tk.MustQuery("desc format='brief' select * from t where b = 1 and a > 'a'").Rows() - require.True(t, checkFuncPushDown(rows, "index:idx(b, a)")) -} - // Test invoke Close without invoking Open before for each operators. func TestUnreasonablyClose(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2451,82 +1627,6 @@ func TestCollectDMLRuntimeStats(t *testing.T) { tk.MustExec("rollback") } -func TestIssue24933(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("drop view if exists v;") - tk.MustExec("create table t(a int);") - tk.MustExec("insert into t values(1), (2), (3);") - - tk.MustExec("create definer='root'@'localhost' view v as select count(*) as c1 from t;") - tk.MustQuery("select * from v;").Check(testkit.Rows("3")) - - // Test subquery and outer field is wildcard. - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select count(*) from t) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("3")) - - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select avg(a) from t group by a) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("1.0000", "2.0000", "3.0000")) - - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select sum(a) from t group by a) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("1", "2", "3")) - - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select group_concat(a) from t group by a) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("1", "2", "3")) - - // Test alias names. - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select count(0) as c1 from t) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("3")) - - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select count(*) as c1 from t) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("3")) - - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select group_concat(a) as `concat(a)` from t group by a) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("1", "2", "3")) - - // Test firstrow. - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select a from t group by a) s;") - tk.MustQuery("select * from v order by 1;").Check(testkit.Rows("1", "2", "3")) - - // Test direct select. - tk.MustGetErrMsg("SELECT `s`.`count(a)` FROM (SELECT COUNT(`a`) FROM `test`.`t`) AS `s`", "[planner:1054]Unknown column 's.count(a)' in 'field list'") - - tk.MustExec("drop view v;") - tk.MustExec("create definer='root'@'localhost' view v as select * from (select count(a) from t) s;") - tk.MustQuery("select * from v").Check(testkit.Rows("3")) - - // Test window function. - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(c1 int);") - tk.MustExec("insert into t values(111), (222), (333);") - tk.MustExec("drop view if exists v;") - tk.MustExec("create definer='root'@'localhost' view v as (select * from (select row_number() over (order by c1) from t) s);") - tk.MustQuery("select * from v;").Check(testkit.Rows("1", "2", "3")) - tk.MustExec("drop view if exists v;") - tk.MustExec("create definer='root'@'localhost' view v as (select * from (select c1, row_number() over (order by c1) from t) s);") - tk.MustQuery("select * from v;").Check(testkit.Rows("111 1", "222 2", "333 3")) - - // Test simple expr. - tk.MustExec("drop view if exists v;") - tk.MustExec("create definer='root'@'localhost' view v as (select * from (select c1 or 0 from t) s)") - tk.MustQuery("select * from v;").Check(testkit.Rows("1", "1", "1")) - tk.MustQuery("select `c1 or 0` from v;").Check(testkit.Rows("1", "1", "1")) - - tk.MustExec("drop view v;") -} - func TestTableSampleTemporaryTable(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2580,20 +1680,6 @@ func TestTableSampleTemporaryTable(t *testing.T) { tk.MustGetErrMsg("select * from tmp2 tablesample regions()", "TABLESAMPLE clause can not be applied to local temporary tables") } -func TestCTEWithIndexLookupJoinDeadLock(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (a int(11) default null,b int(11) default null,key b (b),key ba (b))") - tk.MustExec("create table t1 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b))") - tk.MustExec("create table t2 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b))") - // It's easy to reproduce this problem in 30 times execution of IndexLookUpJoin. - for i := 0; i < 30; i++ { - tk.MustExec("with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a;") - } -} - func TestGetResultRowsCount(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2764,18 +1850,6 @@ func TestAdminShowDDLJobsInfo(t *testing.T) { require.Equal(t, "alter table nocache", tk.MustQuery("admin show ddl jobs 1").Rows()[0][3]) } -func TestAdminChecksumOfPartitionedTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("DROP TABLE IF EXISTS admin_checksum_partition_test;") - tk.MustExec("CREATE TABLE admin_checksum_partition_test (a INT) PARTITION BY HASH(a) PARTITIONS 4;") - tk.MustExec("INSERT INTO admin_checksum_partition_test VALUES (1), (2);") - - r := tk.MustQuery("ADMIN CHECKSUM TABLE admin_checksum_partition_test;") - r.Check(testkit.Rows("test admin_checksum_partition_test 1 5 5")) -} - func TestUnion2(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3066,70 +2140,6 @@ func TestStaleReadAtFutureTime(t *testing.T) { require.Zero(t, tk.Session().GetSessionVars().TxnReadTS.PeakTxnReadTS()) } -func TestSQLMode(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a tinyint not null)") - tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") - tk.ExecToErr("insert t values ()") - tk.ExecToErr("insert t values ('1000')") - - tk.MustExec("create table if not exists tdouble (a double(3,2))") - tk.ExecToErr("insert tdouble values (10.23)") - - tk.MustExec("set sql_mode = ''") - tk.MustExec("insert t values ()") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1364 Field 'a' doesn't have a default value")) - tk.MustExec("insert t values (null)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1048 Column 'a' cannot be null")) - tk.MustExec("insert ignore t values (null)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1048 Column 'a' cannot be null")) - tk.MustExec("insert t select null") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1048 Column 'a' cannot be null")) - tk.MustExec("insert t values (1000)") - tk.MustQuery("select * from t order by a").Check(testkit.Rows("0", "0", "0", "0", "127")) - - tk.MustExec("insert tdouble values (10.23)") - tk.MustQuery("select * from tdouble").Check(testkit.Rows("9.99")) - - tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") - tk.MustExec("set @@global.sql_mode = ''") - - tk2 := testkit.NewTestKit(t, store) - tk2.MustExec("use test") - tk2.MustExec("drop table if exists t2") - tk2.MustExec("create table t2 (a varchar(3))") - tk2.MustExec("insert t2 values ('abcd')") - tk2.MustQuery("select * from t2").Check(testkit.Rows("abc")) - - // session1 is still in strict mode. - tk.ExecToErr("insert t2 values ('abcd')") - // Restore original global strict mode. - tk.MustExec("set @@global.sql_mode = 'STRICT_TRANS_TABLES'") -} - -func TestTableScan(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use information_schema") - result := tk.MustQuery("select * from schemata") - // There must be these tables: information_schema, mysql, performance_schema and test. - require.GreaterOrEqual(t, len(result.Rows()), 4) - tk.MustExec("use test") - tk.MustExec("create database mytest") - rowStr1 := fmt.Sprintf("%s %s %s %s %v %v", "def", "mysql", "utf8mb4", "utf8mb4_bin", nil, nil) - rowStr2 := fmt.Sprintf("%s %s %s %s %v %v", "def", "mytest", "utf8mb4", "utf8mb4_bin", nil, nil) - tk.MustExec("use information_schema") - result = tk.MustQuery("select * from schemata where schema_name = 'mysql'") - result.Check(testkit.Rows(rowStr1)) - result = tk.MustQuery("select * from schemata where schema_name like 'my%'") - result.Check(testkit.Rows(rowStr1, rowStr2)) - result = tk.MustQuery("select 1 from tables limit 1") - result.Check(testkit.Rows("1")) -} - func TestAdapterStatement(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3543,34 +2553,6 @@ func TestCurrentTimestampValueSelection(t *testing.T) { require.Equal(t, 3, len(strings.Split(d, ".")[1])) } -func TestAddDateBuiltinWithWarnings(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@sql_mode='NO_ZERO_DATE'") - result := tk.MustQuery(`select date_add('2001-01-00', interval -2 hour);`) - result.Check(testkit.Rows("")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '2001-01-00'")) -} - -func TestStrToDateBuiltinWithWarnings(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@sql_mode='NO_ZERO_DATE'") - tk.MustExec("use test") - tk.MustQuery(`SELECT STR_TO_DATE('0000-1-01', '%Y-%m-%d');`).Check(testkit.Rows("")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1411 Incorrect datetime value: '0000-1-01' for function str_to_date")) - tk.MustQuery("SELECT CAST('4#,8?Q' AS DATE);").Check(testkit.Rows("")) - tk.MustQuery(`show warnings;`).Check(testkit.Rows( - `Warning 8034 Incorrect datetime value: '4#,8?Q'`, - )) - tk.MustExec("CREATE TABLE t1 (c1 INT, c2 TEXT);") - tk.MustExec("INSERT INTO t1 VALUES (1833458842, '0.3503490908550797');") - tk.MustQuery(`SELECT CAST(t1.c2 AS DATE) FROM t1`).Check(testkit.Rows("")) - tk.MustQuery(`show warnings;`).Check(testkit.Rows( - `Warning 1292 Incorrect datetime value: '0.3503490908550797'`, - )) -} - func TestAdmin(t *testing.T) { var cluster testutils.Cluster store := testkit.CreateMockStore(t, mockstore.WithClusterInspector(func(c testutils.Cluster) { @@ -3859,51 +2841,6 @@ func TestForSelectScopeInUnion(t *testing.T) { require.Error(t, err) } -func TestUnsignedDecimalOverflow(t *testing.T) { - store := testkit.CreateMockStore(t) - - tests := []struct { - input interface{} - hasErr bool - err string - }{{ - -1, - true, - "Out of range value for column", - }, { - "-1.1e-1", - true, - "Out of range value for column", - }, { - -1.1, - true, - "Out of range value for column", - }, { - -0, - false, - "", - }, - } - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a decimal(10,2) unsigned)") - for _, test := range tests { - err := tk.ExecToErr("insert into t values (?)", test.input) - if test.hasErr { - require.Error(t, err) - require.Contains(t, err.Error(), test.err) - } else { - require.NoError(t, err) - } - } - - tk.MustExec("set sql_mode=''") - tk.MustExec("delete from t") - tk.MustExec("insert into t values (?)", -1) - tk.MustQuery("select a from t limit 1").Check(testkit.Rows("0.00")) -} - func TestMaxOneRow(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3924,19 +2861,6 @@ func TestMaxOneRow(t *testing.T) { require.NoError(t, rs.Close()) } -func TestDoSubquery(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a int)`) - tk.MustExec(`do 1 in (select * from t)`) - tk.MustExec(`insert into t values(1)`) - r, err := tk.Exec(`do 1 in (select * from t)`) - require.NoError(t, err) - require.Nil(t, r) -} - func TestSummaryFailedUpdate(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) @@ -3995,40 +2919,6 @@ func TestIsFastPlan(t *testing.T) { } } -func TestCountDistinctJSON(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(j JSON)") - tk.MustExec("insert into t values('2010')") - tk.MustExec("insert into t values('2011')") - tk.MustExec("insert into t values('2012')") - tk.MustExec("insert into t values('2010.000')") - tk.MustExec("insert into t values(cast(? as JSON))", uint64(math.MaxUint64)) - tk.MustExec("insert into t values(cast(? as JSON))", float64(math.MaxUint64)) - - tk.MustQuery("select count(distinct j) from t").Check(testkit.Rows("5")) -} - -func TestHashJoinJSON(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(id int(11), j JSON, d DOUBLE)") - tk.MustExec("insert into t values(0, '2010', 2010)") - tk.MustExec("insert into t values(1, '2011', 2011)") - tk.MustExec("insert into t values(2, '2012', 2012)") - tk.MustExec("insert into t values(3, cast(? as JSON), ?)", uint64(math.MaxUint64), float64(math.MaxUint64)) - - tk.MustQuery("select /*+inl_hash_join(t2)*/ t1.id, t2.id from t t1 join t t2 on t1.j = t2.d;").Check(testkit.Rows("0 0", "1 1", "2 2")) -} - func TestTableLockPrivilege(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -4155,137 +3045,6 @@ func TestSessionRootTrackerDetach(t *testing.T) { require.Nil(t, tk.Session().GetSessionVars().MemTracker.GetFallbackForTest(false)) } -func TestPlanReplayerDumpTPCDS(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table catalog_sales -( - cs_sold_date_sk int , - cs_sold_time_sk int , - cs_ship_date_sk int , - cs_bill_customer_sk int , - cs_bill_cdemo_sk int , - cs_bill_hdemo_sk int , - cs_bill_addr_sk int , - cs_ship_customer_sk int , - cs_ship_cdemo_sk int , - cs_ship_hdemo_sk int , - cs_ship_addr_sk int , - cs_call_center_sk int , - cs_catalog_page_sk int , - cs_ship_mode_sk int , - cs_warehouse_sk int , - cs_item_sk int not null, - cs_promo_sk int , - cs_order_number int not null, - cs_quantity int , - cs_wholesale_cost decimal(7,2) , - cs_list_price decimal(7,2) , - cs_sales_price decimal(7,2) , - cs_ext_discount_amt decimal(7,2) , - cs_ext_sales_price decimal(7,2) , - cs_ext_wholesale_cost decimal(7,2) , - cs_ext_list_price decimal(7,2) , - cs_ext_tax decimal(7,2) , - cs_coupon_amt decimal(7,2) , - cs_ext_ship_cost decimal(7,2) , - cs_net_paid decimal(7,2) , - cs_net_paid_inc_tax decimal(7,2) , - cs_net_paid_inc_ship decimal(7,2) , - cs_net_paid_inc_ship_tax decimal(7,2) , - cs_net_profit decimal(7,2) , - primary key (cs_item_sk, cs_order_number) -);`) - tk.MustExec(`create table store_sales -( - ss_sold_date_sk int , - ss_sold_time_sk int , - ss_item_sk int not null, - ss_customer_sk int , - ss_cdemo_sk int , - ss_hdemo_sk int , - ss_addr_sk int , - ss_store_sk int , - ss_promo_sk int , - ss_ticket_number int not null, - ss_quantity int , - ss_wholesale_cost decimal(7,2) , - ss_list_price decimal(7,2) , - ss_sales_price decimal(7,2) , - ss_ext_discount_amt decimal(7,2) , - ss_ext_sales_price decimal(7,2) , - ss_ext_wholesale_cost decimal(7,2) , - ss_ext_list_price decimal(7,2) , - ss_ext_tax decimal(7,2) , - ss_coupon_amt decimal(7,2) , - ss_net_paid decimal(7,2) , - ss_net_paid_inc_tax decimal(7,2) , - ss_net_profit decimal(7,2) , - primary key (ss_item_sk, ss_ticket_number) -);`) - tk.MustExec(`create table date_dim -( - d_date_sk int not null, - d_date_id char(16) not null, - d_date date , - d_month_seq int , - d_week_seq int , - d_quarter_seq int , - d_year int , - d_dow int , - d_moy int , - d_dom int , - d_qoy int , - d_fy_year int , - d_fy_quarter_seq int , - d_fy_week_seq int , - d_day_name char(9) , - d_quarter_name char(6) , - d_holiday char(1) , - d_weekend char(1) , - d_following_holiday char(1) , - d_first_dom int , - d_last_dom int , - d_same_day_ly int , - d_same_day_lq int , - d_current_day char(1) , - d_current_week char(1) , - d_current_month char(1) , - d_current_quarter char(1) , - d_current_year char(1) , - primary key (d_date_sk) -);`) - tk.MustQuery(`plan replayer dump explain with ssci as ( -select ss_customer_sk customer_sk - ,ss_item_sk item_sk -from store_sales,date_dim -where ss_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by ss_customer_sk - ,ss_item_sk), -csci as( - select cs_bill_customer_sk customer_sk - ,cs_item_sk item_sk -from catalog_sales,date_dim -where cs_sold_date_sk = d_date_sk - and d_month_seq between 1212 and 1212 + 11 -group by cs_bill_customer_sk - ,cs_item_sk) - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci left join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -UNION - select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only - ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only - ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog -from ssci right join csci on (ssci.customer_sk=csci.customer_sk - and ssci.item_sk = csci.item_sk) -limit 100;`) -} - func TestProcessInfoOfSubQuery(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/pkg/executor/test/indexmergereadtest/BUILD.bazel b/pkg/executor/test/indexmergereadtest/BUILD.bazel index ce626d630163f..23b3cd48b5523 100644 --- a/pkg/executor/test/indexmergereadtest/BUILD.bazel +++ b/pkg/executor/test/indexmergereadtest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 37, + shard_count = 20, deps = [ "//pkg/config", "//pkg/executor", diff --git a/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go b/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go index 6049727b18ed6..8a5abd0ea208d 100644 --- a/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go +++ b/pkg/executor/test/indexmergereadtest/index_merge_reader_test.go @@ -37,27 +37,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestSingleTableRead(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(id int primary key, a int, b int, c int, d int)") - tk.MustExec("create index t1a on t1(a)") - tk.MustExec("create index t1b on t1(b)") - tk.MustExec("insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5)") - tk.MustQuery("select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by id").Check(testkit.Rows("1 1 1 1 1", - "5 5 5 5 5")) - tk.MustQuery("select /*+ use_index_merge(t1, primary, t1a) */ a from t1 where id < 2 or a > 4 order by a").Check(testkit.Rows("1", - "5")) - tk.MustQuery("select /*+ use_index_merge(t1, primary, t1a) */ sum(a) from t1 where id < 2 or a > 4").Check(testkit.Rows("6")) - tk.MustQuery("select /*+ use_index_merge(t1, t1a, t1b) */ * from t1 where a < 2 or b > 4 order by a").Check(testkit.Rows("1 1 1 1 1", - "5 5 5 5 5")) - tk.MustQuery("select /*+ use_index_merge(t1, t1a, t1b) */ a from t1 where a < 2 or b > 4 order by a").Check(testkit.Rows("1", - "5")) - tk.MustQuery("select /*+ use_index_merge(t1, t1a, t1b) */ sum(a) from t1 where a < 2 or b > 4").Check(testkit.Rows("6")) -} - func TestIndexMergePickAndExecTaskPanic(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -77,79 +56,6 @@ func TestIndexMergePickAndExecTaskPanic(t *testing.T) { require.Contains(t, err.Error(), "pickAndExecTaskPanic") } -func TestJoin(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(id int primary key, a int, b int, c int, d int)") - tk.MustExec("create index t1a on t1(a)") - tk.MustExec("create index t1b on t1(b)") - tk.MustExec("create table t2(id int primary key, a int)") - tk.MustExec("create index t2a on t2(a)") - tk.MustExec("insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5)") - tk.MustExec("insert into t2 values(1,1),(5,5)") - tk.MustQuery("select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 4").Check(testkit.Rows("6")) - tk.MustQuery("select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 5").Check(testkit.Rows("1")) -} - -func TestIndexMergeReaderAndGeneratedColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0") - tk.MustExec("CREATE TABLE t0(c0 INT AS (1), c1 INT PRIMARY KEY)") - tk.MustExec("INSERT INTO t0(c1) VALUES (0)") - tk.MustExec("CREATE INDEX i0 ON t0(c0)") - tk.MustQuery("SELECT /*+ USE_INDEX_MERGE(t0, i0, PRIMARY)*/ t0.c0 FROM t0 WHERE t0.c1 OR t0.c0").Check(testkit.Rows("1")) - tk.MustQuery("SELECT t0.c0 FROM t0 WHERE t0.c1 OR t0.c0").Check(testkit.Rows("1")) -} - -// issue 25045 -func TestIndexMergeReaderIssue25045(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(a int primary key, b int, c int, key(b), key(c));") - tk.MustExec("INSERT INTO t1 VALUES (10, 10, 10), (11, 11, 11)") - tk.MustQuery("explain format='brief' select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10);").Check(testkit.Rows( - "IndexMerge 0.01 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c(c) range:[10,10], keep order:false, stats:pseudo", - "├─TableRangeScan(Build) 1.00 cop[tikv] table:t1 range:[10,10], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.01 cop[tikv] or(eq(test.t1.c, 10), and(eq(test.t1.b, 10), eq(test.t1.a, 10)))", - " └─TableRowIDScan 11.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10);").Check(testkit.Rows("10 10 10")) -} - -func TestIssue16910(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1, t2, t3;") - tk.MustExec("create table t1 (a int not null, b tinyint not null, index (a), index (b)) partition by range (a) (" + - "partition p0 values less than (10)," + - "partition p1 values less than (20)," + - "partition p2 values less than (30)," + - "partition p3 values less than (40)," + - "partition p4 values less than MAXVALUE);") - tk.MustExec("insert into t1 values(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (20, 20), (21, 21), " + - "(22, 22), (23, 23), (24, 24), (25, 25), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (40, 40), (50, 50), (80, 80), (90, 90), (100, 100);") - tk.MustExec("create table t2 (a int not null, b bigint not null, index (a), index (b)) partition by hash(a) partitions 10;") - tk.MustExec("insert into t2 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23);") - tk.MustQuery("select /*+ USE_INDEX_MERGE(t1, a, b) */ * from t1 partition (p0) join t2 partition (p1) on t1.a = t2.a where t1.a < 40 or t1.b < 30;").Check(testkit.Rows("1 1 1 1")) -} - -func TestIndexMergeCausePanic(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@tidb_enable_index_merge = 1;") - tk.MustExec("create table t (a int, b int, c int, primary key(a), key(b))") - tk.MustQuery("explain select /*+ inl_join(t2) */ * from t t1 join t t2 on t1.a = t2.a and t1.c = t2.c where t2.a = 1 or t2.b = 1") -} - func TestPartitionTableRandomIndexMerge(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -259,244 +165,6 @@ func TestIndexMergeWithPreparedStmt(t *testing.T) { require.True(t, re.MatchString(indexMergeLine)) } -func TestIndexMergeInTransaction(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - for i := 0; i < 2; i++ { - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk));") - if i == 1 { - tk.MustExec("set tx_isolation = 'READ-COMMITTED';") - } - tk.MustExec("begin;") - // Expect two IndexScan(c1, c2). - tk.MustQuery("explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10;").Check(testkit.Rows( - "IndexMerge_9 1841.86 root type: union", - "├─IndexRangeScan_5(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo", - "├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo", - "└─Selection_8(Probe) 1841.86 cop[tikv] lt(test.t1.c3, 10)", - " └─TableRowIDScan_7 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo")) - // Expect one IndexScan(c2) and one TableScan(pk). - tk.MustQuery("explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10;").Check(testkit.Rows( - "IndexMerge_9 1106.67 root type: union", - "├─TableRangeScan_5(Build) 3333.33 cop[tikv] table:t1 range:[-inf,10), keep order:false, stats:pseudo", - "├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo", - "└─Selection_8(Probe) 1106.67 cop[tikv] lt(test.t1.c3, 10)", - " └─TableRowIDScan_7 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustQuery("explain select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where c1 < 10 and c2 < 10 and c3 < 10;").Check(testkit.Rows( - "IndexMerge_9 367.05 root type: intersection", - "├─IndexRangeScan_5(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo", - "├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo", - "├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo", - "└─TableRowIDScan_8(Probe) 367.05 cop[tikv] table:t1 keep order:false, stats:pseudo")) - - // Test with normal key. - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < -1 and c2 < 10) and c3 < 10;").Check(testkit.Rows()) - - tk.MustExec("insert into t1 values(1, 1, 1, 1);") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;").Check(testkit.Rows()) - - tk.MustExec("update t1 set c3 = 100 where c3 = 1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;").Check(testkit.Rows("1 1 100 1")) - - tk.MustExec("delete from t1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10;").Check(testkit.Rows()) - - // Test with primary key, so the partialPlan is TableScan. - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < -1 and c2 < 10) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustExec("insert into t1 values(1, 1, 1, 1);") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustExec("update t1 set c3 = 100 where c3 = 1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10;").Check(testkit.Rows("1 1 100 1")) - tk.MustExec("delete from t1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10;").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10;").Check(testkit.Rows()) - - tk.MustExec("commit;") - if i == 1 { - tk.MustExec("set tx_isolation = 'REPEATABLE-READ';") - } - } - - // Same with above, but select ... for update. - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk));") - tk.MustExec("begin;") - tk.MustQuery("explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows( - "SelectLock_6 1841.86 root for update 0", - "└─IndexMerge_11 1841.86 root type: union", - " ├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo", - " ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo", - " └─Selection_10(Probe) 1841.86 cop[tikv] lt(test.t1.c3, 10)", - " └─TableRowIDScan_9 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustQuery("explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows( - "SelectLock_6 1106.67 root for update 0", - "└─IndexMerge_11 1106.67 root type: union", - " ├─TableRangeScan_7(Build) 3333.33 cop[tikv] table:t1 range:[-inf,10), keep order:false, stats:pseudo", - " ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo", - " └─Selection_10(Probe) 1106.67 cop[tikv] lt(test.t1.c3, 10)", - " └─TableRowIDScan_9 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo")) - - // Test with normal key. - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows()) - tk.MustExec("insert into t1 values(1, 1, 1, 1);") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows("1 1 1 1")) - tk.MustExec("update t1 set c3 = 100 where c3 = 1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows()) - tk.MustExec("delete from t1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows()) - - // Test with primary key, so the partialPlan is TableScan. - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows()) - tk.MustExec("insert into t1 values(1, 1, 1, 1);") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows("1 1 1 1")) - tk.MustExec("update t1 set c3 = 100 where c3 = 1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows()) - tk.MustExec("delete from t1;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update;").Check(testkit.Rows()) - tk.MustExec("commit;") - - // Test partition table. - tk.MustExec("drop table if exists t1;") - tk.MustExec(`create table t1(c1 int, c2 int, c3 int, pk int, part int, key(c1), key(c2), key(c3), primary key(pk, part)) - partition by range(part) ( - partition p0 values less than (10), - partition p1 values less than (20), - partition p2 values less than (maxvalue))`) - tk.MustExec("begin;") - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < 20) and c3 < 20;").Check(testkit.Rows()) - - tk.MustExec("insert into t1 values(1, 1, 1, 1, 1);") - tk.MustExec("insert into t1 values(11, 11, 11, 11, 11);") - tk.MustExec("insert into t1 values(21, 21, 21, 21, 21);") - tk.MustExec("insert into t1 values(31, 31, 31, 31, 31);") - - res := tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20;").Sort() - res.Check(testkit.Rows("1 1 1 1 1", "11 11 11 11 11")) - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20;").Sort() - res.Check(testkit.Rows("1 1 1 1 1", "11 11 11 11 11")) - - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20;").Sort() - res.Check(testkit.Rows("1 1 1 1 1", "11 11 11 11 11")) - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20;").Sort() - res.Check(testkit.Rows("1 1 1 1 1", "11 11 11 11 11")) - - tk.MustExec("update t1 set c3 = 100 where c3 = 1;") - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20;") - res.Check(testkit.Rows("11 11 11 11 11")) - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20;") - res.Check(testkit.Rows("11 11 11 11 11")) - - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20;") - res.Check(testkit.Rows("11 11 11 11 11")) - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20;") - res.Check(testkit.Rows("11 11 11 11 11")) - - tk.MustExec("delete from t1;") - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20;") - res.Check(testkit.Rows()) - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20;") - res.Check(testkit.Rows()) - - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20;") - res.Check(testkit.Rows()) - res = tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20;") - res.Check(testkit.Rows()) - tk.MustExec("commit;") -} - -func TestIndexMergeReaderInTransIssue30685(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // This is a case generated by sqlgen to test if clustered index is ok. - // Detect the bugs in memIndexMergeReader.getMemRowsHandle(). - tk.MustExec("drop table if exists t1;") - tk.MustExec(`create table t1 (col_30 decimal default 0 , - col_31 char(99) collate utf8_bin default 'sVgzHblmYYtEjVg' not null , - col_37 int unsigned default 377206828 , - primary key idx_16 ( col_37 ) , key idx_19 ( col_31) ) collate utf8mb4_general_ci ;`) - tk.MustExec("begin;") - tk.MustExec("insert ignore into t1 values (388021, '', 416235653);") - tk.MustQuery("select /*+ use_index_merge( t1 ) */ 1 from t1 where ( t1.col_31 in ( 'OiOXzpCs' , 'oaVv' ) or t1.col_37 <= 4059907010 ) and t1.col_30 ;").Check(testkit.Rows("1")) - tk.MustExec("commit;") - - tk.MustExec("drop table if exists tbl_3;") - tk.MustExec(`create table tbl_3 ( col_30 decimal , col_31 char(99) , col_32 smallint , - col_33 tinyint unsigned not null , col_34 char(209) , - col_35 char(110) , col_36 int unsigned , col_37 int unsigned , - col_38 decimal(50,15) not null , col_39 char(104), - primary key ( col_37 ) , unique key ( col_33,col_30,col_36,col_39 ) , - unique key ( col_32,col_35 ) , key ( col_31,col_38 ) , - key ( col_31,col_33,col_32,col_35,col_36 ) , - unique key ( col_38,col_34,col_33,col_31,col_30,col_36,col_35,col_37,col_39 ) , - unique key ( col_39,col_32 ) , unique key ( col_30,col_35,col_31,col_38 ) , - key ( col_38,col_32,col_33 ) )`) - tk.MustExec("begin;") - tk.MustExec("insert ignore into tbl_3 values ( 71,'Fipc',-6676,30,'','FgfK',2464927398,4084082400,5602.5868,'' );") - tk.MustQuery("select /*+ use_index_merge( tbl_3 ) */ 1 from tbl_3 where ( tbl_3.col_37 not in ( 1626615245 , 2433569159 ) or tbl_3.col_38 = 0.06 ) ;").Check(testkit.Rows("1")) - tk.MustExec("commit;") - - // int + int compound type as clustered index pk. - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 int, c2 int, c3 int, c4 int, primary key(c1, c2) /*T![clustered_index] CLUSTERED */, key(c3));") - - tk.MustExec("begin;") - tk.MustExec("insert into t1 values(1, 1, 1, 1);") - tk.MustQuery("explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10;").Check(testkit.Rows( - "UnionScan_6 1841.86 root lt(test.t1.c4, 10), or(lt(test.t1.c1, -1), lt(test.t1.c3, 10))", - "└─IndexMerge_11 1841.86 root type: union", - " ├─TableRangeScan_7(Build) 3323.33 cop[tikv] table:t1 range:[-inf,-1), keep order:false, stats:pseudo", - " ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo", - " └─Selection_10(Probe) 1841.86 cop[tikv] lt(test.t1.c4, 10)", - " └─TableRowIDScan_9 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo")) - - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c3 < -1) and c4 < 10;").Check(testkit.Rows("1 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < -1) and c4 < 10;").Check(testkit.Rows()) - tk.MustExec("commit;") - - // Single int type as clustered index pk. - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 varchar(100), c2 int, c3 int, c4 int, primary key(c1) /*T![clustered_index] CLUSTERED */, key(c3));") - - tk.MustExec("begin;") - tk.MustExec("insert into t1 values('b', 1, 1, 1);") - tk.MustQuery("explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10;").Check(testkit.Rows( - "UnionScan_6 1841.86 root lt(test.t1.c4, 10), or(lt(test.t1.c1, \"a\"), lt(test.t1.c3, 10))", - "└─IndexMerge_11 1841.86 root type: union", - " ├─TableRangeScan_7(Build) 3323.33 cop[tikv] table:t1 range:[-inf,\"a\"), keep order:false, stats:pseudo", - " ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo", - " └─Selection_10(Probe) 1841.86 cop[tikv] lt(test.t1.c4, 10)", - " └─TableRowIDScan_9 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo")) - - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10;").Check(testkit.Rows("b 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 <= 'b' or c3 < -1) and c4 < 10;").Check(testkit.Rows("b 1 1 1")) - tk.MustQuery("select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < -1) and c4 < 10;").Check(testkit.Rows()) - tk.MustExec("commit;") -} - func TestIndexMergeReaderMemTracker(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -531,27 +199,6 @@ func TestIndexMergeReaderMemTracker(t *testing.T) { require.Greater(t, bytes, 0.0) } -func TestIndexMergeSplitTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("DROP TABLE IF EXISTS tab2;") - tk.MustExec("CREATE TABLE tab2(pk INTEGER PRIMARY KEY, col0 INTEGER, col1 FLOAT, col2 TEXT, col3 INTEGER, col4 FLOAT, col5 TEXT);") - tk.MustExec("CREATE INDEX idx_tab2_0 ON tab2 (col0 DESC,col3 DESC);") - tk.MustExec("CREATE UNIQUE INDEX idx_tab2_3 ON tab2 (col4,col0 DESC);") - tk.MustExec("CREATE INDEX idx_tab2_4 ON tab2 (col3,col1 DESC);") - tk.MustExec("INSERT INTO tab2 VALUES(0,146,632.63,'shwwd',703,412.47,'xsppr');") - tk.MustExec("INSERT INTO tab2 VALUES(1,81,536.29,'trhdh',49,726.3,'chuxv');") - tk.MustExec("INSERT INTO tab2 VALUES(2,311,541.72,'txrvb',493,581.92,'xtrra');") - tk.MustExec("INSERT INTO tab2 VALUES(3,669,293.27,'vcyum',862,415.14,'nbutk');") - tk.MustExec("INSERT INTO tab2 VALUES(4,681,49.46,'odzhp',106,324.65,'deudp');") - tk.MustExec("INSERT INTO tab2 VALUES(5,319,769.65,'aeqln',855,197.9,'apipa');") - tk.MustExec("INSERT INTO tab2 VALUES(6,610,302.62,'bixap',184,840.31,'vggit');") - tk.MustExec("INSERT INTO tab2 VALUES(7,253,453.21,'gjccm',107,104.5,'lvunv');") - tk.MustExec("SPLIT TABLE tab2 BY (5);") - tk.MustQuery("SELECT /*+ use_index_merge(tab2) */ pk FROM tab2 WHERE (col4 > 565.89 OR col0 > 68 ) and col0 > 10 order by 1;").Check(testkit.Rows("0", "1", "2", "3", "4", "5", "6", "7")) -} - func TestPessimisticLockOnPartitionForIndexMerge(t *testing.T) { // Same purpose with TestPessimisticLockOnPartition, but test IndexMergeReader. store := testkit.CreateMockStore(t) @@ -861,20 +508,6 @@ func TestIndexMergeProcessWorkerHang(t *testing.T) { require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/executor/testIndexMergeProcessWorkerIntersectionHang")) } -func TestIndexMergePanic1(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(c1 int, c2 bigint, c3 bigint, primary key(c1), key(c2), key(c3));") - tk.MustExec("insert into t1 values(1, 1, 1), (100, 100, 100)") - - require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/executor/testIndexMergeResultChCloseEarly", "return(true)")) - tk.MustExec("select /*+ use_index_merge(t1, primary, c2, c3) */ c1 from t1 where c1 < 100 or c2 < 100") - require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/executor/testIndexMergeResultChCloseEarly")) -} - var indexMergePanicRunSQL = func(t *testing.T, tk *testkit.TestKit, fp string) { minV := 200 maxV := 1000 @@ -892,82 +525,66 @@ var indexMergePanicRunSQL = func(t *testing.T, tk *testkit.TestKit, fp string) { require.Contains(t, err.Error(), fp) } -func TestIndexMergePanicPartialIndexWorker(t *testing.T) { +func TestIndexMergePanic(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) setupPartitionTableHelper(tk) + // TestIndexMergePanicPartialIndexWorker fp := "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicPartialIndexWorker" + require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) for i := 0; i < 100; i++ { - require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) indexMergePanicRunSQL(t, tk, fp) - require.NoError(t, failpoint.Disable(fp)) } -} + require.NoError(t, failpoint.Disable(fp)) -func TestIndexMergePanicPartialTableWorker(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - setupPartitionTableHelper(tk) - - fp := "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicPartialTableWorker" + // TestIndexMergePanicPartialTableWorker + fp = "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicPartialTableWorker" + require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) for i := 0; i < 100; i++ { - require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) indexMergePanicRunSQL(t, tk, fp) - require.NoError(t, failpoint.Disable(fp)) } -} + require.NoError(t, failpoint.Disable(fp)) -func TestIndexMergePanicPartialProcessWorkerUnion(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - setupPartitionTableHelper(tk) - - fp := "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicProcessWorkerUnion" + // TestIndexMergePanicProcessWorkerUnion + fp = "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicProcessWorkerUnion" + require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) for i := 0; i < 100; i++ { - require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) indexMergePanicRunSQL(t, tk, fp) - require.NoError(t, failpoint.Disable(fp)) } -} + require.NoError(t, failpoint.Disable(fp)) -func TestIndexMergePanicPartialProcessWorkerIntersection(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - setupPartitionTableHelper(tk) - - fp := "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicProcessWorkerIntersection" + // TestIndexMergePanicProcessWorkerIntersection + fp = "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicProcessWorkerIntersection" + require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) for i := 0; i < 100; i++ { - require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) indexMergePanicRunSQL(t, tk, fp) - require.NoError(t, failpoint.Disable(fp)) } -} + require.NoError(t, failpoint.Disable(fp)) -func TestIndexMergePanicPartitionTableIntersectionWorker(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - setupPartitionTableHelper(tk) - - fp := "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicPartitionTableIntersectionWorker" + // TestIndexMergePanicPartitionTableIntersectionWorker + fp = "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicPartitionTableIntersectionWorker" + require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) for i := 0; i < 100; i++ { - require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) indexMergePanicRunSQL(t, tk, fp) - require.NoError(t, failpoint.Disable(fp)) } -} + require.NoError(t, failpoint.Disable(fp)) -func TestIndexMergePanicTableScanWorker(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - setupPartitionTableHelper(tk) - - fp := "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicTableScanWorker" + // TestIndexMergePanicTableScanWorker + fp = "github.com/pingcap/tidb/pkg/executor/testIndexMergePanicTableScanWorker" + require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) for i := 0; i < 100; i++ { - require.NoError(t, failpoint.Enable(fp, fmt.Sprintf(`panic("%s")`, fp))) indexMergePanicRunSQL(t, tk, fp) - require.NoError(t, failpoint.Disable(fp)) } + require.NoError(t, failpoint.Disable(fp)) + + tk.MustExec("drop table if exists t1") + tk.MustExec("create table t1(c1 int, c2 bigint, c3 bigint, primary key(c1), key(c2), key(c3));") + tk.MustExec("insert into t1 values(1, 1, 1), (100, 100, 100)") + + require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/executor/testIndexMergeResultChCloseEarly", "return(true)")) + tk.MustExec("select /*+ use_index_merge(t1, primary, c2, c3) */ c1 from t1 where c1 < 100 or c2 < 100") + require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/executor/testIndexMergeResultChCloseEarly")) } func TestIndexMergeError(t *testing.T) { @@ -1264,43 +881,6 @@ func TestIndexMergeLimitNotPushedOnPartialSideButKeepOrder(t *testing.T) { } } -func TestIndexMergeNoOrderLimitPushed(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int, b int, c int, index idx(a, c), index idx2(b, c))") - tk.MustExec("insert into t values(1, 1, 1), (2, 2, 2)") - sql := "select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1" - tk.MustHavePlan(sql, "IndexMerge") - tk.MustHavePlan(sql, "Limit") - // 6 means that IndexMerge(embedded limit){Limit->PartialIndexScan, Limit->PartialIndexScan, FinalTableScan} - require.Equal(t, 6, len(tk.MustQuery("explain "+sql).Rows())) - // The result is not stable. So we just check that it can run successfully. - tk.MustQuery(sql) -} - -func TestIndexMergeKeepOrderDirtyRead(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int, b int, c int, index idx1(a, c), index idx2(b, c))") - tk.MustExec("insert into t values(1, 1, 1), (1, 2, -1), (2, 1, -2)") - tk.MustExec("begin") - tk.MustExec("insert into t values(1, 1, -3)") - querySQL := "select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2" - tk.MustHavePlan(querySQL, "Limit") - tk.MustHavePlan(querySQL, "IndexMerge") - tk.MustQuery(querySQL).Check(testkit.Rows("1 1 -3", "2 1 -2")) - tk.MustExec("rollback") - tk.MustExec("begin") - tk.MustExec("insert into t values(1, 2, 4)") - querySQL = "select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2" - tk.MustHavePlan(querySQL, "Limit") - tk.MustHavePlan(querySQL, "IndexMerge") - tk.MustQuery(querySQL).Check(testkit.Rows("1 2 4", "1 1 1")) - tk.MustExec("rollback") -} - func TestIssues46005(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/pkg/executor/test/passwordtest/BUILD.bazel b/pkg/executor/test/passwordtest/BUILD.bazel index 9763605022218..2f7cfb57851ef 100644 --- a/pkg/executor/test/passwordtest/BUILD.bazel +++ b/pkg/executor/test/passwordtest/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "password_management_test.go", ], flaky = True, - shard_count = 16, + shard_count = 8, deps = [ "//pkg/domain", "//pkg/errno", diff --git a/pkg/executor/test/passwordtest/password_management_test.go b/pkg/executor/test/passwordtest/password_management_test.go index 59b6f04cb44f3..2dc435fb7ed11 100644 --- a/pkg/executor/test/passwordtest/password_management_test.go +++ b/pkg/executor/test/passwordtest/password_management_test.go @@ -127,84 +127,6 @@ func TestValidatePassword(t *testing.T) { tk.MustExec("CREATE ROLE role1") } -func expectedPasswordExpiration(t *testing.T, tk *testkit.TestKit, testuser, expired string, lifetime string) { - res := tk.MustQuery(fmt.Sprintf("SELECT password_expired, password_last_changed, password_lifetime FROM mysql.user WHERE user = '%s'", testuser)) - rows := res.Rows() - require.NotEmpty(t, rows) - row := rows[0] - require.Equal(t, 3, len(row)) - require.Equal(t, expired, row[0].(string), testuser) - require.True(t, len(row[1].(string)) > 0, testuser) - require.Equal(t, lifetime, row[2].(string), testuser) -} - -func TestPasswordExpiration(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - // CREATE USER - tk.MustExec(`CREATE USER testuser`) - expectedPasswordExpiration(t, tk, "testuser", "N", "") - tk.MustExec(`CREATE USER testuser1 PASSWORD EXPIRE`) - expectedPasswordExpiration(t, tk, "testuser1", "Y", "") - tk.MustExec(`CREATE USER testuser2 PASSWORD EXPIRE DEFAULT`) - expectedPasswordExpiration(t, tk, "testuser2", "N", "") - tk.MustExec(`CREATE USER testuser3 PASSWORD EXPIRE NEVER`) - expectedPasswordExpiration(t, tk, "testuser3", "N", "0") - tk.MustExec(`CREATE USER testuser4 PASSWORD EXPIRE INTERVAL 3 DAY`) - expectedPasswordExpiration(t, tk, "testuser4", "N", "3") - tk.MustExec(`CREATE ROLE role1`) - expectedPasswordExpiration(t, tk, "role1", "Y", "") - - // ALTER USER - testcases := []struct { - user string - expired string - }{ - {"testuser", "N"}, - {"testuser1", "Y"}, - {"testuser2", "N"}, - {"testuser3", "N"}, - {"testuser4", "N"}, - {"role1", "Y"}, - } - for _, testcase := range testcases { - tk.MustExec(fmt.Sprintf("ALTER USER %s PASSWORD EXPIRE NEVER", testcase.user)) - expectedPasswordExpiration(t, tk, testcase.user, testcase.expired, "0") - tk.MustExec(fmt.Sprintf("ALTER USER %s PASSWORD EXPIRE DEFAULT", testcase.user)) - expectedPasswordExpiration(t, tk, testcase.user, testcase.expired, "") - tk.MustExec(fmt.Sprintf("ALTER USER %s PASSWORD EXPIRE INTERVAL 3 DAY", testcase.user)) - expectedPasswordExpiration(t, tk, testcase.user, testcase.expired, "3") - tk.MustExec(fmt.Sprintf("ALTER USER %s PASSWORD EXPIRE", testcase.user)) - expectedPasswordExpiration(t, tk, testcase.user, "Y", "3") - tk.MustExec(fmt.Sprintf("ALTER USER %s IDENTIFIED BY '' PASSWORD EXPIRE", testcase.user)) - expectedPasswordExpiration(t, tk, testcase.user, "Y", "3") - tk.MustExec(fmt.Sprintf("ALTER USER %s IDENTIFIED WITH 'mysql_native_password' AS ''", testcase.user)) - expectedPasswordExpiration(t, tk, testcase.user, "N", "3") - tk.MustExec(fmt.Sprintf("ALTER USER %s IDENTIFIED BY ''", testcase.user)) - expectedPasswordExpiration(t, tk, testcase.user, "N", "3") - } - - // SET PASSWORD - tk.MustExec("ALTER USER testuser PASSWORD EXPIRE") - expectedPasswordExpiration(t, tk, "testuser", "Y", "3") - tk.MustExec("SET PASSWORD FOR testuser = '1234'") - expectedPasswordExpiration(t, tk, "testuser", "N", "3") - - tk.MustGetErrCode(`CREATE USER ''@localhost IDENTIFIED BY 'pass' PASSWORD EXPIRE`, mysql.ErrPasswordExpireAnonymousUser) - tk.MustExec(`CREATE USER ''@localhost IDENTIFIED BY 'pass'`) - tk.MustGetErrCode(`ALTER USER ''@localhost PASSWORD EXPIRE`, mysql.ErrPasswordExpireAnonymousUser) - - // different cleartext authentication plugin - for _, authplugin := range []string{mysql.AuthNativePassword, mysql.AuthCachingSha2Password, mysql.AuthTiDBSM3Password} { - tk.MustExec("DROP USER IF EXISTS 'u1'@'localhost'") - tk.MustExec(fmt.Sprintf("CREATE USER 'u1'@'localhost' IDENTIFIED WITH '%s'", authplugin)) - tk.MustExec("ALTER USER 'u1'@'localhost' IDENTIFIED BY 'pass'") - tk.MustExec("ALTER USER 'u1'@'localhost' PASSWORD EXPIRE") - tk.MustQuery("SELECT password_expired FROM mysql.user WHERE user = 'u1'").Check(testkit.Rows("Y")) - } -} - // Test cases that related to PASSWORD VALIDATION, PASSWORD EXPIRATION, PASSWORD REUSE POLICY, and PASSWORD FAILED-LOGIN TRACK. func TestPasswordManagement(t *testing.T) { store := testkit.CreateMockStore(t) @@ -414,318 +336,6 @@ func TestFailedLoginTrackingBasic(t *testing.T) { tk.MustQuery("select user_attributes from mysql.user where user = 'u4' and host = 'localhost'").Check(testkit.Rows(`{"Password_locking": {"failed_login_attempts": 0, "password_lock_time_days": 6}}`)) } -func TestUserReuseControl(t *testing.T) { - store := testkit.CreateMockStore(t) - rootTK := testkit.NewTestKit(t, store) - rootTK.MustQuery(`show variables like "password_history"`).Check(testkit.Rows("password_history 0")) - rootTK.MustQuery(`show variables like "password_reuse_interval"`).Check(testkit.Rows("password_reuse_interval 0")) - rootTK.MustExec(`set global password_history = -1`) - rootTK.MustExec(`set global password_reuse_interval = -1`) - rootTK.MustQuery(`show variables like "password_history"`).Check(testkit.Rows("password_history 0")) - rootTK.MustQuery(`show variables like "password_reuse_interval"`).Check(testkit.Rows("password_reuse_interval 0")) - rootTK.MustExec(`set global password_history = 4294967295`) - rootTK.MustExec(`set global password_reuse_interval = 4294967295`) - rootTK.MustQuery(`show variables like "password_history"`).Check(testkit.Rows("password_history 4294967295")) - rootTK.MustQuery(`show variables like "password_reuse_interval"`).Check(testkit.Rows("password_reuse_interval 4294967295")) - rootTK.MustExec(`set global password_history = 4294967296`) - rootTK.MustExec(`set global password_reuse_interval = 4294967296`) - rootTK.MustQuery(`show variables like "password_history"`).Check(testkit.Rows("password_history 4294967295")) - rootTK.MustQuery(`show variables like "password_reuse_interval"`).Check(testkit.Rows("password_reuse_interval 4294967295")) - rootTK.MustGetErrCode(`set session password_history = 42949`, 1229) - rootTK.MustGetErrCode(`set session password_reuse_interval = 42949`, 1229) -} - -func TestUserReuseInfo(t *testing.T) { - store := testkit.CreateMockStore(t) - rootTK := testkit.NewTestKit(t, store) - rootTK.MustExec(`CREATE USER testReuse`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(` `)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD HISTORY 5`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`5 `)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD HISTORY 0`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`0 `)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD HISTORY DEFAULT`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(` `)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD HISTORY 65536`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`65535 `)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD REUSE INTERVAL 5 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`65535 5`)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD REUSE INTERVAL 0 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`65535 0`)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD REUSE INTERVAL DEFAULT`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`65535 `)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD REUSE INTERVAL 65536 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`65535 65535`)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD HISTORY 6 PASSWORD REUSE INTERVAL 6 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`6 6`)) - rootTK.MustExec(`ALTER USER testReuse PASSWORD HISTORY 6 PASSWORD HISTORY 7 `) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`7 6`)) - - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD HISTORY 5`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`5 `)) - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD REUSE INTERVAL 5 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(` 5`)) - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD REUSE INTERVAL 5 DAY PASSWORD REUSE INTERVAL 6 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(` 6`)) - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 6 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`5 6`)) - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD REUSE INTERVAL 6 DAY PASSWORD HISTORY 5`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`5 6`)) - - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustGetErrCode(`CREATE USER testReuse PASSWORD HISTORY -5`, 1064) - rootTK.MustGetErrCode(`CREATE USER testReuse PASSWORD REUSE INTERVAL -6 DAY`, 1064) - rootTK.MustExec(`CREATE USER testReuse PASSWORD HISTORY 65535 PASSWORD REUSE INTERVAL 65535 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`65535 65535`)) - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD HISTORY 65536 PASSWORD REUSE INTERVAL 65536 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`65535 65535`)) - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(` `)) - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse PASSWORD HISTORY 0 PASSWORD REUSE INTERVAL 0 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows(`0 0`)) -} - -func TestUserReuseFunction(t *testing.T) { - store := testkit.CreateMockStore(t) - rootTK := testkit.NewTestKit(t, store) - rootTK.MustExec(`CREATE USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`set global password_history = 1;`) - rootTK.MustExec(`alter USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustExec(`DROP USER testReuse`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - - rootTK.MustExec(`set global password_history = 0;`) - rootTK.MustExec(`set global password_reuse_interval = 1;`) - rootTK.MustExec(`CREATE USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`2`)) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`3`)) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`4`)) - rootTK.MustExec(`update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '1 0:0:1' DAY_SECOND)`) - rootTK.MustExec(`alter USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustExec(`drop USER testReuse `) - - rootTK.MustExec(`set global password_reuse_interval = 0;`) - //password nil is not stored - rootTK.MustExec(`CREATE USER testReuse PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 6 DAY`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`drop USER testReuse `) - - rootTK.MustExec(`CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`4`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustExec(`alter USER testReuse identified by 'test4'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`5`)) - rootTK.MustExec(`alter USER testReuse identified by 'test5'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`5`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test1'`, 3638) - rootTK.MustExec(`alter USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`5`)) - rootTK.MustExec(`drop USER testReuse`) - - rootTK.MustExec(`CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustExec(`alter USER testReuse identified by 'test4'`) - rootTK.MustExec(`alter USER testReuse identified by 'test5'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`6`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustExec(`update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '3 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1`) - rootTK.MustExec(`alter USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`6`)) - rootTK.MustExec(`drop USER testReuse`) - - rootTK.MustExec(`CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustExec(`update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '3 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`4`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustExec(`ALTER USER testReuse PASSWORD HISTORY 3`) - rootTK.MustExec(`alter USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`4`)) - rootTK.MustExec(`drop USER testReuse`) - - rootTK.MustExec(`set global password_history = 1;`) - rootTK.MustExec(`set global password_reuse_interval = 1;`) - rootTK.MustExec(`CREATE USER testReuse identified by 'test' PASSWORD HISTORY 0 PASSWORD REUSE INTERVAL 0 DAY`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`alter USER testReuse identified by 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`drop USER testReuse`) - - rootTK.MustExec(`set global password_history = 0;`) - rootTK.MustExec(`set global password_reuse_interval = 360000000;`) - rootTK.MustExec(`CREATE USER testReuse identified by 'test'`) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustGetErrCode(`set PASSWORD FOR testReuse = 'test'`, 3638) - rootTK.MustExec(`alter USER testReuse identified by ''`) - rootTK.MustExec(`alter USER testReuse identified by ''`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`2`)) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustExec(`set global password_reuse_interval = 4294967295;`) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`4`)) - rootTK.MustExec(`set PASSWORD FOR testReuse = 'test4'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`5`)) - rootTK.MustExec(`drop USER testReuse`) - - rootTK.MustExec(`set global password_reuse_interval = 0;`) - rootTK.MustExec(`CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5`) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`2`)) - rootTK.MustExec(`alter USER testReuse identified by 'test1' PASSWORD HISTORY 0`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`alter USER testReuse identified by 'test1' PASSWORD HISTORY 2 PASSWORD REUSE INTERVAL 1 DAY`) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustExec(`alter USER testReuse identified by 'test1' PASSWORD HISTORY 2 PASSWORD REUSE INTERVAL 0 DAY`) - - // Support password and default value modification at the same time. - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`set global password_history = 1`) - rootTK.MustExec(`CREATE USER testReuse identified by 'test' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustGetErrCode(`ALTER USER testReuse identified by 'test' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT`, 3638) - rootTK.MustExec(`ALTER USER testReuse identified by 'test1' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) -} - -func TestUserReuseDifferentAuth(t *testing.T) { - store := testkit.CreateMockStore(t) - rootTK := testkit.NewTestKit(t, store) - // test caching_sha2_password. - rootTK.MustExec(`CREATE USER testReuse identified with 'caching_sha2_password' by 'test' PASSWORD HISTORY 1 `) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustGetErrCode(`set password for testReuse = 'test'`, 3638) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustExec(`alter USER testReuse identified with 'tidb_sm3_password'`) - // changing the auth method prunes history. - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse identified with 'tidb_sm3_password' by 'test' PASSWORD HISTORY 1 `) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustGetErrCode(`set password for testReuse = 'test'`, 3638) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustExec(`alter USER testReuse identified with 'caching_sha2_password'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustExec(`CREATE USER testReuse identified with 'caching_sha2_password' by 'test' PASSWORD REUSE INTERVAL 1 DAY`) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustGetErrCode(`set password for testReuse = 'test'`, 3638) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustExec(`update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '1 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1`) - rootTK.MustExec(`alter USER testReuse identified by 'test'`) - - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustGetErrCode(`CREATE USER testReuse identified with 'mysql_clear_password' by 'test' PASSWORD REUSE INTERVAL 1 DAY`, 1524) - rootTK.MustGetErrCode(`CREATE USER testReuse identified with 'tidb_session_token' by 'test' PASSWORD REUSE INTERVAL 1 DAY`, 1524) - // no password. - rootTK.MustExec(`CREATE USER testReuse identified with 'auth_socket' by 'test' PASSWORD REUSE INTERVAL 1 DAY`) - rootTK.MustExec(`ALTER USER testReuse identified by 'test' `) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustQuery(`SELECT authentication_string FROM mysql.user WHERE user = 'testReuse'`).Check(testkit.Rows("")) - rootTK.MustExec(`ALTER USER testReuse identified with 'caching_sha2_password' by 'test' `) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - // AuthTiDBAuthToken is the token login method on the cloud, - // and the Password Reuse Policy does not take effect. - rootTK.MustExec(`drop USER testReuse`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`CREATE USER testReuse identified with 'tidb_auth_token' by 'test' PASSWORD REUSE INTERVAL 1 DAY`) - rootTK.MustExec(`ALTER USER testReuse identified by 'test' `) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`set password for testReuse = 'test'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustExec(`ALTER USER testReuse identified with 'caching_sha2_password' by 'test' `) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustGetErrCode(`alter USER testReuse identified by 'test'`, 3638) - rootTK.MustGetErrCode(`set password for testReuse = 'test'`, 3638) - rootTK.MustExec(`drop USER testReuse`) -} - -func TestUserReuseMultiuser(t *testing.T) { - store := testkit.CreateMockStore(t) - rootTK := testkit.NewTestKit(t, store) - //alter multi user success - rootTK.MustExec(`CREATE USER testReuse identified by 'test', testReuse1 identified by 'test', testReuse2 identified by 'test' PASSWORD HISTORY 65535 PASSWORD REUSE INTERVAL 65535 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'`).Check(testkit.Rows(`65535 65535`, `65535 65535`, `65535 65535`)) - rootTK.MustExec(`ALTER USER testReuse identified by 'test1', testReuse1 identified by 'test1', testReuse2 identified by 'test1' PASSWORD HISTORY 3 PASSWORD REUSE INTERVAL 3 DAY`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'`).Check(testkit.Rows(`3 3`, `3 3`, `3 3`)) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' group by user`).Check(testkit.Rows(`2`, `2`, `2`)) - //alter multi user fail - rootTK.MustExec(`CREATE USER testReuse3 identified by 'test'`) - rootTK.MustQuery(`SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'`).Check(testkit.Rows(`3 3`, `3 3`, `3 3`, ` `)) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' group by user`).Check(testkit.Rows(`2`, `2`, `2`)) - rootTK.MustGetErrCode(`ALTER USER testReuse identified by 'test1', testReuse3 identified by 'test1'`, 3638) - //drop user - rootTK.MustExec(`drop User testReuse, testReuse1, testReuse2, testReuse3`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' `).Check(testkit.Rows(`0`)) -} - -func TestUserReuseRename(t *testing.T) { - store := testkit.CreateMockStore(t) - rootTK := testkit.NewTestKit(t, store) - rootTK.MustExec(`CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`1`)) - rootTK.MustExec(`alter USER testReuse identified by 'test1'`) - rootTK.MustExec(`alter USER testReuse identified by 'test2'`) - rootTK.MustExec(`alter USER testReuse identified by 'test3'`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`4`)) - rootTK.MustExec(`rename USER testReuse to testReuse1`) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'`).Check(testkit.Rows(`0`)) - rootTK.MustQuery(`SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse1'`).Check(testkit.Rows(`4`)) -} - -func TestUserAlterUser(t *testing.T) { - store := testkit.CreateMockStore(t) - rootTK := testkit.NewTestKit(t, store) - rootTK.MustExec(`CREATE USER test1 IDENTIFIED WITH 'mysql_native_password' BY '1234'`) - alterUserSQL := `ALTER USER 'test1' IDENTIFIED BY '222', 'test_not_exist'@'localhost' IDENTIFIED BY '111';` - rootTK.MustGetErrCode(alterUserSQL, mysql.ErrCannotUser) - result := rootTK.MustQuery(`SELECT authentication_string FROM mysql.User WHERE User="test1" and Host="%"`) - result.Check(testkit.Rows(auth.EncodePassword("1234"))) - alterUserSQL = `ALTER USER IF EXISTS 'test1' IDENTIFIED BY '222', 'test_not_exist'@'localhost' IDENTIFIED BY '111';` - rootTK.MustExec(alterUserSQL) - rootTK.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Note|3162|User 'test_not_exist'@'localhost' does not exist.")) - result = rootTK.MustQuery(`SELECT authentication_string FROM mysql.User WHERE User="test1" and Host="%"`) - result.Check(testkit.Rows(auth.EncodePassword("222"))) -} - func sha1Password(s string) []byte { crypt := sha1.New() crypt.Write([]byte(s)) diff --git a/pkg/executor/test/seqtest/BUILD.bazel b/pkg/executor/test/seqtest/BUILD.bazel index 644e9f4aa79ef..4c2e9835d8c58 100644 --- a/pkg/executor/test/seqtest/BUILD.bazel +++ b/pkg/executor/test/seqtest/BUILD.bazel @@ -10,7 +10,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 33, + shard_count = 31, deps = [ "//pkg/config", "//pkg/ddl/testutil", diff --git a/pkg/executor/test/seqtest/prepared_test.go b/pkg/executor/test/seqtest/prepared_test.go index da1c1f2b1505e..ddc740dbc4fcd 100644 --- a/pkg/executor/test/seqtest/prepared_test.go +++ b/pkg/executor/test/seqtest/prepared_test.go @@ -656,42 +656,3 @@ func TestPreparedIssue17419(t *testing.T) { // _, ok := tk1.Session().ShowProcess().Plan.(*plannercore.Execute) // require.True(t, ok) } - -func TestLimitUnsupportedCase(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, key(a))") - tk.MustExec("prepare stmt from 'select * from t limit ?'") - - tk.MustExec("set @a = 1.2") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = 1.") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = '0'") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = '1'") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = 1_2") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") -} - -func TestIssue38323(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(id int, k int);") - - tk.MustExec("prepare stmt from 'explain select * from t where id = ? and k = ? group by id, k';") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: not a SELECT/UPDATE/INSERT/DELETE/SET statement")) - tk.MustExec("set @a = 1;") - tk.MustExec("execute stmt using @a, @a") - tk.MustQuery("execute stmt using @a, @a").Check(tk.MustQuery("explain select * from t where id = 1 and k = 1 group by id, k").Rows()) - - tk.MustExec("prepare stmt from 'explain select * from t where ? = id and ? = k group by id, k';") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: not a SELECT/UPDATE/INSERT/DELETE/SET statement")) - tk.MustExec("set @a = 1;") - tk.MustQuery("execute stmt using @a, @a").Check(tk.MustQuery("explain select * from t where 1 = id and 1 = k group by id, k").Rows()) -} diff --git a/tests/integrationtest/r/black_list.result b/tests/integrationtest/r/black_list.result index 66c81ddc017ee..68c69c9dc6ba3 100644 --- a/tests/integrationtest/r/black_list.result +++ b/tests/integrationtest/r/black_list.result @@ -57,3 +57,106 @@ TableReader 3323.33 root data:Selection delete from mysql.expr_pushdown_blacklist; admin reload expr_pushdown_blacklist; +drop table if exists t; +create table t(a enum('a','b','c'), b enum('a','b','c'), c int, index idx(b,a)); +insert into t values(1,1,1),(2,2,2),(3,3,3); +insert into mysql.expr_pushdown_blacklist(name) values('enum'); +admin reload expr_pushdown_blacklist; + +desc format='brief' select /*+ HASH_AGG() */ max(a) from t; +id estRows task access object operator info +HashAgg 1.00 root funcs:max(black_list.t.a)->Column#5 +└─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t, index:idx(b, a) keep order:false, stats:pseudo +desc format='brief' select /*+ STREAM_AGG() */ max(a) from t; +id estRows task access object operator info +StreamAgg 1.00 root funcs:max(black_list.t.a)->Column#5 +└─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t, index:idx(b, a) keep order:false, stats:pseudo +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; + +desc format='brief' select /*+ HASH_AGG() */ max(a) from t; +id estRows task access object operator info +HashAgg 1.00 root funcs:max(Column#7)->Column#5 +└─IndexReader 1.00 root index:HashAgg + └─HashAgg 1.00 cop[tikv] funcs:max(black_list.t.a)->Column#7 + └─IndexFullScan 10000.00 cop[tikv] table:t, index:idx(b, a) keep order:false, stats:pseudo +desc format='brief' select /*+ STREAM_AGG() */ max(a) from t; +id estRows task access object operator info +StreamAgg 1.00 root funcs:max(Column#7)->Column#5 +└─IndexReader 1.00 root index:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:max(black_list.t.a)->Column#7 + └─IndexFullScan 10000.00 cop[tikv] table:t, index:idx(b, a) keep order:false, stats:pseudo +insert into mysql.expr_pushdown_blacklist(name) values('enum'); +admin reload expr_pushdown_blacklist; + +desc format='brief' select * from t where a + b; +id estRows task access object operator info +Selection 8000.00 root plus(cast(black_list.t.a, double BINARY), cast(black_list.t.b, double BINARY)) +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where a + b; +id estRows task access object operator info +Selection 8000.00 root plus(cast(black_list.t.a, double BINARY), cast(black_list.t.b, double BINARY)) +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; + +desc format='brief' select * from t where a + b; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] plus(cast(black_list.t.a, double BINARY), cast(black_list.t.b, double BINARY)) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where a + b; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] plus(cast(black_list.t.a, double BINARY), cast(black_list.t.b, double BINARY)) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +insert into mysql.expr_pushdown_blacklist(name) values('enum'); +admin reload expr_pushdown_blacklist; + +desc format='brief' select * from t where b = 1; +id estRows task access object operator info +Selection 8000.00 root eq(black_list.t.b, 1) +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where b = 'a'; +id estRows task access object operator info +Selection 8000.00 root eq(black_list.t.b, "a") +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where b > 1; +id estRows task access object operator info +Selection 8000.00 root gt(black_list.t.b, 1) +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where b > 'a'; +id estRows task access object operator info +Selection 8000.00 root gt(black_list.t.b, "a") +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; + +desc format='brief' select * from t where b = 1 and a = 1; +id estRows task access object operator info +IndexLookUp 0.10 root +├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(b, a) range:["a" "a","a" "a"], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where b = 'a' and a = 'a'; +id estRows task access object operator info +IndexLookUp 0.10 root +├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(b, a) range:["a" "a","a" "a"], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where b = 1 and a > 1; +id estRows task access object operator info +IndexLookUp 33.33 root +├─IndexRangeScan(Build) 33.33 cop[tikv] table:t, index:idx(b, a) range:("a" "a","a" +inf], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 33.33 cop[tikv] table:t keep order:false, stats:pseudo +desc format='brief' select * from t where b = 1 and a > 'a'; +id estRows task access object operator info +IndexLookUp 0.20 root +├─IndexRangeScan(Build) 0.20 cop[tikv] table:t, index:idx(b, a) range:["a" "b","a" "b"], ["a" "c","a" "c"], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.20 cop[tikv] table:t keep order:false, stats:pseudo diff --git a/tests/integrationtest/r/executor/executor.result b/tests/integrationtest/r/executor/executor.result index 35b29ee851b08..620918235febb 100644 --- a/tests/integrationtest/r/executor/executor.result +++ b/tests/integrationtest/r/executor/executor.result @@ -3349,3 +3349,958 @@ b > a select c > a from t; c > a 0 +load stats; +[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 11 near ";" +load stats ./xxx.json; +[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 12 near "./xxx.json;" +drop database if exists test_show; +create database test_show; +use test_show; +show engines; +Engine Support Comment Transactions XA Savepoints +InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YES YES +drop table if exists t; +create table t(a int primary key); +show index in t; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered +t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES +show index from t; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered +t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES +show master status; +File Position Binlog_Do_DB Binlog_Ignore_DB Executed_Gtid_Set +tidb-binlog 0 +show create database test_show; +Database Create Database +test_show CREATE DATABASE `test_show` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ +show privileges; +Privilege Context Comment +Alter Tables To alter the table +Alter routine Functions,Procedures To alter or drop stored functions/procedures +Config Server Admin To use SHOW CONFIG and SET CONFIG statements +Create Databases,Tables,Indexes To create new databases and tables +Create routine Databases To use CREATE FUNCTION/PROCEDURE +Create role Server Admin To create new roles +Create temporary tables Databases To use CREATE TEMPORARY TABLE +Create view Tables To create new views +Create user Server Admin To create new users +Delete Tables To delete existing rows +Drop Databases,Tables To drop databases, tables, and views +Drop role Server Admin To drop roles +Event Server Admin To create, alter, drop and execute events +Execute Functions,Procedures To execute stored routines +File File access on server To read and write files on the server +Grant option Databases,Tables,Functions,Procedures To give to other users those privileges you possess +Index Tables To create or drop indexes +Insert Tables To insert data into tables +Lock tables Databases To use LOCK TABLES (together with SELECT privilege) +Process Server Admin To view the plain text of currently executing queries +Proxy Server Admin To make proxy user possible +References Databases,Tables To have references on tables +Reload Server Admin To reload or refresh tables, logs and privileges +Replication client Server Admin To ask where the slave or master servers are +Replication slave Server Admin To read binary log events from the master +Select Tables To retrieve rows from table +Show databases Server Admin To see all databases with SHOW DATABASES +Show view Tables To see views with SHOW CREATE VIEW +Shutdown Server Admin To shut down the server +Super Server Admin To use KILL thread, SET GLOBAL, CHANGE MASTER, etc. +Trigger Tables To use triggers +Create tablespace Server Admin To create/alter/drop tablespaces +Update Tables To update existing rows +Usage Server Admin No privileges - allow connect only +BACKUP_ADMIN Server Admin +RESTORE_ADMIN Server Admin +SYSTEM_USER Server Admin +SYSTEM_VARIABLES_ADMIN Server Admin +ROLE_ADMIN Server Admin +CONNECTION_ADMIN Server Admin +PLACEMENT_ADMIN Server Admin +DASHBOARD_CLIENT Server Admin +RESTRICTED_TABLES_ADMIN Server Admin +RESTRICTED_STATUS_ADMIN Server Admin +RESTRICTED_VARIABLES_ADMIN Server Admin +RESTRICTED_USER_ADMIN Server Admin +RESTRICTED_CONNECTION_ADMIN Server Admin +RESTRICTED_REPLICA_WRITER_ADMIN Server Admin +RESOURCE_GROUP_ADMIN Server Admin +show table status; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t InnoDB 10 Compact 0 0 0 0 0 0 NULL 0 NULL NULL utf8mb4_bin +drop database test_show; +use executor__executor; +select \N; +NULL +NULL +select "\N"; +N +N +drop table if exists test; +create table test (`\N` int); +insert into test values (1); +select * from test; +\N +1 +select \N from test; +NULL +NULL +select (\N) from test; +NULL +NULL +select `\N` from test; +\N +1 +select (`\N`) from test; +\N +1 +select '\N' from test; +N +N +select ('\N') from test; +N +N +select nUll; +NULL +NULL +select (null); +NULL +NULL +select null+NULL; +null+NULL +NULL +select 'abc'; +abc +abc +select (('abc')); +abc +abc +select 'abc'+'def'; +'abc'+'def' +0 +select '\n'; + + + +select '\t col'; +col + col +select '\t Col'; +Col + Col +select '\n\t 中文 col'; +中文 col + + 中文 col +select ' \r\n .col'; +.col + + .col +select ' 😆col'; +😆col + 😆col +select 'abc '; +abc +abc +select ' abc 123 '; +abc 123 + abc 123 +select 'a' ' ' 'string'; +a +a string +select 'a' " " "string"; +a +a string +select 'string' 'string'; +string +stringstring +select "ss" "a"; +ss +ssa +select "ss" "a" "b"; +ss +ssab +select "ss" "a" ' ' "b"; +ss +ssa b +select "ss" "a" ' ' "b" ' ' "d"; +ss +ssa b d +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; +select * from b; +a k1 k2 v +2 3 4 100 +select * from a; +k1 k2 v +2 3 20 +3 4 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +2 3 4 100 +select * from a; +k1 k2 v +2 3 20 +3 4 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +22 23 24 100 +select * from a; +k1 k2 v +12 13 20 +23 24 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +22 23 24 100 +select * from a; +k1 k2 v +12 13 20 +23 24 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +22 23 24 100 +select * from a; +k1 k2 v +11 11 11 +23 24 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); +select * from b; +a k1 k2 v +22 22 22 22 +select * from a; +k1 k2 v +11 11 11 +23 24 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; +select * from b; +a k1 k2 v +2 3 4 100 +select * from a; +k1 k2 v +2 3 20 +3 4 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +2 3 4 100 +select * from a; +k1 k2 v +2 3 20 +3 4 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +22 23 24 100 +select * from a; +k1 k2 v +12 13 20 +23 24 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +22 23 24 100 +select * from a; +k1 k2 v +12 13 20 +23 24 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +a k1 k2 v +22 23 24 100 +select * from a; +k1 k2 v +11 11 11 +23 24 20 +admin check table a; + +admin check table b; + +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); +select * from b; +a k1 k2 v +22 22 22 22 +select * from a; +k1 k2 v +11 11 11 +23 24 20 +admin check table a; + +admin check table b; + +set @@tidb_enable_clustered_index=On; +drop table if exists t; +create table t (a int, b int, c int, primary key(a,b)); +explain format = 'brief' select t1.a from t t1 left join t t2 on t1.a = t2.a and t1.b = t2.b; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +set @@tidb_enable_clustered_index=default; +drop table if exists t; +create table t (c1 bit(2)); +insert into t values (0), (1), (2), (3); +insert into t values (4); +Error 1406 (22001): Data too long for column 'c1' at row 1 +insert into t values ('a'); +Error 1406 (22001): Data too long for column 'c1' at row 1 +select hex(c1) from t where c1 = 2; +hex(c1) +2 +drop table if exists t; +create table t (c1 bit(31)); +insert into t values (0x7fffffff); +insert into t values (0x80000000); +Error 1406 (22001): Data too long for column 'c1' at row 1 +insert into t values (0xffffffff); +Error 1406 (22001): Data too long for column 'c1' at row 1 +insert into t values ('123'); +insert into t values ('1234'); +insert into t values ('12345); +[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 30 near "'12345);" +drop table if exists t; +create table t (c1 bit(62)); +insert into t values ('12345678'); +drop table if exists t; +create table t (c1 bit(61)); +insert into t values ('12345678'); +Error 1406 (22001): Data too long for column 'c1' at row 1 +drop table if exists t; +create table t (c1 bit(32)); +insert into t values (0x7fffffff); +insert into t values (0xffffffff); +insert into t values (0x1ffffffff); +Error 1406 (22001): Data too long for column 'c1' at row 1 +insert into t values ('1234'); +insert into t values ('12345'); +Error 1406 (22001): Data too long for column 'c1' at row 1 +drop table if exists t; +create table t (c1 bit(64)); +insert into t values (0xffffffffffffffff); +insert into t values ('12345678'); +insert into t values ('123456789'); +Error 1366 (HY000): Incorrect bit value: '123456789' for column 'c1' at row 1 +drop table if exists t; +create table t (c1 bit(64)); +insert into t values (0xffffffffffffffff); +insert into t values ('12345678'); +select hex(c1) from t where c1; +hex(c1) +FFFFFFFFFFFFFFFF +3132333435363738 +drop table if exists t, t1; +create table t (ts timestamp); +set time_zone = '+00:00'; +insert into t values ('2017-04-27 22:40:42'); +set time_zone = '+10:00'; +select * from t; +ts +2017-04-28 08:40:42 +set time_zone = '-6:00'; +select * from t; +ts +2017-04-27 16:40:42 +drop table if exists t1; +CREATE TABLE t1 ( +id bigint(20) NOT NULL AUTO_INCREMENT, +uid int(11) DEFAULT NULL, +datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +ip varchar(128) DEFAULT NULL, +PRIMARY KEY (id), +KEY i_datetime (datetime), +KEY i_userid (uid) +); +INSERT INTO t1 VALUES (123381351,1734,"2014-03-31 08:57:10","127.0.0.1"); +select datetime from t1; +datetime +2014-03-31 08:57:10 +select datetime from t1 where datetime='2014-03-31 08:57:10'; +datetime +2014-03-31 08:57:10 +select * from t1 where datetime='2014-03-31 08:57:10'; +id uid datetime ip +123381351 1734 2014-03-31 08:57:10 127.0.0.1 +set time_zone = 'Asia/Shanghai'; +drop table if exists t1; +CREATE TABLE t1 ( +id bigint(20) NOT NULL AUTO_INCREMENT, +datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (id) +); +INSERT INTO t1 VALUES (123381351,"2014-03-31 08:57:10"); +select * from t1 where datetime="2014-03-31 08:57:10"; +id datetime +123381351 2014-03-31 08:57:10 +alter table t1 add key i_datetime (datetime); +select * from t1 where datetime="2014-03-31 08:57:10"; +id datetime +123381351 2014-03-31 08:57:10 +select * from t1; +id datetime +123381351 2014-03-31 08:57:10 +select datetime from t1 where datetime='2014-03-31 08:57:10'; +datetime +2014-03-31 08:57:10 +set time_zone=default; +drop table if exists t2; +create table t2(a int, b int, c int); +insert into t2 values (11, 8, (select not b)); +Error 1054 (42S22): Unknown column 'b' in 'field list' +insert into t2 set a = 11, b = 8, c = (select b)); +[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 49 near ");" +insert into t2 values(1, 1, (select b from t2)); +select * from t2; +a b c +1 1 NULL +insert into t2 set a = 1, b = 1, c = (select b+1 from t2); +select * from t2; +a b c +1 1 NULL +1 1 2 +delete from t2; +insert into t2 values(2, 4, a); +select * from t2; +a b c +2 4 2 +insert into t2 set a = 3, b = 5, c = b; +select * from t2; +a b c +2 4 2 +3 5 5 +drop table if exists t; +create table t(a int, b int); +insert into t values ( 81, ( select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ) ); +Error 1105 (HY000): Insert's SET operation or VALUES_LIST doesn't support complex subqueries now +insert into t set a = 81, b = (select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ); +Error 1105 (HY000): Insert's SET operation or VALUES_LIST doesn't support complex subqueries now +drop table if exists t2; +drop table if exists t; +create table t (id bit(16), key id(id)); +insert into t values (65); +select * from t where id not in (-1,2); +id +A +select * from t where id in (-1, -2); +Error 1582 (42000): Incorrect parameter count in the call to native function 'in' +drop table if exists t; +drop table if exists t1; +create table t(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) clustered); +create table t1(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) nonclustered); +insert into t(k1) select 1; +insert into t1(k1) select 1; +set @@tidb_enable_vectorized_expression = 0; +(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); +k1 hex(v) +1 1D5E4CF7F +(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); +k1 hex(v) +1 1D5E4CF7F +set @@tidb_enable_vectorized_expression = 1; +(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); +k1 hex(v) +1 1D5E4CF7F +(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); +k1 hex(v) +1 1D5E4CF7F +set @@tidb_enable_vectorized_expression = default; +drop table if exists t; +drop view if exists v; +create table t(a int); +insert into t values(1), (2), (3); +create definer='root'@'localhost' view v as select count(*) as c1 from t; +select * from v; +c1 +3 +drop view v; +create definer='root'@'localhost' view v as select * from (select count(*) from t) s; +select * from v order by 1; +count(*) +3 +drop view v; +create definer='root'@'localhost' view v as select * from (select avg(a) from t group by a) s; +select * from v order by 1; +avg(a) +1.0000 +2.0000 +3.0000 +drop view v; +create definer='root'@'localhost' view v as select * from (select sum(a) from t group by a) s; +select * from v order by 1; +sum(a) +1 +2 +3 +drop view v; +create definer='root'@'localhost' view v as select * from (select group_concat(a) from t group by a) s; +select * from v order by 1; +group_concat(a) +1 +2 +3 +drop view v; +create definer='root'@'localhost' view v as select * from (select count(0) as c1 from t) s; +select * from v order by 1; +c1 +3 +drop view v; +create definer='root'@'localhost' view v as select * from (select count(*) as c1 from t) s; +select * from v order by 1; +c1 +3 +drop view v; +create definer='root'@'localhost' view v as select * from (select group_concat(a) as `concat(a)` from t group by a) s; +select * from v order by 1; +concat(a) +1 +2 +3 +drop view v; +create definer='root'@'localhost' view v as select * from (select a from t group by a) s; +select * from v order by 1; +a +1 +2 +3 +SELECT `s`.`count(a)` FROM (SELECT COUNT(`a`) FROM `test`.`t`) AS `s`; +Error 1146 (42S02): Table 'test.t' doesn't exist +drop view v; +create definer='root'@'localhost' view v as select * from (select count(a) from t) s; +select * from v; +count(a) +3 +drop table if exists t; +create table t(c1 int); +insert into t values(111), (222), (333); +drop view if exists v; +create definer='root'@'localhost' view v as (select * from (select row_number() over (order by c1) from t) s); +select * from v; +row_number() over (order by c1) +1 +2 +3 +drop view if exists v; +create definer='root'@'localhost' view v as (select * from (select c1, row_number() over (order by c1) from t) s); +select * from v; +c1 row_number() over (order by c1) +111 1 +222 2 +333 3 +drop view if exists v; +create definer='root'@'localhost' view v as (select * from (select c1 or 0 from t) s); +select * from v; +c1 or 0 +1 +1 +1 +select `c1 or 0` from v; +c1 or 0 +1 +1 +1 +drop view v; +drop table if exists t, t1, t2; +create table t (a int(11) default null,b int(11) default null,key b (b),key ba (b)); +create table t1 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); +create table t2 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +DROP TABLE IF EXISTS admin_checksum_partition_test; +CREATE TABLE admin_checksum_partition_test (a INT) PARTITION BY HASH(a) PARTITIONS 4; +INSERT INTO admin_checksum_partition_test VALUES (1), (2); +ADMIN CHECKSUM TABLE admin_checksum_partition_test; +drop table if exists t; +create table t (a tinyint not null); +set sql_mode = 'STRICT_TRANS_TABLES'; +insert t values (); +Error 1364 (HY000): Field 'a' doesn't have a default value +insert t values ('1000'); +Error 1264 (22003): Out of range value for column 'a' at row 1 +create table if not exists tdouble (a double(3,2)); +insert tdouble values (10.23); +Error 1264 (22003): Out of range value for column 'a' at row 1 +set sql_mode = ''; +insert t values (); +show warnings; +Level Code Message +Warning 1364 Field 'a' doesn't have a default value +insert t values (null); +show warnings; +Level Code Message +Warning 1048 Column 'a' cannot be null +insert ignore t values (null); +show warnings; +Level Code Message +Warning 1048 Column 'a' cannot be null +insert t select null; +show warnings; +Level Code Message +Warning 1048 Column 'a' cannot be null +insert t values (1000); +select * from t order by a; +a +0 +0 +0 +0 +127 +insert tdouble values (10.23); +select * from tdouble; +a +9.99 +set sql_mode = 'STRICT_TRANS_TABLES'; +set @@global.sql_mode = ''; +drop table if exists t2; +create table t2 (a varchar(3)); +insert t2 values ('abcd'); +select * from t2; +a +abc +insert t2 values ('abcd'); +Error 1406 (22001): Data too long for column 'a' at row 1 +set sql_mode = default; +set @@global.sql_mode = default; +use information_schema; +select count(*)>=4 from schemata; +count(*)>=4 +1 +create database mytest; +use information_schema; +select * from schemata where schema_name = 'mysql'; +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME SQL_PATH TIDB_PLACEMENT_POLICY_NAME +def mysql utf8mb4 utf8mb4_bin NULL NULL +select * from schemata where schema_name like 'my%'; +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME SQL_PATH TIDB_PLACEMENT_POLICY_NAME +def mysql utf8mb4 utf8mb4_bin NULL NULL +def mytest utf8mb4 utf8mb4_bin NULL NULL +select 1 from tables limit 1; +1 +1 +use executor__executor; +set @@sql_mode='NO_ZERO_DATE'; +select date_add('2001-01-00', interval -2 hour); +date_add('2001-01-00', interval -2 hour) +NULL +show warnings; +Level Code Message +Warning 1292 Incorrect datetime value: '2001-01-00' +set @@sql_mode=default; +set @@sql_mode='NO_ZERO_DATE'; +drop table if exists t1; +SELECT STR_TO_DATE('0000-1-01', '%Y-%m-%d'); +STR_TO_DATE('0000-1-01', '%Y-%m-%d') +NULL +show warnings; +Level Code Message +Warning 1411 Incorrect datetime value: '0000-1-01' for function str_to_date +SELECT CAST('4#,8?Q' AS DATE); +CAST('4#,8?Q' AS DATE) +NULL +show warnings; +Level Code Message +Warning 8034 Incorrect datetime value: '4#,8?Q' +CREATE TABLE t1 (c1 INT, c2 TEXT); +INSERT INTO t1 VALUES (1833458842, '0.3503490908550797'); +SELECT CAST(t1.c2 AS DATE) FROM t1; +CAST(t1.c2 AS DATE) +NULL +show warnings; +Level Code Message +Warning 1292 Incorrect datetime value: '0.3503490908550797' +set @@sql_mode=default; +drop table if exists t; +create table t(a decimal(10,2) unsigned); +insert into t values (-1); +Error 1264 (22003): Out of range value for column 'a' at row 1 +insert into t values ("-1.1e-1"); +Error 1264 (22003): Out of range value for column 'a' at row 1 +insert into t values (-1.1); +Error 1264 (22003): Out of range value for column 'a' at row 1 +insert into t values (-0); +set sql_mode=''; +delete from t; +insert into t values (-1); +select a from t limit 1; +a +0.00 +set sql_mode=default; +drop table if exists t; +create table t(a int); +do 1 in (select * from t); +insert into t values(1); +do 1 in (select * from t); +drop table if exists t; +create table t(j JSON); +insert into t values('2010'); +insert into t values('2011'); +insert into t values('2012'); +insert into t values('2010.000'); +insert into t values(cast(18446744073709551615 as JSON)); +insert into t values(cast(18446744073709551616.000000 as JSON)); +select count(distinct j) from t; +count(distinct j) +5 +drop table if exists t; +create table t(id int(11), j JSON, d DOUBLE); +insert into t values(0, '2010', 2010); +insert into t values(1, '2011', 2011); +insert into t values(2, '2012', 2012); +insert into t values(3, cast(18446744073709551615 as JSON), 18446744073709551616.000000); +select /*+inl_hash_join(t2)*/ t1.id, t2.id from t t1 join t t2 on t1.j = t2.d; +id id +0 0 +1 1 +2 2 +drop table if exists catalog_sales, store_sales, date_dim; +create table catalog_sales +( +cs_sold_date_sk int , +cs_sold_time_sk int , +cs_ship_date_sk int , +cs_bill_customer_sk int , +cs_bill_cdemo_sk int , +cs_bill_hdemo_sk int , +cs_bill_addr_sk int , +cs_ship_customer_sk int , +cs_ship_cdemo_sk int , +cs_ship_hdemo_sk int , +cs_ship_addr_sk int , +cs_call_center_sk int , +cs_catalog_page_sk int , +cs_ship_mode_sk int , +cs_warehouse_sk int , +cs_item_sk int not null, +cs_promo_sk int , +cs_order_number int not null, +cs_quantity int , +cs_wholesale_cost decimal(7,2) , +cs_list_price decimal(7,2) , +cs_sales_price decimal(7,2) , +cs_ext_discount_amt decimal(7,2) , +cs_ext_sales_price decimal(7,2) , +cs_ext_wholesale_cost decimal(7,2) , +cs_ext_list_price decimal(7,2) , +cs_ext_tax decimal(7,2) , +cs_coupon_amt decimal(7,2) , +cs_ext_ship_cost decimal(7,2) , +cs_net_paid decimal(7,2) , +cs_net_paid_inc_tax decimal(7,2) , +cs_net_paid_inc_ship decimal(7,2) , +cs_net_paid_inc_ship_tax decimal(7,2) , +cs_net_profit decimal(7,2) , +primary key (cs_item_sk, cs_order_number) +); +create table store_sales +( +ss_sold_date_sk int , +ss_sold_time_sk int , +ss_item_sk int not null, +ss_customer_sk int , +ss_cdemo_sk int , +ss_hdemo_sk int , +ss_addr_sk int , +ss_store_sk int , +ss_promo_sk int , +ss_ticket_number int not null, +ss_quantity int , +ss_wholesale_cost decimal(7,2) , +ss_list_price decimal(7,2) , +ss_sales_price decimal(7,2) , +ss_ext_discount_amt decimal(7,2) , +ss_ext_sales_price decimal(7,2) , +ss_ext_wholesale_cost decimal(7,2) , +ss_ext_list_price decimal(7,2) , +ss_ext_tax decimal(7,2) , +ss_coupon_amt decimal(7,2) , +ss_net_paid decimal(7,2) , +ss_net_paid_inc_tax decimal(7,2) , +ss_net_profit decimal(7,2) , +primary key (ss_item_sk, ss_ticket_number) +); +create table date_dim +( +d_date_sk int not null, +d_date_id char(16) not null, +d_date date , +d_month_seq int , +d_week_seq int , +d_quarter_seq int , +d_year int , +d_dow int , +d_moy int , +d_dom int , +d_qoy int , +d_fy_year int , +d_fy_quarter_seq int , +d_fy_week_seq int , +d_day_name char(9) , +d_quarter_name char(6) , +d_holiday char(1) , +d_weekend char(1) , +d_following_holiday char(1) , +d_first_dom int , +d_last_dom int , +d_same_day_ly int , +d_same_day_lq int , +d_current_day char(1) , +d_current_week char(1) , +d_current_month char(1) , +d_current_quarter char(1) , +d_current_year char(1) , +primary key (d_date_sk) +); +plan replayer dump explain with ssci as ( +select ss_customer_sk customer_sk +,ss_item_sk item_sk +from store_sales,date_dim +where ss_sold_date_sk = d_date_sk +and d_month_seq between 1212 and 1212 + 11 +group by ss_customer_sk +,ss_item_sk), +csci as( +select cs_bill_customer_sk customer_sk +,cs_item_sk item_sk +from catalog_sales,date_dim +where cs_sold_date_sk = d_date_sk +and d_month_seq between 1212 and 1212 + 11 +group by cs_bill_customer_sk +,cs_item_sk) +select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only +,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only +,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog +from ssci left join csci on (ssci.customer_sk=csci.customer_sk +and ssci.item_sk = csci.item_sk) +UNION +select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only +,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only +,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog +from ssci right join csci on (ssci.customer_sk=csci.customer_sk +and ssci.item_sk = csci.item_sk) +limit 100; diff --git a/tests/integrationtest/r/executor/index_merge_reader.result b/tests/integrationtest/r/executor/index_merge_reader.result new file mode 100644 index 0000000000000..fb6f3a9b1f890 --- /dev/null +++ b/tests/integrationtest/r/executor/index_merge_reader.result @@ -0,0 +1,514 @@ +drop table if exists t1, t2; +create table t1(id int primary key, a int, b int, c int, d int); +create index t1a on t1(a); +create index t1b on t1(b); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by id; +id a b c d +1 1 1 1 1 +5 5 5 5 5 +select /*+ use_index_merge(t1, primary, t1a) */ a from t1 where id < 2 or a > 4 order by a; +a +1 +5 +select /*+ use_index_merge(t1, primary, t1a) */ sum(a) from t1 where id < 2 or a > 4; +sum(a) +6 +select /*+ use_index_merge(t1, t1a, t1b) */ * from t1 where a < 2 or b > 4 order by a; +id a b c d +1 1 1 1 1 +5 5 5 5 5 +select /*+ use_index_merge(t1, t1a, t1b) */ a from t1 where a < 2 or b > 4 order by a; +a +1 +5 +select /*+ use_index_merge(t1, t1a, t1b) */ sum(a) from t1 where a < 2 or b > 4; +sum(a) +6 +drop table if exists t1, t2; +create table t1(id int primary key, a int, b int, c int, d int); +create index t1a on t1(a); +create index t1b on t1(b); +create table t2(id int primary key, a int); +create index t2a on t2(a); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +insert into t2 values(1,1),(5,5); +select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 4; +sum(t1.a) +6 +select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 5; +sum(t1.a) +1 +drop table if exists t0; +CREATE TABLE t0(c0 INT AS (1), c1 INT PRIMARY KEY); +INSERT INTO t0(c1) VALUES (0); +CREATE INDEX i0 ON t0(c0); +SELECT /*+ USE_INDEX_MERGE(t0, i0, PRIMARY)*/ t0.c0 FROM t0 WHERE t0.c1 OR t0.c0; +c0 +1 +SELECT t0.c0 FROM t0 WHERE t0.c1 OR t0.c0; +c0 +1 +drop table if exists t1; +create table t1(a int primary key, b int, c int, key(b), key(c)); +INSERT INTO t1 VALUES (10, 10, 10), (11, 11, 11); +explain format='brief' select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10); +id estRows task access object operator info +IndexMerge 0.01 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:c(c) range:[10,10], keep order:false, stats:pseudo +├─TableRangeScan(Build) 1.00 cop[tikv] table:t1 range:[10,10], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] or(eq(executor__index_merge_reader.t1.c, 10), and(eq(executor__index_merge_reader.t1.b, 10), eq(executor__index_merge_reader.t1.a, 10))) + └─TableRowIDScan 11.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10); +a b c +10 10 10 +drop table if exists t1, t2, t3; +create table t1 (a int not null, b tinyint not null, index (a), index (b)) partition by range (a) (partition p0 values less than (10),partition p1 values less than (20),partition p2 values less than (30),partition p3 values less than (40),partition p4 values less than MAXVALUE); +insert into t1 values(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (40, 40), (50, 50), (80, 80), (90, 90), (100, 100); +create table t2 (a int not null, b bigint not null, index (a), index (b)) partition by hash(a) partitions 10; +insert into t2 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23); +select /*+ USE_INDEX_MERGE(t1, a, b) */ * from t1 partition (p0) join t2 partition (p1) on t1.a = t2.a where t1.a < 40 or t1.b < 30; +a b a b +1 1 1 1 +drop table if exists t; +set @@tidb_enable_index_merge = 1; +create table t (a int, b int, c int, primary key(a), key(b)); +explain format='brief' select /*+ inl_join(t2) */ * from t t1 join t t2 on t1.a = t2.a and t1.c = t2.c where t2.a = 1 or t2.b = 1; +id estRows task access object operator info +Projection 13.74 root executor__index_merge_reader.t.a, executor__index_merge_reader.t.b, executor__index_merge_reader.t.c, executor__index_merge_reader.t.a, executor__index_merge_reader.t.b, executor__index_merge_reader.t.c +└─IndexJoin 13.74 root inner join, inner:TableReader, outer key:executor__index_merge_reader.t.a, inner key:executor__index_merge_reader.t.a, equal cond:eq(executor__index_merge_reader.t.a, executor__index_merge_reader.t.a), eq(executor__index_merge_reader.t.c, executor__index_merge_reader.t.c), other cond:or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(executor__index_merge_reader.t.c)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10.98 root data:Selection + └─Selection 10.98 cop[tikv] not(isnull(executor__index_merge_reader.t.c)), or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + └─TableRangeScan 9990.00 cop[tikv] table:t2 range: decided by [executor__index_merge_reader.t.a], keep order:false, stats:pseudo +set @@tidb_enable_index_merge = default; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk)); +begin; +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10; +id estRows task access object operator info +IndexMerge_9 1841.86 root type: union +├─IndexRangeScan_5(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo +└─Selection_8(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10) + └─TableRowIDScan_7 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo +explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10; +id estRows task access object operator info +IndexMerge_9 1106.67 root type: union +├─TableRangeScan_5(Build) 3333.33 cop[tikv] table:t1 range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo +└─Selection_8(Probe) 1106.67 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10) + └─TableRowIDScan_7 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo +explain select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where c1 < 10 and c2 < 10 and c3 < 10; +id estRows task access object operator info +IndexMerge_9 367.05 root type: intersection +├─IndexRangeScan_5(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo +└─TableRowIDScan_8(Probe) 367.05 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < -1 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +1 1 100 1 +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < -1 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < -1) and c3 < 10; +c1 c2 c3 pk +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +1 1 100 1 +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +commit; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk)); +set tx_isolation = 'READ-COMMITTED'; +begin; +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10; +id estRows task access object operator info +IndexMerge_9 1841.86 root type: union +├─IndexRangeScan_5(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo +└─Selection_8(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10) + └─TableRowIDScan_7 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo +explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10; +id estRows task access object operator info +IndexMerge_9 1106.67 root type: union +├─TableRangeScan_5(Build) 3333.33 cop[tikv] table:t1 range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo +└─Selection_8(Probe) 1106.67 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10) + └─TableRowIDScan_7 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo +explain select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where c1 < 10 and c2 < 10 and c3 < 10; +id estRows task access object operator info +IndexMerge_9 367.05 root type: intersection +├─IndexRangeScan_5(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_6(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo +├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo +└─TableRowIDScan_8(Probe) 367.05 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < -1 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +1 1 100 1 +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < -1 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < -1) and c3 < 10; +c1 c2 c3 pk +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 < 10; +c1 c2 c3 pk +1 1 1 1 +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +1 1 100 1 +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +c1 c2 c3 pk +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +c1 c2 c3 pk +commit; +set tx_isolation = 'REPEATABLE-READ'; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk)); +begin; +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +id estRows task access object operator info +SelectLock_6 1841.86 root for update 0 +└─IndexMerge_11 1841.86 root type: union + ├─IndexRangeScan_7(Build) 3323.33 cop[tikv] table:t1, index:c1(c1) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo + └─Selection_10(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10) + └─TableRowIDScan_9 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo +explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +id estRows task access object operator info +SelectLock_6 1106.67 root for update 0 +└─IndexMerge_11 1106.67 root type: union + ├─TableRangeScan_7(Build) 3333.33 cop[tikv] table:t1 range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c2(c2) range:[-inf,10), keep order:false, stats:pseudo + └─Selection_10(Probe) 1106.67 cop[tikv] lt(executor__index_merge_reader.t1.c3, 10) + └─TableRowIDScan_9 3330.01 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +1 1 1 1 +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +1 1 1 1 +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +c1 c2 c3 pk +commit; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, part int, key(c1), key(c2), key(c3), primary key(pk, part)) +partition by range(part) ( +partition p0 values less than (10), +partition p1 values less than (20), +partition p2 values less than (maxvalue)); +begin; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < 20) and c3 < 20; +c1 c2 c3 pk part +insert into t1 values(1, 1, 1, 1, 1); +insert into t1 values(11, 11, 11, 11, 11); +insert into t1 values(21, 21, 21, 21, 21); +insert into t1 values(31, 31, 31, 31, 31); +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20; +c1 c2 c3 pk part +1 1 1 1 1 +11 11 11 11 11 +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20; +c1 c2 c3 pk part +1 1 1 1 1 +11 11 11 11 11 +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20; +c1 c2 c3 pk part +1 1 1 1 1 +11 11 11 11 11 +select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20; +c1 c2 c3 pk part +1 1 1 1 1 +11 11 11 11 11 +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20; +c1 c2 c3 pk part +11 11 11 11 11 +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20; +c1 c2 c3 pk part +11 11 11 11 11 +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20; +c1 c2 c3 pk part +11 11 11 11 11 +select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20; +c1 c2 c3 pk part +11 11 11 11 11 +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20; +c1 c2 c3 pk part +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20; +c1 c2 c3 pk part +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20; +c1 c2 c3 pk part +select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20; +c1 c2 c3 pk part +commit; +set tx_isolation = default; +drop table if exists t1; +create table t1 (col_30 decimal default 0 , +col_31 char(99) collate utf8_bin default 'sVgzHblmYYtEjVg' not null , +col_37 int unsigned default 377206828 , +primary key idx_16 ( col_37 ) , key idx_19 ( col_31) ) collate utf8mb4_general_ci ; +begin; +insert ignore into t1 values (388021, '', 416235653); +select /*+ use_index_merge( t1 ) */ 1 from t1 where ( t1.col_31 in ( 'OiOXzpCs' , 'oaVv' ) or t1.col_37 <= 4059907010 ) and t1.col_30 ; +1 +1 +commit; +drop table if exists tbl_3; +create table tbl_3 ( col_30 decimal , col_31 char(99) , col_32 smallint , +col_33 tinyint unsigned not null , col_34 char(209) , +col_35 char(110) , col_36 int unsigned , col_37 int unsigned , +col_38 decimal(50,15) not null , col_39 char(104), +primary key ( col_37 ) , unique key ( col_33,col_30,col_36,col_39 ) , +unique key ( col_32,col_35 ) , key ( col_31,col_38 ) , +key ( col_31,col_33,col_32,col_35,col_36 ) , +unique key ( col_38,col_34,col_33,col_31,col_30,col_36,col_35,col_37,col_39 ) , +unique key ( col_39,col_32 ) , unique key ( col_30,col_35,col_31,col_38 ) , +key ( col_38,col_32,col_33 ) ); +begin; +insert ignore into tbl_3 values ( 71,'Fipc',-6676,30,'','FgfK',2464927398,4084082400,5602.5868,'' ); +select /*+ use_index_merge( tbl_3 ) */ 1 from tbl_3 where ( tbl_3.col_37 not in ( 1626615245 , 2433569159 ) or tbl_3.col_38 = 0.06 ) ; +1 +1 +commit; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, c4 int, primary key(c1, c2) /*T![clustered_index] CLUSTERED */, key(c3)); +begin; +insert into t1 values(1, 1, 1, 1); +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10; +id estRows task access object operator info +UnionScan_6 1841.86 root lt(executor__index_merge_reader.t1.c4, 10), or(lt(executor__index_merge_reader.t1.c1, -1), lt(executor__index_merge_reader.t1.c3, 10)) +└─IndexMerge_11 1841.86 root type: union + ├─TableRangeScan_7(Build) 3323.33 cop[tikv] table:t1 range:[-inf,-1), keep order:false, stats:pseudo + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo + └─Selection_10(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c4, 10) + └─TableRowIDScan_9 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10; +c1 c2 c3 c4 +1 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c3 < -1) and c4 < 10; +c1 c2 c3 c4 +1 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < -1) and c4 < 10; +c1 c2 c3 c4 +commit; +drop table if exists t1; +create table t1(c1 varchar(100), c2 int, c3 int, c4 int, primary key(c1) /*T![clustered_index] CLUSTERED */, key(c3)); +begin; +insert into t1 values('b', 1, 1, 1); +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10; +id estRows task access object operator info +UnionScan_6 1841.86 root lt(executor__index_merge_reader.t1.c4, 10), or(lt(executor__index_merge_reader.t1.c1, "a"), lt(executor__index_merge_reader.t1.c3, 10)) +└─IndexMerge_11 1841.86 root type: union + ├─TableRangeScan_7(Build) 3323.33 cop[tikv] table:t1 range:[-inf,"a"), keep order:false, stats:pseudo + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t1, index:c3(c3) range:[-inf,10), keep order:false, stats:pseudo + └─Selection_10(Probe) 1841.86 cop[tikv] lt(executor__index_merge_reader.t1.c4, 10) + └─TableRowIDScan_9 5542.21 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10; +c1 c2 c3 c4 +b 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (c1 <= 'b' or c3 < -1) and c4 < 10; +c1 c2 c3 c4 +b 1 1 1 +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < -1) and c4 < 10; +c1 c2 c3 c4 +commit; +DROP TABLE IF EXISTS tab2; +CREATE TABLE tab2(pk INTEGER PRIMARY KEY, col0 INTEGER, col1 FLOAT, col2 TEXT, col3 INTEGER, col4 FLOAT, col5 TEXT); +CREATE INDEX idx_tab2_0 ON tab2 (col0 DESC,col3 DESC); +CREATE UNIQUE INDEX idx_tab2_3 ON tab2 (col4,col0 DESC); +CREATE INDEX idx_tab2_4 ON tab2 (col3,col1 DESC); +INSERT INTO tab2 VALUES(0,146,632.63,'shwwd',703,412.47,'xsppr'); +INSERT INTO tab2 VALUES(1,81,536.29,'trhdh',49,726.3,'chuxv'); +INSERT INTO tab2 VALUES(2,311,541.72,'txrvb',493,581.92,'xtrra'); +INSERT INTO tab2 VALUES(3,669,293.27,'vcyum',862,415.14,'nbutk'); +INSERT INTO tab2 VALUES(4,681,49.46,'odzhp',106,324.65,'deudp'); +INSERT INTO tab2 VALUES(5,319,769.65,'aeqln',855,197.9,'apipa'); +INSERT INTO tab2 VALUES(6,610,302.62,'bixap',184,840.31,'vggit'); +INSERT INTO tab2 VALUES(7,253,453.21,'gjccm',107,104.5,'lvunv'); +SPLIT TABLE tab2 BY (5); +SELECT /*+ use_index_merge(tab2) */ pk FROM tab2 WHERE (col4 > 565.89 OR col0 > 68 ) and col0 > 10 order by 1; +pk +0 +1 +2 +3 +4 +5 +6 +7 +drop table if exists t; +create table t(a int, b int, c int, index idx(a, c), index idx2(b, c)); +insert into t values(1, 1, 1), (2, 2, 2); +explain format='brief' select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1; +id estRows task access object operator info +IndexMerge 1.00 root type: union, limit embedded(offset:0, count:1) +├─Limit(Build) 0.50 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan 0.50 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo +├─Limit(Build) 0.50 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan 0.50 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1; +a b c +1 1 1 +drop table if exists t; +create table t(a int, b int, c int, index idx1(a, c), index idx2(b, c)); +insert into t values(1, 1, 1), (1, 2, -1), (2, 1, -2); +begin; +insert into t values(1, 1, -3); +explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; +id estRows task access object operator info +Projection_8 2.00 root executor__index_merge_reader.t.a, executor__index_merge_reader.t.b, executor__index_merge_reader.t.c +└─Limit_15 2.00 root offset:0, count:2 + └─UnionScan_21 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + └─IndexMerge_25 2.00 root type: union + ├─IndexRangeScan_22(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, stats:pseudo + ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan_24(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; +a b c +1 1 -3 +2 1 -2 +rollback; +begin; +insert into t values(1, 2, 4); +explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; +id estRows task access object operator info +Projection_8 2.00 root executor__index_merge_reader.t.a, executor__index_merge_reader.t.b, executor__index_merge_reader.t.c +└─Limit_15 2.00 root offset:0, count:2 + └─UnionScan_21 2.00 root or(eq(executor__index_merge_reader.t.a, 1), eq(executor__index_merge_reader.t.b, 1)) + └─IndexMerge_25 2.00 root type: union + ├─IndexRangeScan_22(Build) 1.00 cop[tikv] table:t, index:idx1(a, c) range:[1,1], keep order:true, desc, stats:pseudo + ├─IndexRangeScan_23(Build) 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, desc, stats:pseudo + └─TableRowIDScan_24(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; +a b c +1 2 4 +1 1 1 +rollback; diff --git a/tests/integrationtest/r/executor/password_management.result b/tests/integrationtest/r/executor/password_management.result new file mode 100644 index 0000000000000..9d47b8c42f030 --- /dev/null +++ b/tests/integrationtest/r/executor/password_management.result @@ -0,0 +1,692 @@ +drop user if EXISTS testuser, testuser1, testuser2, testuser3, testuser4; +drop role if EXISTS role1; +CREATE USER testuser; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +N NULL +CREATE USER testuser1 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +Y NULL +CREATE USER testuser2 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +N NULL +CREATE USER testuser3 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +N 0 +CREATE USER testuser4 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +N 3 +CREATE ROLE role1; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +Y NULL +ALTER USER testuser PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +N 0 +ALTER USER testuser PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +N NULL +ALTER USER testuser PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +N 3 +ALTER USER testuser PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +Y 3 +ALTER USER testuser IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +Y 3 +ALTER USER testuser IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +N 3 +ALTER USER testuser IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +N 3 +ALTER USER testuser1 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +Y 0 +ALTER USER testuser1 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +Y NULL +ALTER USER testuser1 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +Y 3 +ALTER USER testuser1 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +Y 3 +ALTER USER testuser1 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +Y 3 +ALTER USER testuser1 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +N 3 +ALTER USER testuser1 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +password_expired password_lifetime +N 3 +ALTER USER testuser2 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +N 0 +ALTER USER testuser2 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +N NULL +ALTER USER testuser2 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +N 3 +ALTER USER testuser2 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +Y 3 +ALTER USER testuser2 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +Y 3 +ALTER USER testuser2 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +N 3 +ALTER USER testuser2 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +password_expired password_lifetime +N 3 +ALTER USER testuser3 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +N 0 +ALTER USER testuser3 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +N NULL +ALTER USER testuser3 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +N 3 +ALTER USER testuser3 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +Y 3 +ALTER USER testuser3 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +Y 3 +ALTER USER testuser3 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +N 3 +ALTER USER testuser3 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +password_expired password_lifetime +N 3 +ALTER USER testuser4 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +N 0 +ALTER USER testuser4 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +N NULL +ALTER USER testuser4 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +N 3 +ALTER USER testuser4 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +Y 3 +ALTER USER testuser4 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +Y 3 +ALTER USER testuser4 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +N 3 +ALTER USER testuser4 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +password_expired password_lifetime +N 3 +ALTER USER role1 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +Y 0 +ALTER USER role1 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +Y NULL +ALTER USER role1 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +Y 3 +ALTER USER role1 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +Y 3 +ALTER USER role1 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +Y 3 +ALTER USER role1 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +N 3 +ALTER USER role1 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +password_expired password_lifetime +N 3 +ALTER USER testuser PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +Y 3 +SET PASSWORD FOR testuser = '1234'; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +password_expired password_lifetime +N 3 +drop user if EXISTS ''@localhost; +CREATE USER ''@localhost IDENTIFIED BY 'pass' PASSWORD EXPIRE; +Error 3016 (HY000): The password for anonymous user cannot be expired. +CREATE USER ''@localhost IDENTIFIED BY 'pass'; +ALTER USER ''@localhost PASSWORD EXPIRE; +Error 3016 (HY000): The password for anonymous user cannot be expired. +DROP USER IF EXISTS 'u1'@'localhost'; +CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password'; +ALTER USER 'u1'@'localhost' IDENTIFIED BY 'pass'; +ALTER USER 'u1'@'localhost' PASSWORD EXPIRE; +SELECT password_expired FROM mysql.user WHERE user = 'u1' and host = 'localhost'; +password_expired +Y +DROP USER IF EXISTS 'u1'@'localhost'; +CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'caching_sha2_password'; +ALTER USER 'u1'@'localhost' IDENTIFIED BY 'pass'; +ALTER USER 'u1'@'localhost' PASSWORD EXPIRE; +SELECT password_expired FROM mysql.user WHERE user = 'u1' and host = 'localhost'; +password_expired +Y +DROP USER IF EXISTS 'u1'@'localhost'; +CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'tidb_sm3_password'; +ALTER USER 'u1'@'localhost' IDENTIFIED BY 'pass'; +ALTER USER 'u1'@'localhost' PASSWORD EXPIRE; +SELECT password_expired FROM mysql.user WHERE user = 'u1' and host = 'localhost'; +password_expired +Y +drop user 'u1'@'localhost'; +show variables like "password_history"; +Variable_name Value +password_history 0 +show variables like "password_reuse_interval"; +Variable_name Value +password_reuse_interval 0 +set global password_history = -1; +set global password_reuse_interval = -1; +show variables like "password_history"; +Variable_name Value +password_history 0 +show variables like "password_reuse_interval"; +Variable_name Value +password_reuse_interval 0 +set global password_history = 4294967295; +set global password_reuse_interval = 4294967295; +show variables like "password_history"; +Variable_name Value +password_history 4294967295 +show variables like "password_reuse_interval"; +Variable_name Value +password_reuse_interval 4294967295 +set global password_history = 4294967296; +set global password_reuse_interval = 4294967296; +show variables like "password_history"; +Variable_name Value +password_history 4294967295 +show variables like "password_reuse_interval"; +Variable_name Value +password_reuse_interval 4294967295 +set session password_history = 42949; +Error 1229 (HY000): Variable 'password_history' is a GLOBAL variable and should be set with SET GLOBAL +set session password_reuse_interval = 42949; +Error 1229 (HY000): Variable 'password_reuse_interval' is a GLOBAL variable and should be set with SET GLOBAL +set global password_history = DEFAULT; +set global password_reuse_interval = DEFAULT; +drop user if EXISTS testReuse; +CREATE USER testReuse; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +NULL NULL +ALTER USER testReuse PASSWORD HISTORY 5; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +5 NULL +ALTER USER testReuse PASSWORD HISTORY 0; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +0 NULL +ALTER USER testReuse PASSWORD HISTORY DEFAULT; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +NULL NULL +ALTER USER testReuse PASSWORD HISTORY 65536; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +65535 NULL +ALTER USER testReuse PASSWORD REUSE INTERVAL 5 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +65535 5 +ALTER USER testReuse PASSWORD REUSE INTERVAL 0 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +65535 0 +ALTER USER testReuse PASSWORD REUSE INTERVAL DEFAULT; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +65535 NULL +ALTER USER testReuse PASSWORD REUSE INTERVAL 65536 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +65535 65535 +ALTER USER testReuse PASSWORD HISTORY 6 PASSWORD REUSE INTERVAL 6 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +6 6 +ALTER USER testReuse PASSWORD HISTORY 6 PASSWORD HISTORY 7 ; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +7 6 +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 5; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +5 NULL +drop USER testReuse; +CREATE USER testReuse PASSWORD REUSE INTERVAL 5 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +NULL 5 +drop USER testReuse; +CREATE USER testReuse PASSWORD REUSE INTERVAL 5 DAY PASSWORD REUSE INTERVAL 6 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +NULL 6 +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 6 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +5 6 +drop USER testReuse; +CREATE USER testReuse PASSWORD REUSE INTERVAL 6 DAY PASSWORD HISTORY 5; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +5 6 +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY -5; +[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 40 near "-5;" +CREATE USER testReuse PASSWORD REUSE INTERVAL -6 DAY; +[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 47 near "-6 DAY;" +CREATE USER testReuse PASSWORD HISTORY 65535 PASSWORD REUSE INTERVAL 65535 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +65535 65535 +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 65536 PASSWORD REUSE INTERVAL 65536 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +65535 65535 +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +NULL NULL +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 0 PASSWORD REUSE INTERVAL 0 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +Password_reuse_history Password_reuse_time +0 0 +drop user if EXISTS testReuse; +CREATE USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +set global password_history = 1; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test1'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +DROP USER testReuse; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +set global password_history = 0; +set global password_reuse_interval = 1; +CREATE USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +alter USER testReuse identified by 'test1'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +2 +alter USER testReuse identified by 'test2'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +3 +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +4 +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '1 0:0:1' DAY_SECOND); +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +drop USER testReuse ; +set global password_reuse_interval = 0; +CREATE USER testReuse PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 6 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +drop USER testReuse ; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +4 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +alter USER testReuse identified by 'test4'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +5 +alter USER testReuse identified by 'test5'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +5 +alter USER testReuse identified by 'test1'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +5 +drop USER testReuse; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +alter USER testReuse identified by 'test4'; +alter USER testReuse identified by 'test5'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +6 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '3 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +6 +drop USER testReuse; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '3 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +4 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +ALTER USER testReuse PASSWORD HISTORY 3; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +4 +drop USER testReuse; +set global password_history = 1; +set global password_reuse_interval = 1; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 0 PASSWORD REUSE INTERVAL 0 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +drop USER testReuse; +set global password_history = 0; +set global password_reuse_interval = 360000000; +CREATE USER testReuse identified by 'test'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +set PASSWORD FOR testReuse = 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +alter USER testReuse identified by ''; +alter USER testReuse identified by ''; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +2 +alter USER testReuse identified by 'test2'; +set global password_reuse_interval = 4294967295; +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +4 +set PASSWORD FOR testReuse = 'test4'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +5 +drop USER testReuse; +set global password_reuse_interval = 0; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5; +alter USER testReuse identified by 'test1'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +2 +alter USER testReuse identified by 'test1' PASSWORD HISTORY 0; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +alter USER testReuse identified by 'test1' PASSWORD HISTORY 2 PASSWORD REUSE INTERVAL 1 DAY; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +alter USER testReuse identified by 'test1' PASSWORD HISTORY 2 PASSWORD REUSE INTERVAL 0 DAY; +drop USER testReuse; +set global password_history = 1; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +ALTER USER testReuse identified by 'test' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +ALTER USER testReuse identified by 'test1' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +set global password_history = DEFAULT; +set global password_reuse_interval = DEFAULT; +drop user if EXISTS testReuse; +CREATE USER testReuse identified with 'caching_sha2_password' by 'test' PASSWORD HISTORY 1 ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +set password for testReuse = 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +alter USER testReuse identified by 'test1'; +alter USER testReuse identified with 'tidb_sm3_password'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +drop USER testReuse; +CREATE USER testReuse identified with 'tidb_sm3_password' by 'test' PASSWORD HISTORY 1 ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +set password for testReuse = 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +alter USER testReuse identified by 'test1'; +alter USER testReuse identified with 'caching_sha2_password'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +drop USER testReuse; +CREATE USER testReuse identified with 'caching_sha2_password' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +set password for testReuse = 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '1 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1; +alter USER testReuse identified by 'test'; +drop USER testReuse; +CREATE USER testReuse identified with 'mysql_clear_password' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +Error 1524 (HY000): Plugin 'mysql_clear_password' is not loaded +CREATE USER testReuse identified with 'tidb_session_token' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +Error 1524 (HY000): Plugin 'tidb_session_token' is not loaded +CREATE USER testReuse identified with 'auth_socket' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +ALTER USER testReuse identified by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +SELECT authentication_string FROM mysql.user WHERE user = 'testReuse'; +authentication_string + +ALTER USER testReuse identified with 'caching_sha2_password' by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +drop USER testReuse; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +CREATE USER testReuse identified with 'tidb_auth_token' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +ALTER USER testReuse identified by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +set password for testReuse = 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +ALTER USER testReuse identified with 'caching_sha2_password' by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +set password for testReuse = 'test'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +drop USER testReuse; +drop user if EXISTS testReuse, testReuse1, testReuse2, testReuse3; +CREATE USER testReuse identified by 'test', testReuse1 identified by 'test', testReuse2 identified by 'test' PASSWORD HISTORY 65535 PASSWORD REUSE INTERVAL 65535 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'; +Password_reuse_history Password_reuse_time +65535 65535 +65535 65535 +65535 65535 +ALTER USER testReuse identified by 'test1', testReuse1 identified by 'test1', testReuse2 identified by 'test1' PASSWORD HISTORY 3 PASSWORD REUSE INTERVAL 3 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'; +Password_reuse_history Password_reuse_time +3 3 +3 3 +3 3 +SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' group by user; +count(*) +2 +2 +2 +CREATE USER testReuse3 identified by 'test'; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'; +Password_reuse_history Password_reuse_time +3 3 +3 3 +3 3 +NULL NULL +SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' group by user; +count(*) +2 +2 +2 +ALTER USER testReuse identified by 'test1', testReuse3 identified by 'test1'; +Error 3638 (HY000): Cannot use these credentials for 'testReuse@%' because they contradict the password history policy. +drop User testReuse, testReuse1, testReuse2, testReuse3; +SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' ; +count(*) +0 +drop user if EXISTS testReuse, testReuse1; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +1 +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +4 +rename USER testReuse to testReuse1; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +count(*) +0 +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse1'; +count(*) +4 +drop user if EXISTS test1; +CREATE USER test1 IDENTIFIED WITH 'mysql_native_password' BY '1234'; +ALTER USER 'test1' IDENTIFIED BY '222', 'test_not_exist'@'localhost' IDENTIFIED BY '111'; +Error 1396 (HY000): Operation ALTER USER failed for 'test_not_exist'@'localhost' +SELECT authentication_string FROM mysql.User WHERE User="test1" and Host="%"; +authentication_string +*A4B6157319038724E3560894F7F932C8886EBFCF +ALTER USER IF EXISTS 'test1' IDENTIFIED BY '222', 'test_not_exist'@'localhost' IDENTIFIED BY '111'; +show warnings; +Level Code Message +Note 3162 User 'test_not_exist'@'localhost' does not exist. +SELECT authentication_string FROM mysql.User WHERE User="test1" and Host="%"; +authentication_string +*899ECD04E40F745BD52A4C552BE4A818AC65FAF8 diff --git a/tests/integrationtest/r/executor/prepared.result b/tests/integrationtest/r/executor/prepared.result index fc2ccce32e8a1..3d1dd0167494e 100644 --- a/tests/integrationtest/r/executor/prepared.result +++ b/tests/integrationtest/r/executor/prepared.result @@ -315,3 +315,57 @@ set @@tidb_txn_mode = 'optimistic'; prepare stmt1 from 'do 1'; set tidb_enable_prepared_plan_cache=default; set @@tidb_txn_mode=default; +drop table if exists t; +create table t(a int, key(a)); +prepare stmt from 'select * from t limit ?'; +set @a = 1.2; +execute stmt using @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +set @a = 1.; +execute stmt using @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +set @a = '0'; +execute stmt using @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +set @a = '1'; +execute stmt using @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +set @a = 1_2; +execute stmt using @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +drop table if exists t; +create table t(id int, k int); +prepare stmt from 'explain select * from t where id = ? and k = ? group by id, k'; +show warnings; +Level Code Message +Warning 1105 skip prepared plan-cache: not a SELECT/UPDATE/INSERT/DELETE/SET statement +set @a = 1; +execute stmt using @a, @a; +id estRows task access object operator info +HashAgg_8 1.00 root group by:executor__prepared.t.id, executor__prepared.t.k, funcs:firstrow(executor__prepared.t.id)->executor__prepared.t.id, funcs:firstrow(executor__prepared.t.k)->executor__prepared.t.k +└─TableReader_15 0.01 root data:Selection_14 + └─Selection_14 0.01 cop[tikv] eq(executor__prepared.t.id, 1), eq(executor__prepared.t.k, 1) + └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain select * from t where id = 1 and k = 1 group by id, k; +id estRows task access object operator info +HashAgg_8 1.00 root group by:executor__prepared.t.id, executor__prepared.t.k, funcs:firstrow(executor__prepared.t.id)->executor__prepared.t.id, funcs:firstrow(executor__prepared.t.k)->executor__prepared.t.k +└─TableReader_15 0.01 root data:Selection_14 + └─Selection_14 0.01 cop[tikv] eq(executor__prepared.t.id, 1), eq(executor__prepared.t.k, 1) + └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +prepare stmt from 'explain select * from t where ? = id and ? = k group by id, k'; +show warnings; +Level Code Message +Warning 1105 skip prepared plan-cache: not a SELECT/UPDATE/INSERT/DELETE/SET statement +set @a = 1; +execute stmt using @a, @a; +id estRows task access object operator info +HashAgg_8 1.00 root group by:executor__prepared.t.id, executor__prepared.t.k, funcs:firstrow(executor__prepared.t.id)->executor__prepared.t.id, funcs:firstrow(executor__prepared.t.k)->executor__prepared.t.k +└─TableReader_15 0.01 root data:Selection_14 + └─Selection_14 0.01 cop[tikv] eq(1, executor__prepared.t.id), eq(1, executor__prepared.t.k) + └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain select * from t where 1 = id and 1 = k group by id, k; +id estRows task access object operator info +HashAgg_8 1.00 root group by:executor__prepared.t.id, executor__prepared.t.k, funcs:firstrow(executor__prepared.t.id)->executor__prepared.t.id, funcs:firstrow(executor__prepared.t.k)->executor__prepared.t.k +└─TableReader_15 0.01 root data:Selection_14 + └─Selection_14 0.01 cop[tikv] eq(1, executor__prepared.t.id), eq(1, executor__prepared.t.k) + └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo diff --git a/tests/integrationtest/t/black_list.test b/tests/integrationtest/t/black_list.test index 70fe4bab1cd3c..753cef95d896d 100644 --- a/tests/integrationtest/t/black_list.test +++ b/tests/integrationtest/t/black_list.test @@ -43,3 +43,36 @@ explain format = 'brief' select * from t where a < 1; delete from mysql.expr_pushdown_blacklist; admin reload expr_pushdown_blacklist; + +# TestExprBlackListForEnum +drop table if exists t; +create table t(a enum('a','b','c'), b enum('a','b','c'), c int, index idx(b,a)); +insert into t values(1,1,1),(2,2,2),(3,3,3); +insert into mysql.expr_pushdown_blacklist(name) values('enum'); +admin reload expr_pushdown_blacklist; +desc format='brief' select /*+ HASH_AGG() */ max(a) from t; +desc format='brief' select /*+ STREAM_AGG() */ max(a) from t; +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; +desc format='brief' select /*+ HASH_AGG() */ max(a) from t; +desc format='brief' select /*+ STREAM_AGG() */ max(a) from t; +insert into mysql.expr_pushdown_blacklist(name) values('enum'); +admin reload expr_pushdown_blacklist; +desc format='brief' select * from t where a + b; +desc format='brief' select * from t where a + b; +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; +desc format='brief' select * from t where a + b; +desc format='brief' select * from t where a + b; +insert into mysql.expr_pushdown_blacklist(name) values('enum'); +admin reload expr_pushdown_blacklist; +desc format='brief' select * from t where b = 1; +desc format='brief' select * from t where b = 'a'; +desc format='brief' select * from t where b > 1; +desc format='brief' select * from t where b > 'a'; +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; +desc format='brief' select * from t where b = 1 and a = 1; +desc format='brief' select * from t where b = 'a' and a = 'a'; +desc format='brief' select * from t where b = 1 and a > 1; +desc format='brief' select * from t where b = 1 and a > 'a'; diff --git a/tests/integrationtest/t/executor/executor.test b/tests/integrationtest/t/executor/executor.test index 26b073c81556f..9175b30e271a8 100644 --- a/tests/integrationtest/t/executor/executor.test +++ b/tests/integrationtest/t/executor/executor.test @@ -1846,3 +1846,694 @@ select b < a from t; select b = a from t; select b > a from t; select c > a from t; + +# TestLoadStats +-- error 1064 +load stats; +-- error 1064 +load stats ./xxx.json; + +# TestShow +drop database if exists test_show; +create database test_show; +use test_show; +show engines; +drop table if exists t; +create table t(a int primary key); +show index in t; +show index from t; +--replace_column 2 0 +show master status; +show create database test_show; +show privileges; +--replace_column 12 0 +show table status; + +drop database test_show; +use executor__executor; + +# TestSelectBackslashN +# Issue 3685. +select \N; +select "\N"; + +drop table if exists test; +create table test (`\N` int); +insert into test values (1); +select * from test; +select \N from test; +select (\N) from test; +select `\N` from test; +select (`\N`) from test; +select '\N' from test; +select ('\N') from test; + +# TestSelectNull +# Issue #4053. +select nUll; +select (null); +select null+NULL; + +# TestSelectStringLiteral Issue #3686. +select 'abc'; +select (('abc')); +select 'abc'+'def'; +## Below checks whether leading invalid chars are trimmed. +select '\n'; +## Lowercased letter is a valid char. +select '\t col'; +## Uppercased letter is a valid char. +select '\t Col'; +## Chinese char is a valid char. +select '\n\t 中文 col'; +## Punctuation is a valid char. +select ' \r\n .col'; +## Emoji is a valid char. +select ' 😆col'; +## Below checks whether trailing invalid chars are preserved. +select 'abc '; +select ' abc 123 '; +## Issue #4239. +select 'a' ' ' 'string'; +select 'a' " " "string"; +select 'string' 'string'; +select "ss" "a"; +select "ss" "a" "b"; +select "ss" "a" ' ' "b"; +select "ss" "a" ' ' "b" ' ' "d"; + +# TestUpdateClustered +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) ); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) , key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.v = 20, b.v = 100, a.k1 = a.k1 + 1, b.k1 = b.k1 + 1, a.k2 = a.k2 + 2, b.k2 = b.k2 + 2; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 int, k2 int, v int); +create table b (a int not null, k1 int, k2 int, v int, primary key(k1, k2) clustered); +insert into a values (1, 1, 1), (2, 2, 2); +insert into b values (2, 2, 2, 2); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a left join b on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b right join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update b join a on a.k1 = b.k1 and a.k2 = b.k2 set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, b.k1 = b.k1 + 1, b.k2 = b.k2 + 2, a.v = 20, b.v = 100; +select * from b; +select * from a; +admin check table a; +admin check table b; +drop table if exists a, b; +create table a (k1 varchar(100), k2 varchar(100), v varchar(100)); +create table b (a varchar(100) not null, k1 varchar(100), k2 varchar(100), v varchar(100), primary key(k1(1), k2(1)) clustered, key kk1(k1(1), v(1))); +insert into a values ('11', '11', '11'), ('22', '22', '22'); +insert into b values ('22', '22', '22', '22'); +update a set a.k1 = a.k1 + 1, a.k2 = a.k2 + 2, a.v = 20 where exists (select 1 from b where a.k1 = b.k1 and a.k2 = b.k2); +select * from b; +select * from a; +admin check table a; +admin check table b; + +# TestClusterIndexOuterJoinElimination +set @@tidb_enable_clustered_index=On; +drop table if exists t; +create table t (a int, b int, c int, primary key(a,b)); +explain format = 'brief' select t1.a from t t1 left join t t2 on t1.a = t2.a and t1.b = t2.b; +set @@tidb_enable_clustered_index=default; + +# TestExecutorBit +drop table if exists t; +create table t (c1 bit(2)); +insert into t values (0), (1), (2), (3); +-- error 1406 +insert into t values (4); +-- error 1406 +insert into t values ('a'); +select hex(c1) from t where c1 = 2; +drop table if exists t; +create table t (c1 bit(31)); +insert into t values (0x7fffffff); +-- error 1406 +insert into t values (0x80000000); +-- error 1406 +insert into t values (0xffffffff); +insert into t values ('123'); +insert into t values ('1234'); +-- error 1064 +insert into t values ('12345); +drop table if exists t; +create table t (c1 bit(62)); +insert into t values ('12345678'); +drop table if exists t; +create table t (c1 bit(61)); +-- error 1406 +insert into t values ('12345678'); +drop table if exists t; +create table t (c1 bit(32)); +insert into t values (0x7fffffff); +insert into t values (0xffffffff); +-- error 1406 +insert into t values (0x1ffffffff); +insert into t values ('1234'); +-- error 1406 +insert into t values ('12345'); +drop table if exists t; +create table t (c1 bit(64)); +insert into t values (0xffffffffffffffff); +insert into t values ('12345678'); +-- error 1366 +insert into t values ('123456789'); +drop table if exists t; +create table t (c1 bit(64)); +insert into t values (0xffffffffffffffff); +insert into t values ('12345678'); +select hex(c1) from t where c1; + +# TestTimestampTimeZone +drop table if exists t, t1; +create table t (ts timestamp); +set time_zone = '+00:00'; +insert into t values ('2017-04-27 22:40:42'); +set time_zone = '+10:00'; +select * from t; +set time_zone = '-6:00'; +select * from t; + +## For issue https://github.com/pingcap/tidb/issues/3467 +drop table if exists t1; +CREATE TABLE t1 ( + id bigint(20) NOT NULL AUTO_INCREMENT, + uid int(11) DEFAULT NULL, + datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + ip varchar(128) DEFAULT NULL, +PRIMARY KEY (id), + KEY i_datetime (datetime), + KEY i_userid (uid) +); +INSERT INTO t1 VALUES (123381351,1734,"2014-03-31 08:57:10","127.0.0.1"); +select datetime from t1; +select datetime from t1 where datetime='2014-03-31 08:57:10'; +select * from t1 where datetime='2014-03-31 08:57:10'; + +## For issue https://github.com/pingcap/tidb/issues/3485 +set time_zone = 'Asia/Shanghai'; +drop table if exists t1; +CREATE TABLE t1 ( + id bigint(20) NOT NULL AUTO_INCREMENT, + datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id) +); +INSERT INTO t1 VALUES (123381351,"2014-03-31 08:57:10"); +select * from t1 where datetime="2014-03-31 08:57:10"; +alter table t1 add key i_datetime (datetime); +select * from t1 where datetime="2014-03-31 08:57:10"; +select * from t1; +select datetime from t1 where datetime='2014-03-31 08:57:10'; +set time_zone=default; + +# TestInsertValuesWithSubQuery +# this is from jira issue #5856 +drop table if exists t2; +create table t2(a int, b int, c int); +-- error 1054 +insert into t2 values (11, 8, (select not b)); +-- error 1064 +insert into t2 set a = 11, b = 8, c = (select b)); +insert into t2 values(1, 1, (select b from t2)); +select * from t2; +insert into t2 set a = 1, b = 1, c = (select b+1 from t2); +select * from t2; +delete from t2; +insert into t2 values(2, 4, a); +select * from t2; +insert into t2 set a = 3, b = 5, c = b; +select * from t2; + +## issue #30626 +drop table if exists t; +create table t(a int, b int); +## TODO: should insert success and get (81,1) from the table +-- error 1105 +insert into t values ( 81, ( select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ) ); +-- error 1105 +insert into t set a = 81, b = (select ( SELECT '1' AS `c0` WHERE '1' >= `subq_0`.`c0` ) as `c1` FROM ( SELECT '1' AS `c0` ) AS `subq_0` ); +drop table if exists t2; + +# TestBitColumnIn +# fix issue https://github.com/pingcap/tidb/issues/32871 +drop table if exists t; +create table t (id bit(16), key id(id)); +insert into t values (65); +select * from t where id not in (-1,2); +-- error 1582 +select * from t where id in (-1, -2); + +# TestProjectionBitType +drop table if exists t; +drop table if exists t1; +create table t(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) clustered); +create table t1(k1 int, v bit(34) DEFAULT b'111010101111001001100111101111111', primary key(k1) nonclustered); +insert into t(k1) select 1; +insert into t1(k1) select 1; +set @@tidb_enable_vectorized_expression = 0; +(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); +(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); +set @@tidb_enable_vectorized_expression = 1; +(select k1, hex(v) from t where false) union(select k1, hex(v) from t for update); +(select k1, hex(v) from t1 where false) union(select k1, hex(v) from t1 for update); + +set @@tidb_enable_vectorized_expression = default; + +# TestIssue24933 +drop table if exists t; +drop view if exists v; +create table t(a int); +insert into t values(1), (2), (3); +create definer='root'@'localhost' view v as select count(*) as c1 from t; +select * from v; +drop view v; +create definer='root'@'localhost' view v as select * from (select count(*) from t) s; +select * from v order by 1; +drop view v; +create definer='root'@'localhost' view v as select * from (select avg(a) from t group by a) s; +select * from v order by 1; +drop view v; +create definer='root'@'localhost' view v as select * from (select sum(a) from t group by a) s; +select * from v order by 1; +drop view v; +create definer='root'@'localhost' view v as select * from (select group_concat(a) from t group by a) s; +select * from v order by 1; +drop view v; +create definer='root'@'localhost' view v as select * from (select count(0) as c1 from t) s; +select * from v order by 1; +drop view v; +create definer='root'@'localhost' view v as select * from (select count(*) as c1 from t) s; +select * from v order by 1; +drop view v; +create definer='root'@'localhost' view v as select * from (select group_concat(a) as `concat(a)` from t group by a) s; +select * from v order by 1; +drop view v; +create definer='root'@'localhost' view v as select * from (select a from t group by a) s; +select * from v order by 1; +-- error 1054 +SELECT `s`.`count(a)` FROM (SELECT COUNT(`a`) FROM `test`.`t`) AS `s`; +drop view v; +create definer='root'@'localhost' view v as select * from (select count(a) from t) s; +select * from v; +drop table if exists t; +create table t(c1 int); +insert into t values(111), (222), (333); +drop view if exists v; +create definer='root'@'localhost' view v as (select * from (select row_number() over (order by c1) from t) s); +select * from v; +drop view if exists v; +create definer='root'@'localhost' view v as (select * from (select c1, row_number() over (order by c1) from t) s); +select * from v; +drop view if exists v; +create definer='root'@'localhost' view v as (select * from (select c1 or 0 from t) s); +select * from v; +select `c1 or 0` from v; +drop view v; + +# TestCTEWithIndexLookupJoinDeadLock +drop table if exists t, t1, t2; +create table t (a int(11) default null,b int(11) default null,key b (b),key ba (b)); +create table t1 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); +create table t2 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b)); + +## It's easy to reproduce this problem in 30 times execution of IndexLookUpJoin. +--disable_result_log +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a; +--enable_result_log + +# TestAdminChecksumOfPartitionedTable +DROP TABLE IF EXISTS admin_checksum_partition_test; +CREATE TABLE admin_checksum_partition_test (a INT) PARTITION BY HASH(a) PARTITIONS 4; +INSERT INTO admin_checksum_partition_test VALUES (1), (2); +## The result is different with TiKV and unistore +--disable_result_log +ADMIN CHECKSUM TABLE admin_checksum_partition_test; +--enable_result_log + +# TestSQLMode +drop table if exists t; +create table t (a tinyint not null); +set sql_mode = 'STRICT_TRANS_TABLES'; +-- error 1364 +insert t values (); +-- error 1264 +insert t values ('1000'); +create table if not exists tdouble (a double(3,2)); +-- error 1264 +insert tdouble values (10.23); +set sql_mode = ''; +insert t values (); +show warnings; +insert t values (null); +show warnings; +insert ignore t values (null); +show warnings; +insert t select null; +show warnings; +insert t values (1000); +select * from t order by a; +insert tdouble values (10.23); +select * from tdouble; +set sql_mode = 'STRICT_TRANS_TABLES'; +set @@global.sql_mode = ''; + +connect (conn1, localhost, root,, executor__executor); +drop table if exists t2; +create table t2 (a varchar(3)); +insert t2 values ('abcd'); +select * from t2; +connection default; +disconnect conn1; + +-- error 1406 +insert t2 values ('abcd'); +set sql_mode = default; +set @@global.sql_mode = default; + +# TestTableScan +use information_schema; +## There must be these tables: information_schema, mysql, performance_schema and test. +select count(*)>=4 from schemata; +create database mytest; +use information_schema; +select * from schemata where schema_name = 'mysql'; +select * from schemata where schema_name like 'my%'; +select 1 from tables limit 1; +use executor__executor; + +# TestAddDateBuiltinWithWarnings +set @@sql_mode='NO_ZERO_DATE'; +select date_add('2001-01-00', interval -2 hour); +show warnings; +set @@sql_mode=default; + +# TestStrToDateBuiltinWithWarnings +set @@sql_mode='NO_ZERO_DATE'; +drop table if exists t1; +SELECT STR_TO_DATE('0000-1-01', '%Y-%m-%d'); +show warnings; +SELECT CAST('4#,8?Q' AS DATE); +show warnings; +CREATE TABLE t1 (c1 INT, c2 TEXT); +INSERT INTO t1 VALUES (1833458842, '0.3503490908550797'); +SELECT CAST(t1.c2 AS DATE) FROM t1; +show warnings; +set @@sql_mode=default; + +# TestUnsignedDecimalOverflow +drop table if exists t; +create table t(a decimal(10,2) unsigned); +-- error 1264 +insert into t values (-1); +-- error 1264 +insert into t values ("-1.1e-1"); +-- error 1264 +insert into t values (-1.1); +insert into t values (-0); +set sql_mode=''; +delete from t; +insert into t values (-1); +select a from t limit 1; +set sql_mode=default; + +# TestDoSubquery +drop table if exists t; +create table t(a int); +do 1 in (select * from t); +insert into t values(1); +do 1 in (select * from t); + +# TestCountDistinctJSON +drop table if exists t; +create table t(j JSON); +insert into t values('2010'); +insert into t values('2011'); +insert into t values('2012'); +insert into t values('2010.000'); +insert into t values(cast(18446744073709551615 as JSON)); +insert into t values(cast(18446744073709551616.000000 as JSON)); +select count(distinct j) from t; + +# TestHashJoinJSON +drop table if exists t; +create table t(id int(11), j JSON, d DOUBLE); +insert into t values(0, '2010', 2010); +insert into t values(1, '2011', 2011); +insert into t values(2, '2012', 2012); +insert into t values(3, cast(18446744073709551615 as JSON), 18446744073709551616.000000); +select /*+inl_hash_join(t2)*/ t1.id, t2.id from t t1 join t t2 on t1.j = t2.d; + +# TestPlanReplayerDumpTPCDS +drop table if exists catalog_sales, store_sales, date_dim; +create table catalog_sales +( + cs_sold_date_sk int , + cs_sold_time_sk int , + cs_ship_date_sk int , + cs_bill_customer_sk int , + cs_bill_cdemo_sk int , + cs_bill_hdemo_sk int , + cs_bill_addr_sk int , + cs_ship_customer_sk int , + cs_ship_cdemo_sk int , + cs_ship_hdemo_sk int , + cs_ship_addr_sk int , + cs_call_center_sk int , + cs_catalog_page_sk int , + cs_ship_mode_sk int , + cs_warehouse_sk int , + cs_item_sk int not null, + cs_promo_sk int , + cs_order_number int not null, + cs_quantity int , + cs_wholesale_cost decimal(7,2) , + cs_list_price decimal(7,2) , + cs_sales_price decimal(7,2) , + cs_ext_discount_amt decimal(7,2) , + cs_ext_sales_price decimal(7,2) , + cs_ext_wholesale_cost decimal(7,2) , + cs_ext_list_price decimal(7,2) , + cs_ext_tax decimal(7,2) , + cs_coupon_amt decimal(7,2) , + cs_ext_ship_cost decimal(7,2) , + cs_net_paid decimal(7,2) , + cs_net_paid_inc_tax decimal(7,2) , + cs_net_paid_inc_ship decimal(7,2) , + cs_net_paid_inc_ship_tax decimal(7,2) , + cs_net_profit decimal(7,2) , + primary key (cs_item_sk, cs_order_number) +); +create table store_sales +( + ss_sold_date_sk int , + ss_sold_time_sk int , + ss_item_sk int not null, + ss_customer_sk int , + ss_cdemo_sk int , + ss_hdemo_sk int , + ss_addr_sk int , + ss_store_sk int , + ss_promo_sk int , + ss_ticket_number int not null, + ss_quantity int , + ss_wholesale_cost decimal(7,2) , + ss_list_price decimal(7,2) , + ss_sales_price decimal(7,2) , + ss_ext_discount_amt decimal(7,2) , + ss_ext_sales_price decimal(7,2) , + ss_ext_wholesale_cost decimal(7,2) , + ss_ext_list_price decimal(7,2) , + ss_ext_tax decimal(7,2) , + ss_coupon_amt decimal(7,2) , + ss_net_paid decimal(7,2) , + ss_net_paid_inc_tax decimal(7,2) , + ss_net_profit decimal(7,2) , + primary key (ss_item_sk, ss_ticket_number) +); +create table date_dim +( + d_date_sk int not null, + d_date_id char(16) not null, + d_date date , + d_month_seq int , + d_week_seq int , + d_quarter_seq int , + d_year int , + d_dow int , + d_moy int , + d_dom int , + d_qoy int , + d_fy_year int , + d_fy_quarter_seq int , + d_fy_week_seq int , + d_day_name char(9) , + d_quarter_name char(6) , + d_holiday char(1) , + d_weekend char(1) , + d_following_holiday char(1) , + d_first_dom int , + d_last_dom int , + d_same_day_ly int , + d_same_day_lq int , + d_current_day char(1) , + d_current_week char(1) , + d_current_month char(1) , + d_current_quarter char(1) , + d_current_year char(1) , + primary key (d_date_sk) +); +--disable_result_log +plan replayer dump explain with ssci as ( +select ss_customer_sk customer_sk + ,ss_item_sk item_sk +from store_sales,date_dim +where ss_sold_date_sk = d_date_sk + and d_month_seq between 1212 and 1212 + 11 +group by ss_customer_sk + ,ss_item_sk), +csci as( + select cs_bill_customer_sk customer_sk + ,cs_item_sk item_sk +from catalog_sales,date_dim +where cs_sold_date_sk = d_date_sk + and d_month_seq between 1212 and 1212 + 11 +group by cs_bill_customer_sk + ,cs_item_sk) + select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only + ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only + ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog +from ssci left join csci on (ssci.customer_sk=csci.customer_sk + and ssci.item_sk = csci.item_sk) +UNION + select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only + ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only + ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog +from ssci right join csci on (ssci.customer_sk=csci.customer_sk + and ssci.item_sk = csci.item_sk) +limit 100; +--enable_result_log + diff --git a/tests/integrationtest/t/executor/index_merge_reader.test b/tests/integrationtest/t/executor/index_merge_reader.test new file mode 100644 index 0000000000000..ed95c7f216e73 --- /dev/null +++ b/tests/integrationtest/t/executor/index_merge_reader.test @@ -0,0 +1,276 @@ +# TestSingleTableRead +drop table if exists t1, t2; +create table t1(id int primary key, a int, b int, c int, d int); +create index t1a on t1(a); +create index t1b on t1(b); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by id; +select /*+ use_index_merge(t1, primary, t1a) */ a from t1 where id < 2 or a > 4 order by a; +select /*+ use_index_merge(t1, primary, t1a) */ sum(a) from t1 where id < 2 or a > 4; +select /*+ use_index_merge(t1, t1a, t1b) */ * from t1 where a < 2 or b > 4 order by a; +select /*+ use_index_merge(t1, t1a, t1b) */ a from t1 where a < 2 or b > 4 order by a; +select /*+ use_index_merge(t1, t1a, t1b) */ sum(a) from t1 where a < 2 or b > 4; + +# TestJoin +drop table if exists t1, t2; +create table t1(id int primary key, a int, b int, c int, d int); +create index t1a on t1(a); +create index t1b on t1(b); +create table t2(id int primary key, a int); +create index t2a on t2(a); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +insert into t2 values(1,1),(5,5); +select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 4; +select /*+ use_index_merge(t1, t1a, t1b) */ sum(t1.a) from t1 join t2 on t1.id = t2.id where t1.a < 2 or t1.b > 5; + +# TestIndexMergeReaderAndGeneratedColumn +drop table if exists t0; +CREATE TABLE t0(c0 INT AS (1), c1 INT PRIMARY KEY); +INSERT INTO t0(c1) VALUES (0); +CREATE INDEX i0 ON t0(c0); +SELECT /*+ USE_INDEX_MERGE(t0, i0, PRIMARY)*/ t0.c0 FROM t0 WHERE t0.c1 OR t0.c0; +SELECT t0.c0 FROM t0 WHERE t0.c1 OR t0.c0; + +# TestIndexMergeReaderIssue25045 +drop table if exists t1; +create table t1(a int primary key, b int, c int, key(b), key(c)); +INSERT INTO t1 VALUES (10, 10, 10), (11, 11, 11); +explain format='brief' select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10); +select /*+ use_index_merge(t1) */ * from t1 where c=10 or (b=10 and a=10); + +# TestIssue16910 +drop table if exists t1, t2, t3; +create table t1 (a int not null, b tinyint not null, index (a), index (b)) partition by range (a) (partition p0 values less than (10),partition p1 values less than (20),partition p2 values less than (30),partition p3 values less than (40),partition p4 values less than MAXVALUE); +insert into t1 values(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (40, 40), (50, 50), (80, 80), (90, 90), (100, 100); +create table t2 (a int not null, b bigint not null, index (a), index (b)) partition by hash(a) partitions 10; +insert into t2 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23); +select /*+ USE_INDEX_MERGE(t1, a, b) */ * from t1 partition (p0) join t2 partition (p1) on t1.a = t2.a where t1.a < 40 or t1.b < 30; + +# TestIndexMergeCausePanic +drop table if exists t; +set @@tidb_enable_index_merge = 1; +create table t (a int, b int, c int, primary key(a), key(b)); +explain format='brief' select /*+ inl_join(t2) */ * from t t1 join t t2 on t1.a = t2.a and t1.c = t2.c where t2.a = 1 or t2.b = 1; +set @@tidb_enable_index_merge = default; + +# TestIndexMergeInTransaction +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk)); +begin; +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10; +explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10; +explain select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where c1 < 10 and c2 < 10 and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < -1 and c2 < 10) and c3 < 10; +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < -1 and c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < -1) and c3 < 10; +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 < 10; +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +commit; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk)); +set tx_isolation = 'READ-COMMITTED'; +begin; +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10; +explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10; +explain select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where c1 < 10 and c2 < 10 and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < -1 and c2 < 10) and c3 < 10; +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c1, c2, c3) */ * from t1 where (c1 < 10 and c2 < 10) and c3 > 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < -1 and c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < -1) and c3 < 10; +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 < 10; +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 10) and c3 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < -1) and c3 < 10; +select /*+ use_index_merge(t1, c2, c3, primary) */ * from t1 where (pk < 10 and c2 < 10) and c3 > 10; +commit; +set tx_isolation = 'REPEATABLE-READ'; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, key(c1), key(c2), key(c3), primary key(pk)); +begin; +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +explain select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c2 < 10) and c3 < 10 for update; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +insert into t1 values(1, 1, 1, 1); +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 10 or c2 < 10) and c3 < 10 for update; +commit; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, pk int, part int, key(c1), key(c2), key(c3), primary key(pk, part)) + partition by range(part) ( + partition p0 values less than (10), + partition p1 values less than (20), + partition p2 values less than (maxvalue)); +begin; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < 20) and c3 < 20; +insert into t1 values(1, 1, 1, 1, 1); +insert into t1 values(11, 11, 11, 11, 11); +insert into t1 values(21, 21, 21, 21, 21); +insert into t1 values(31, 31, 31, 31, 31); +--sorted_result +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20; +--sorted_result +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20; +--sorted_result +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20; +--sorted_result +select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20; +update t1 set c3 = 100 where c3 = 1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20; +delete from t1; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c2 < 20) and c3 < 20; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 20 or c2 < -1) and c3 < 20; +select /*+ use_index_merge(t1) */ * from t1 where (pk < -1 or c2 < 20) and c3 < 20; +select /*+ use_index_merge(t1) */ * from t1 where (pk < 20 or c2 < -1) and c3 < 20; +commit; +set tx_isolation = default; + +# TestIndexMergeReaderInTransIssue30685 +# This is a case generated by sqlgen to test if clustered index is ok. +# Detect the bugs in memIndexMergeReader.getMemRowsHandle(). +drop table if exists t1; +create table t1 (col_30 decimal default 0 , + col_31 char(99) collate utf8_bin default 'sVgzHblmYYtEjVg' not null , + col_37 int unsigned default 377206828 , + primary key idx_16 ( col_37 ) , key idx_19 ( col_31) ) collate utf8mb4_general_ci ; +begin; +insert ignore into t1 values (388021, '', 416235653); +select /*+ use_index_merge( t1 ) */ 1 from t1 where ( t1.col_31 in ( 'OiOXzpCs' , 'oaVv' ) or t1.col_37 <= 4059907010 ) and t1.col_30 ; +commit; +drop table if exists tbl_3; +create table tbl_3 ( col_30 decimal , col_31 char(99) , col_32 smallint , + col_33 tinyint unsigned not null , col_34 char(209) , + col_35 char(110) , col_36 int unsigned , col_37 int unsigned , + col_38 decimal(50,15) not null , col_39 char(104), + primary key ( col_37 ) , unique key ( col_33,col_30,col_36,col_39 ) , + unique key ( col_32,col_35 ) , key ( col_31,col_38 ) , + key ( col_31,col_33,col_32,col_35,col_36 ) , + unique key ( col_38,col_34,col_33,col_31,col_30,col_36,col_35,col_37,col_39 ) , + unique key ( col_39,col_32 ) , unique key ( col_30,col_35,col_31,col_38 ) , + key ( col_38,col_32,col_33 ) ); +begin; +insert ignore into tbl_3 values ( 71,'Fipc',-6676,30,'','FgfK',2464927398,4084082400,5602.5868,'' ); +select /*+ use_index_merge( tbl_3 ) */ 1 from tbl_3 where ( tbl_3.col_37 not in ( 1626615245 , 2433569159 ) or tbl_3.col_38 = 0.06 ) ; +commit; +drop table if exists t1; +create table t1(c1 int, c2 int, c3 int, c4 int, primary key(c1, c2) /*T![clustered_index] CLUSTERED */, key(c3)); +begin; +insert into t1 values(1, 1, 1, 1); +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < 10) and c4 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 10 or c3 < -1) and c4 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < -1 or c3 < -1) and c4 < 10; +commit; +drop table if exists t1; +create table t1(c1 varchar(100), c2 int, c3 int, c4 int, primary key(c1) /*T![clustered_index] CLUSTERED */, key(c3)); +begin; +insert into t1 values('b', 1, 1, 1); +explain select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < 10) and c4 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 <= 'b' or c3 < -1) and c4 < 10; +select /*+ use_index_merge(t1) */ * from t1 where (c1 < 'a' or c3 < -1) and c4 < 10; +commit; + +# TestIndexMergeSplitTable +DROP TABLE IF EXISTS tab2; +CREATE TABLE tab2(pk INTEGER PRIMARY KEY, col0 INTEGER, col1 FLOAT, col2 TEXT, col3 INTEGER, col4 FLOAT, col5 TEXT); +CREATE INDEX idx_tab2_0 ON tab2 (col0 DESC,col3 DESC); +CREATE UNIQUE INDEX idx_tab2_3 ON tab2 (col4,col0 DESC); +CREATE INDEX idx_tab2_4 ON tab2 (col3,col1 DESC); +INSERT INTO tab2 VALUES(0,146,632.63,'shwwd',703,412.47,'xsppr'); +INSERT INTO tab2 VALUES(1,81,536.29,'trhdh',49,726.3,'chuxv'); +INSERT INTO tab2 VALUES(2,311,541.72,'txrvb',493,581.92,'xtrra'); +INSERT INTO tab2 VALUES(3,669,293.27,'vcyum',862,415.14,'nbutk'); +INSERT INTO tab2 VALUES(4,681,49.46,'odzhp',106,324.65,'deudp'); +INSERT INTO tab2 VALUES(5,319,769.65,'aeqln',855,197.9,'apipa'); +INSERT INTO tab2 VALUES(6,610,302.62,'bixap',184,840.31,'vggit'); +INSERT INTO tab2 VALUES(7,253,453.21,'gjccm',107,104.5,'lvunv'); +SPLIT TABLE tab2 BY (5); +SELECT /*+ use_index_merge(tab2) */ pk FROM tab2 WHERE (col4 > 565.89 OR col0 > 68 ) and col0 > 10 order by 1; + +# TestIndexMergeNoOrderLimitPushed +drop table if exists t; +create table t(a int, b int, c int, index idx(a, c), index idx2(b, c)); +insert into t values(1, 1, 1), (2, 2, 2); +explain format='brief' select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1; +select /*+ USE_INDEX_MERGE(t, idx, idx2) */ * from t where a = 1 or b = 1 limit 1; + +# TestIndexMergeKeepOrderDirtyRead +drop table if exists t; +create table t(a int, b int, c int, index idx1(a, c), index idx2(b, c)); +insert into t values(1, 1, 1), (1, 2, -1), (2, 1, -2); +begin; +insert into t values(1, 1, -3); +explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; +select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c limit 2; +rollback; +begin; +insert into t values(1, 2, 4); +explain select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; +select /*+ USE_INDEX_MERGE(t, idx1, idx2) */ * from t where a = 1 or b = 1 order by c desc limit 2; +rollback; + diff --git a/tests/integrationtest/t/executor/password_management.test b/tests/integrationtest/t/executor/password_management.test new file mode 100644 index 0000000000000..8eb12f63c319f --- /dev/null +++ b/tests/integrationtest/t/executor/password_management.test @@ -0,0 +1,427 @@ +# TestPasswordExpiration +drop user if EXISTS testuser, testuser1, testuser2, testuser3, testuser4; +drop role if EXISTS role1; +CREATE USER testuser; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +CREATE USER testuser1 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +CREATE USER testuser2 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +CREATE USER testuser3 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +CREATE USER testuser4 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +CREATE ROLE role1; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER testuser PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +ALTER USER testuser PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +ALTER USER testuser PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +ALTER USER testuser PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +ALTER USER testuser IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +ALTER USER testuser IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +ALTER USER testuser IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +ALTER USER testuser1 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +ALTER USER testuser1 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +ALTER USER testuser1 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +ALTER USER testuser1 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +ALTER USER testuser1 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +ALTER USER testuser1 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +ALTER USER testuser1 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser1'; +ALTER USER testuser2 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +ALTER USER testuser2 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +ALTER USER testuser2 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +ALTER USER testuser2 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +ALTER USER testuser2 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +ALTER USER testuser2 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +ALTER USER testuser2 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser2'; +ALTER USER testuser3 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +ALTER USER testuser3 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +ALTER USER testuser3 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +ALTER USER testuser3 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +ALTER USER testuser3 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +ALTER USER testuser3 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +ALTER USER testuser3 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser3'; +ALTER USER testuser4 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +ALTER USER testuser4 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +ALTER USER testuser4 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +ALTER USER testuser4 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +ALTER USER testuser4 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +ALTER USER testuser4 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +ALTER USER testuser4 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser4'; +ALTER USER role1 PASSWORD EXPIRE NEVER; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER role1 PASSWORD EXPIRE DEFAULT; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER role1 PASSWORD EXPIRE INTERVAL 3 DAY; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER role1 PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER role1 IDENTIFIED BY '' PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER role1 IDENTIFIED WITH 'mysql_native_password' AS ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER role1 IDENTIFIED BY ''; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'role1'; +ALTER USER testuser PASSWORD EXPIRE; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +SET PASSWORD FOR testuser = '1234'; +SELECT password_expired, password_lifetime FROM mysql.user WHERE user = 'testuser'; +drop user if EXISTS ''@localhost; +-- error 3016 +CREATE USER ''@localhost IDENTIFIED BY 'pass' PASSWORD EXPIRE; +CREATE USER ''@localhost IDENTIFIED BY 'pass'; +-- error 3016 +ALTER USER ''@localhost PASSWORD EXPIRE; +DROP USER IF EXISTS 'u1'@'localhost'; +CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password'; +ALTER USER 'u1'@'localhost' IDENTIFIED BY 'pass'; +ALTER USER 'u1'@'localhost' PASSWORD EXPIRE; +SELECT password_expired FROM mysql.user WHERE user = 'u1' and host = 'localhost'; +DROP USER IF EXISTS 'u1'@'localhost'; +CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'caching_sha2_password'; +ALTER USER 'u1'@'localhost' IDENTIFIED BY 'pass'; +ALTER USER 'u1'@'localhost' PASSWORD EXPIRE; +SELECT password_expired FROM mysql.user WHERE user = 'u1' and host = 'localhost'; +DROP USER IF EXISTS 'u1'@'localhost'; +CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'tidb_sm3_password'; +ALTER USER 'u1'@'localhost' IDENTIFIED BY 'pass'; +ALTER USER 'u1'@'localhost' PASSWORD EXPIRE; +SELECT password_expired FROM mysql.user WHERE user = 'u1' and host = 'localhost'; +drop user 'u1'@'localhost'; + +# TestUserReuseControl +show variables like "password_history"; +show variables like "password_reuse_interval"; +set global password_history = -1; +set global password_reuse_interval = -1; +show variables like "password_history"; +show variables like "password_reuse_interval"; +set global password_history = 4294967295; +set global password_reuse_interval = 4294967295; +show variables like "password_history"; +show variables like "password_reuse_interval"; +set global password_history = 4294967296; +set global password_reuse_interval = 4294967296; +show variables like "password_history"; +show variables like "password_reuse_interval"; +-- error 1229 +set session password_history = 42949; +-- error 1229 +set session password_reuse_interval = 42949; + +set global password_history = DEFAULT; +set global password_reuse_interval = DEFAULT; + +# TestUserReuseInfo +drop user if EXISTS testReuse; +CREATE USER testReuse; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD HISTORY 5; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD HISTORY 0; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD HISTORY DEFAULT; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD HISTORY 65536; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD REUSE INTERVAL 5 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD REUSE INTERVAL 0 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD REUSE INTERVAL DEFAULT; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD REUSE INTERVAL 65536 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD HISTORY 6 PASSWORD REUSE INTERVAL 6 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse PASSWORD HISTORY 6 PASSWORD HISTORY 7 ; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 5; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD REUSE INTERVAL 5 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD REUSE INTERVAL 5 DAY PASSWORD REUSE INTERVAL 6 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 6 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD REUSE INTERVAL 6 DAY PASSWORD HISTORY 5; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +-- error 1064 +CREATE USER testReuse PASSWORD HISTORY -5; +-- error 1064 +CREATE USER testReuse PASSWORD REUSE INTERVAL -6 DAY; +CREATE USER testReuse PASSWORD HISTORY 65535 PASSWORD REUSE INTERVAL 65535 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 65536 PASSWORD REUSE INTERVAL 65536 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse PASSWORD HISTORY 0 PASSWORD REUSE INTERVAL 0 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user = 'testReuse'; + +# TestUserReuseFunction +drop user if EXISTS testReuse; +CREATE USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +set global password_history = 1; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test1'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +DROP USER testReuse; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +set global password_history = 0; +set global password_reuse_interval = 1; +CREATE USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +alter USER testReuse identified by 'test1'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test2'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '1 0:0:1' DAY_SECOND); +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse ; +set global password_reuse_interval = 0; +CREATE USER testReuse PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 6 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse ; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +alter USER testReuse identified by 'test4'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test5'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +alter USER testReuse identified by 'test4'; +alter USER testReuse identified by 'test5'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '3 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5 PASSWORD REUSE INTERVAL 3 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '3 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +ALTER USER testReuse PASSWORD HISTORY 3; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +set global password_history = 1; +set global password_reuse_interval = 1; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 0 PASSWORD REUSE INTERVAL 0 DAY; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +set global password_history = 0; +set global password_reuse_interval = 360000000; +CREATE USER testReuse identified by 'test'; +alter USER testReuse identified by 'test1'; +-- error 3638 +alter USER testReuse identified by 'test'; +-- error 3638 +set PASSWORD FOR testReuse = 'test'; +alter USER testReuse identified by ''; +alter USER testReuse identified by ''; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test2'; +set global password_reuse_interval = 4294967295; +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +set PASSWORD FOR testReuse = 'test4'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +set global password_reuse_interval = 0; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5; +alter USER testReuse identified by 'test1'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test1' PASSWORD HISTORY 0; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test1' PASSWORD HISTORY 2 PASSWORD REUSE INTERVAL 1 DAY; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +alter USER testReuse identified by 'test1' PASSWORD HISTORY 2 PASSWORD REUSE INTERVAL 0 DAY; +drop USER testReuse; +set global password_history = 1; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +ALTER USER testReuse identified by 'test' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +ALTER USER testReuse identified by 'test1' PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; + +set global password_history = DEFAULT; +set global password_reuse_interval = DEFAULT; + +# TestUserReuseDifferentAuth +drop user if EXISTS testReuse; +CREATE USER testReuse identified with 'caching_sha2_password' by 'test' PASSWORD HISTORY 1 ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +-- error 3638 +set password for testReuse = 'test'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified with 'tidb_sm3_password'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse identified with 'tidb_sm3_password' by 'test' PASSWORD HISTORY 1 ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +-- error 3638 +set password for testReuse = 'test'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified with 'caching_sha2_password'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +CREATE USER testReuse identified with 'caching_sha2_password' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +-- error 3638 +alter USER testReuse identified by 'test'; +-- error 3638 +set password for testReuse = 'test'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +-- error 3638 +alter USER testReuse identified by 'test'; +update mysql.password_history set Password_timestamp = date_sub(Password_timestamp,interval '1 0:0:1' DAY_SECOND) where user = 'testReuse' order by Password_timestamp asc limit 1; +alter USER testReuse identified by 'test'; +drop USER testReuse; +-- error 1524 +CREATE USER testReuse identified with 'mysql_clear_password' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +-- error 1524 +CREATE USER testReuse identified with 'tidb_session_token' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +CREATE USER testReuse identified with 'auth_socket' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +ALTER USER testReuse identified by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +SELECT authentication_string FROM mysql.user WHERE user = 'testReuse'; +ALTER USER testReuse identified with 'caching_sha2_password' by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +drop USER testReuse; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +CREATE USER testReuse identified with 'tidb_auth_token' by 'test' PASSWORD REUSE INTERVAL 1 DAY; +ALTER USER testReuse identified by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +set password for testReuse = 'test'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +ALTER USER testReuse identified with 'caching_sha2_password' by 'test' ; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +-- error 3638 +alter USER testReuse identified by 'test'; +-- error 3638 +set password for testReuse = 'test'; +drop USER testReuse; + +# TestUserReuseMultiuser +drop user if EXISTS testReuse, testReuse1, testReuse2, testReuse3; +CREATE USER testReuse identified by 'test', testReuse1 identified by 'test', testReuse2 identified by 'test' PASSWORD HISTORY 65535 PASSWORD REUSE INTERVAL 65535 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'; +ALTER USER testReuse identified by 'test1', testReuse1 identified by 'test1', testReuse2 identified by 'test1' PASSWORD HISTORY 3 PASSWORD REUSE INTERVAL 3 DAY; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'; +SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' group by user; +CREATE USER testReuse3 identified by 'test'; +SELECT Password_reuse_history,Password_reuse_time FROM mysql.user WHERE user like 'testReuse%'; +SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' group by user; +-- error 3638 +ALTER USER testReuse identified by 'test1', testReuse3 identified by 'test1'; +drop User testReuse, testReuse1, testReuse2, testReuse3; +SELECT count(*) FROM mysql.password_history WHERE user like 'testReuse%' ; + +# TestUserReuseRename +drop user if EXISTS testReuse, testReuse1; +CREATE USER testReuse identified by 'test' PASSWORD HISTORY 5; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +alter USER testReuse identified by 'test1'; +alter USER testReuse identified by 'test2'; +alter USER testReuse identified by 'test3'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +rename USER testReuse to testReuse1; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse'; +SELECT count(*) FROM mysql.password_history WHERE user = 'testReuse1'; + +# TestUserAlterUser +drop user if EXISTS test1; +CREATE USER test1 IDENTIFIED WITH 'mysql_native_password' BY '1234'; +-- error 1396 +ALTER USER 'test1' IDENTIFIED BY '222', 'test_not_exist'@'localhost' IDENTIFIED BY '111'; +SELECT authentication_string FROM mysql.User WHERE User="test1" and Host="%"; +ALTER USER IF EXISTS 'test1' IDENTIFIED BY '222', 'test_not_exist'@'localhost' IDENTIFIED BY '111'; +show warnings; +SELECT authentication_string FROM mysql.User WHERE User="test1" and Host="%"; + diff --git a/tests/integrationtest/t/executor/prepared.test b/tests/integrationtest/t/executor/prepared.test index 273f1529ee73d..7b3e8b344de7c 100644 --- a/tests/integrationtest/t/executor/prepared.test +++ b/tests/integrationtest/t/executor/prepared.test @@ -230,3 +230,37 @@ prepare stmt1 from 'do 1'; set tidb_enable_prepared_plan_cache=default; set @@tidb_txn_mode=default; +# TestLimitUnsupportedCase +drop table if exists t; +create table t(a int, key(a)); +prepare stmt from 'select * from t limit ?'; +set @a = 1.2; +-- error 1210 +execute stmt using @a; +set @a = 1.; +-- error 1210 +execute stmt using @a; +set @a = '0'; +-- error 1210 +execute stmt using @a; +set @a = '1'; +-- error 1210 +execute stmt using @a; +set @a = 1_2; +-- error 1210 +execute stmt using @a; + +# TestIssue38323 +drop table if exists t; +create table t(id int, k int); +prepare stmt from 'explain select * from t where id = ? and k = ? group by id, k'; +show warnings; +set @a = 1; +execute stmt using @a, @a; +explain select * from t where id = 1 and k = 1 group by id, k; +prepare stmt from 'explain select * from t where ? = id and ? = k group by id, k'; +show warnings; +set @a = 1; +execute stmt using @a, @a; +explain select * from t where 1 = id and 1 = k group by id, k; +