diff --git a/executor/test/jointest/BUILD.bazel b/executor/test/jointest/BUILD.bazel index ef14f6b30089a..9f313448718e3 100644 --- a/executor/test/jointest/BUILD.bazel +++ b/executor/test/jointest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 14, + shard_count = 11, deps = [ "//config", "//meta/autoid", diff --git a/executor/test/jointest/join_test.go b/executor/test/jointest/join_test.go index ed52ca06b2d1f..d0158f811ce4d 100644 --- a/executor/test/jointest/join_test.go +++ b/executor/test/jointest/join_test.go @@ -30,27 +30,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestJoinPanic2(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set sql_mode = 'ONLY_FULL_GROUP_BY'") - tk.MustExec("drop table if exists events") - tk.MustExec("create table events (clock int, source int)") - tk.MustQuery("SELECT * FROM events e JOIN (SELECT MAX(clock) AS clock FROM events e2 GROUP BY e2.source) e3 ON e3.clock=e.clock") - err := tk.ExecToErr("SELECT * FROM events e JOIN (SELECT clock FROM events e2 GROUP BY e2.source) e3 ON e3.clock=e.clock") - require.Error(t, err) - - // Test for PR 18983, use to detect race. - tk.MustExec("use test") - tk.MustExec("drop table if exists tpj1,tpj2;") - tk.MustExec("create table tpj1 (id int, b int, unique index (id));") - tk.MustExec("create table tpj2 (id int, b int, unique index (id));") - tk.MustExec("insert into tpj1 values (1,1);") - tk.MustExec("insert into tpj2 values (1,1);") - tk.MustQuery("select tpj1.b,tpj2.b from tpj1 left join tpj2 on tpj1.id=tpj2.id where tpj1.id=1;").Check(testkit.Rows("1 1")) -} - func TestJoinInDisk(t *testing.T) { origin := config.RestoreFunc() defer origin() @@ -906,38 +885,6 @@ func TestJoinLeak(t *testing.T) { tk.MustExec("set @@tidb_hash_join_concurrency=5") } -func TestSubqueryInJoinOn(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("drop table if exists t2") - tk.MustExec("create table t1 (id int)") - tk.MustExec("create table t2 (id int)") - tk.MustExec("insert into t1 values (1)") - tk.MustExec("insert into t2 values (1)") - - err := tk.ExecToErr("SELECT * FROM t1 JOIN t2 on (t2.id < all (SELECT 1))") - require.Error(t, err) -} - -func TestIssue15850JoinNullValue(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustQuery("SELECT * FROM (select null) v NATURAL LEFT JOIN (select null) v1;").Check(testkit.Rows("")) - require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - - tk.MustExec("drop table if exists t0;") - tk.MustExec("drop view if exists v0;") - tk.MustExec("CREATE TABLE t0(c0 TEXT);") - tk.MustExec("CREATE VIEW v0(c0) AS SELECT NULL;") - tk.MustQuery("SELECT /*+ HASH_JOIN(v0) */ * FROM v0 NATURAL LEFT JOIN t0;").Check(testkit.Rows("")) - require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - tk.MustQuery("SELECT /*+ MERGE_JOIN(v0) */ * FROM v0 NATURAL LEFT JOIN t0;").Check(testkit.Rows("")) - require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount()) -} - func TestNullEmptyAwareSemiJoin(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/executor/test/writetest/BUILD.bazel b/executor/test/writetest/BUILD.bazel index 260a9a05c4e8a..fc1b09d703dfc 100644 --- a/executor/test/writetest/BUILD.bazel +++ b/executor/test/writetest/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "write_test.go", ], flaky = True, - shard_count = 44, + shard_count = 30, deps = [ "//br/pkg/lightning/mydump", "//config", @@ -21,10 +21,8 @@ go_test( "//planner/core", "//session", "//sessionctx", - "//sessionctx/variable", "//sessiontxn", "//store/mockstore", - "//table", "//table/tables", "//testkit", "//types", diff --git a/executor/test/writetest/write_test.go b/executor/test/writetest/write_test.go index 06d7065ef7107..c885952a7210d 100644 --- a/executor/test/writetest/write_test.go +++ b/executor/test/writetest/write_test.go @@ -32,10 +32,8 @@ import ( "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/sessionctx" - "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/sessiontxn" "github.com/pingcap/tidb/store/mockstore" - "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/types" @@ -1686,132 +1684,6 @@ func TestPessimisticDeleteYourWrites(t *testing.T) { session2.MustQuery("select * from x").Check(testkit.Rows("1 2")) } -// TestWriteListPartitionTable1 test for write list partition when the partition expression is simple. -func TestWriteListPartitionTable1(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec("drop table if exists t") - tk.MustExec(`create table t (id int, name varchar(10)) partition by list (id) ( - partition p0 values in (3,5,6,9,17), - partition p1 values in (1,2,10,11,19,20), - partition p2 values in (4,12,13,14,18), - partition p3 values in (7,8,15,16,null) - );`) - - // Test add unique index failed. - tk.MustExec("insert into t values (1, 'a'),(1,'b')") - err := tk.ExecToErr("alter table t add unique index idx (id)") - require.EqualError(t, err, "[kv:1062]Duplicate entry '1' for key 't.idx'") - // Test add unique index success. - tk.MustExec("delete from t where name='b'") - tk.MustExec("alter table t add unique index idx (id)") - - // --------------------------Test insert--------------------------- - // Test insert 1 partition. - tk.MustExec("delete from t") - tk.MustExec("insert into t values (1, 'a'),(2,'b'),(10,'c')") - tk.MustQuery("select * from t partition(p1) order by id").Check(testkit.Rows("1 a", "2 b", "10 c")) - // Test insert multi-partitions. - tk.MustExec("delete from t") - tk.MustExec("insert into t values (1, 'a'),(3,'c'),(4,'e')") - tk.MustQuery("select * from t partition(p0) order by id").Check(testkit.Rows("3 c")) - tk.MustQuery("select * from t partition(p1) order by id").Check(testkit.Rows("1 a")) - tk.MustQuery("select * from t partition(p2) order by id").Check(testkit.Rows("4 e")) - tk.MustQuery("select * from t partition(p3) order by id").Check(testkit.Rows()) - // Test insert on duplicate. - tk.MustExec("insert into t values (1, 'd'), (3,'f'),(5,'g') on duplicate key update name='x'") - tk.MustQuery("select * from t partition(p0) order by id").Check(testkit.Rows("3 x", "5 g")) - tk.MustQuery("select * from t partition(p1) order by id").Check(testkit.Rows("1 x")) - tk.MustQuery("select * from t partition(p2) order by id").Check(testkit.Rows("4 e")) - tk.MustQuery("select * from t partition(p3) order by id").Check(testkit.Rows()) - // Test insert on duplicate error - err = tk.ExecToErr("insert into t values (3, 'a'), (11,'x') on duplicate key update id=id+1") - require.EqualError(t, err, "[kv:1062]Duplicate entry '4' for key 't.idx'") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 x", "3 x", "4 e", "5 g")) - // Test insert ignore with duplicate - tk.MustExec("insert ignore into t values (1, 'b'), (5,'a'),(null,'y')") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1062 Duplicate entry '1' for key 't.idx'", "Warning 1062 Duplicate entry '5' for key 't.idx'")) - tk.MustQuery("select * from t partition(p0) order by id").Check(testkit.Rows("3 x", "5 g")) - tk.MustQuery("select * from t partition(p1) order by id").Check(testkit.Rows("1 x")) - tk.MustQuery("select * from t partition(p2) order by id").Check(testkit.Rows("4 e")) - tk.MustQuery("select * from t partition(p3) order by id").Check(testkit.Rows(" y")) - // Test insert ignore without duplicate - tk.MustExec("insert ignore into t values (15, 'a'),(17,'a')") - tk.MustQuery("select * from t partition(p0,p1,p2) order by id").Check(testkit.Rows("1 x", "3 x", "4 e", "5 g", "17 a")) - tk.MustQuery("select * from t partition(p3) order by id").Check(testkit.Rows(" y", "15 a")) - // Test insert meet no partition error. - err = tk.ExecToErr("insert into t values (100, 'd')") - require.EqualError(t, err, "[table:1526]Table has no partition for value 100") - - // --------------------------Test update--------------------------- - // Test update 1 partition. - tk.MustExec("delete from t") - tk.MustExec("insert into t values (1, 'a'),(2,'b'),(3,'c')") - tk.MustExec("update t set name='b' where id=2;") - tk.MustQuery("select * from t partition(p1)").Check(testkit.Rows("1 a", "2 b")) - tk.MustExec("update t set name='x' where id in (1,2)") - tk.MustQuery("select * from t partition(p1)").Check(testkit.Rows("1 x", "2 x")) - tk.MustExec("update t set name='y' where id < 3") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 y", "2 y", "3 c")) - // Test update meet duplicate error. - err = tk.ExecToErr("update t set id=2 where id = 1") - require.EqualError(t, err, "[kv:1062]Duplicate entry '2' for key 't.idx'") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 y", "2 y", "3 c")) - - // Test update multi-partitions - tk.MustExec("update t set name='z' where id in (1,2,3);") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 z", "2 z", "3 z")) - tk.MustExec("update t set name='a' limit 3") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 a", "2 a", "3 a")) - tk.MustExec("update t set id=id*10 where id in (1,2)") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("3 a", "10 a", "20 a")) - // Test update meet duplicate error. - err = tk.ExecToErr("update t set id=id+17 where id in (3,10)") - require.EqualError(t, err, "[kv:1062]Duplicate entry '20' for key 't.idx'") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("3 a", "10 a", "20 a")) - // Test update meet no partition error. - err = tk.ExecToErr("update t set id=id*2 where id in (3,20)") - require.EqualError(t, err, "[table:1526]Table has no partition for value 40") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("3 a", "10 a", "20 a")) - - // --------------------------Test replace--------------------------- - // Test replace 1 partition. - tk.MustExec("delete from t") - tk.MustExec("replace into t values (1, 'a'),(2,'b')") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 a", "2 b")) - // Test replace multi-partitions. - tk.MustExec("replace into t values (3, 'c'),(4,'d'),(7,'f')") - tk.MustQuery("select * from t partition(p0) order by id").Check(testkit.Rows("3 c")) - tk.MustQuery("select * from t partition(p1) order by id").Check(testkit.Rows("1 a", "2 b")) - tk.MustQuery("select * from t partition(p2) order by id").Check(testkit.Rows("4 d")) - tk.MustQuery("select * from t partition(p3) order by id").Check(testkit.Rows("7 f")) - // Test replace on duplicate. - tk.MustExec("replace into t values (1, 'x'),(7,'x')") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 x", "2 b", "3 c", "4 d", "7 x")) - // Test replace meet no partition error. - err = tk.ExecToErr("replace into t values (10,'x'),(50,'x')") - require.EqualError(t, err, "[table:1526]Table has no partition for value 50") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 x", "2 b", "3 c", "4 d", "7 x")) - - // --------------------------Test delete--------------------------- - // Test delete 1 partition. - tk.MustExec("delete from t where id = 3") - tk.MustQuery("select * from t partition(p0) order by id").Check(testkit.Rows()) - tk.MustExec("delete from t where id in (1,2)") - tk.MustQuery("select * from t partition(p1) order by id").Check(testkit.Rows()) - // Test delete multi-partitions. - tk.MustExec("delete from t where id in (4,7,10,11)") - tk.MustQuery("select * from t").Check(testkit.Rows()) - tk.MustExec("insert into t values (3, 'c'),(4,'d'),(7,'f')") - tk.MustExec("delete from t where id < 10") - tk.MustQuery("select * from t").Check(testkit.Rows()) - tk.MustExec("insert into t values (3, 'c'),(4,'d'),(7,'f')") - tk.MustExec("delete from t limit 3") - tk.MustQuery("select * from t").Check(testkit.Rows()) -} - // TestWriteListPartitionTable2 test for write list partition when the partition expression is complicated and contain generated column. func TestWriteListPartitionTable2(t *testing.T) { failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`) @@ -2058,158 +1930,6 @@ func TestWriteListColumnsPartitionTable1(t *testing.T) { tk.MustQuery("select * from t").Check(testkit.Rows()) } -// TestWriteListColumnsPartitionTable2 test for write list partition when the partition by multi-columns. -func TestWriteListColumnsPartitionTable2(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec("drop table if exists t") - tk.MustExec(`create table t (location varchar(10), id int, a int) partition by list columns (location,id) ( - partition p_west values in (('w', 1),('w', 2),('w', 3),('w', 4)), - partition p_east values in (('e', 5),('e', 6),('e', 7),('e', 8)), - partition p_north values in (('n', 9),('n',10),('n',11),('n',12)), - partition p_south values in (('s',13),('s',14),('s',15),('s',16)) - );`) - - // Test add unique index failed. - tk.MustExec("insert into t values ('w', 1, 1),('w', 1, 2)") - err := tk.ExecToErr("alter table t add unique index idx (location,id)") - require.EqualError(t, err, "[kv:1062]Duplicate entry 'w-1' for key 't.idx'") - // Test add unique index success. - tk.MustExec("delete from t where a=2") - tk.MustExec("alter table t add unique index idx (location,id)") - - // --------------------------Test insert--------------------------- - // Test insert 1 partition. - tk.MustExec("delete from t") - tk.MustExec("insert into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3)") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 1", "w 2 2", "w 3 3")) - // Test insert multi-partitions. - tk.MustExec("delete from t") - tk.MustExec("insert into t values ('w', 1, 1),('e', 5, 5),('n', 9, 9)") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 1")) - tk.MustQuery("select * from t partition(p_east) order by id").Check(testkit.Rows("e 5 5")) - tk.MustQuery("select * from t partition(p_north) order by id").Check(testkit.Rows("n 9 9")) - tk.MustQuery("select * from t partition(p_south) order by id").Check(testkit.Rows()) - // Test insert on duplicate. - tk.MustExec("insert into t values ('w', 1, 1) on duplicate key update a=a+1") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 2")) - // Test insert on duplicate and move from partition 1 to partition 2 - tk.MustExec("insert into t values ('w', 1, 1) on duplicate key update location='s', id=13") - tk.MustQuery("select * from t partition(p_south) order by id").Check(testkit.Rows("s 13 2")) - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows()) - // Test insert on duplicate error - tk.MustExec("insert into t values ('w', 2, 2), ('w', 1, 1)") - tk.MustGetErrMsg("insert into t values ('w', 2, 3) on duplicate key update id=1", "[kv:1062]Duplicate entry 'w-1' for key 't.idx'") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 1", "w 2 2")) - // Test insert ignore with duplicate - tk.MustExec("insert ignore into t values ('w', 2, 2), ('w', 3, 3), ('n', 10, 10)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1062 Duplicate entry 'w-2' for key 't.idx'")) - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 1", "w 2 2", "w 3 3")) - tk.MustQuery("select * from t partition(p_north) order by id").Check(testkit.Rows("n 9 9", "n 10 10")) - // Test insert ignore without duplicate - tk.MustExec("insert ignore into t values ('w', 4, 4), ('s', 14, 14)") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 1", "w 2 2", "w 3 3", "w 4 4")) - tk.MustQuery("select * from t partition(p_south) order by id").Check(testkit.Rows("s 13 2", "s 14 14")) - // Test insert meet no partition error. - tk.MustGetErrMsg("insert into t values ('w', 5, 5)", "[table:1526]Table has no partition for value from column_list") - tk.MustGetErrMsg("insert into t values ('s', 5, 5)", "[table:1526]Table has no partition for value from column_list") - tk.MustGetErrMsg("insert into t values ('s', 100, 5)", "[table:1526]Table has no partition for value from column_list") - tk.MustGetErrMsg("insert into t values ('x', 1, 5)", "[table:1526]Table has no partition for value from column_list") - - // --------------------------Test update--------------------------- - // Test update 1 partition. - tk.MustExec("delete from t") - tk.MustExec("insert into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3)") - tk.MustExec("update t set a=2 where a=1") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 2", "w 2 2", "w 3 3")) - tk.MustExec("update t set a=3 where location='w'") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 3", "w 2 3", "w 3 3")) - tk.MustExec("update t set a=4 where location='w' and id=1") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 4", "w 2 3", "w 3 3")) - tk.MustExec("update t set a=5 where id=1") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 5", "w 2 3", "w 3 3")) - tk.MustExec("update t set a=a+id where id>1") - tk.MustQuery("select * from t partition(p_west) order by id,a").Check(testkit.Rows("w 1 5", "w 2 5", "w 3 6")) - // Test update meet duplicate error. - err = tk.ExecToErr("update t set id=id+1 where location='w' and id<2") - require.EqualError(t, err, "[kv:1062]Duplicate entry 'w-2' for key 't.idx'") - tk.MustQuery("select * from t partition(p_west) order by id,a").Check(testkit.Rows("w 1 5", "w 2 5", "w 3 6")) - - // Test update multi-partitions - tk.MustExec("delete from t") - tk.MustExec("insert into t values ('w', 1, 1), ('w', 2, 2), ('e', 8, 8),('n', 11, 11)") - tk.MustExec("update t set a=a+1 where id < 20") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 2", "w 2 3", "e 8 9", "n 11 12")) - tk.MustExec("update t set a=a+1 where location in ('w','s','n')") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 3", "w 2 4", "e 8 9", "n 11 13")) - tk.MustExec("update t set a=a+1 where location in ('w','s','n') and id in (1,3,5,7,8,9,11)") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 4", "w 2 4", "e 8 9", "n 11 14")) - tk.MustExec("update t set a=a+1 where location='n' and id=12") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 4", "w 2 4", "e 8 9", "n 11 14")) - tk.MustExec("update t set a=a+1 where location='n' and id=11") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 4", "w 2 4", "e 8 9", "n 11 15")) - // Test update meet duplicate error. - err = tk.ExecToErr("update t set id=id+1 where location='w' and id in (1,2)") - require.EqualError(t, err, "[kv:1062]Duplicate entry 'w-2' for key 't.idx'") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 4", "w 2 4", "e 8 9", "n 11 15")) - // Test update meet no partition error. - err = tk.ExecToErr("update t set id=id+3 where location='w' and id in (1,2)") - require.EqualError(t, err, "[table:1526]Table has no partition for value from column_list") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 4", "w 2 4", "e 8 9", "n 11 15")) - // Test update that move from partition 1 to partition 2. - // TODO: fix this - tk.MustExec("update t set location='s', id=14 where location='e' and id=8") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 4", "w 2 4", "n 11 15", "s 14 9")) - - // --------------------------Test replace--------------------------- - // Test replace 1 partition. - tk.MustExec("delete from t") - tk.MustExec("replace into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3)") - tk.MustQuery("select * from t partition(p_west) order by id").Check(testkit.Rows("w 1 1", "w 2 2", "w 3 3")) - // Test replace multi-partitions. - tk.MustExec("delete from t") - tk.MustExec("replace into t values ('w', 1, 1),('e', 5, 5),('n', 9, 9)") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 1", "e 5 5", "n 9 9")) - // Test replace on duplicate. - tk.MustExec("replace into t values ('w', 1, 2),('n', 10, 10)") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 2", "e 5 5", "n 9 9", "n 10 10")) - // Test replace meet no partition error. - tk.MustGetErrMsg("replace into t values ('w', 5, 5)", "[table:1526]Table has no partition for value from column_list") - tk.MustGetErrMsg("replace into t values ('s', 5, 5)", "[table:1526]Table has no partition for value from column_list") - tk.MustGetErrMsg("replace into t values ('s', 100, 5)", "[table:1526]Table has no partition for value from column_list") - tk.MustGetErrMsg("replace into t values ('x', 1, 5)", "[table:1526]Table has no partition for value from column_list") - - // --------------------------Test delete--------------------------- - // Test delete 1 partition. - tk.MustExec("delete from t where location='w' and id=2") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("w 1 2", "e 5 5", "n 9 9", "n 10 10")) - tk.MustExec("delete from t where location='w' and id=1") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("e 5 5", "n 9 9", "n 10 10")) - // Test delete multi-partitions. - tk.MustExec("delete from t where location in ('w','e','n') and id in (1,2,3,4,5,8,9)") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("n 10 10")) - tk.MustExec("delete from t where a=10") - tk.MustQuery("select * from t order by id").Check(testkit.Rows()) - tk.MustExec("replace into t values ('w', 1, 1),('e', 5, 5),('n', 11, 11)") - tk.MustExec("delete from t where id < 10") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("n 11 11")) - tk.MustExec("delete from t limit 1") - tk.MustQuery("select * from t order by id").Check(testkit.Rows()) -} - -func TestWriteListPartitionTableIssue21437(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec("drop table if exists t") - tk.MustExec(`create table t (a int) partition by list (a%10) (partition p0 values in (0,1));`) - err := tk.ExecToErr("replace into t values (null)") - require.EqualError(t, err, "[table:1526]Table has no partition for value NULL") -} - func TestListPartitionWithAutoRandom(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -2258,220 +1978,6 @@ func TestListPartitionWithAutoIncrement(t *testing.T) { tk.MustQuery("select b from t where a=1").Check(testkit.Rows("4")) } -func TestListPartitionWithGeneratedColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - // Test for generated column with bigint type. - tableDefs := []string{ - // Test for virtual generated column for list partition - `create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list (5*b - 4*b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10));`, - // Test for stored generated column for list partition - `create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list (5*b - 4*b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10));`, - // Test for virtual generated column for list columns partition - `create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list columns(b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10));`, - // Test for stored generated column for list columns partition - `create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list columns(b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10));`, - } - for _, tbl := range tableDefs { - tk.MustExec("drop table if exists t") - tk.MustExec(tbl) - // Test for insert - tk.MustExec("insert into t (a) values (1),(3),(5),(7),(9)") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("1", "3", "5")) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("7", "9")) - tk.MustQuery("select * from t where a = 1").Check(testkit.Rows("1 1")) - // Test for update - tk.MustExec("update t set a=a+1 where a = 1") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("2", "3", "5")) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("7", "9")) - tk.MustQuery("select * from t where a = 1").Check(testkit.Rows()) - tk.MustQuery("select * from t where a = 2").Check(testkit.Rows("2 2")) - // Test for delete - tk.MustExec("delete from t where a>10") - tk.MustQuery("select count(1) from t").Check(testkit.Rows("5")) - tk.MustExec("delete from t where a=9") - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("7")) - tk.MustQuery("select count(1) from t").Check(testkit.Rows("4")) - - // Test for insert meet no partition error - err := tk.ExecToErr("insert into t (a) values (11)") - require.True(t, table.ErrNoPartitionForGivenValue.Equal(err)) - // Test for update meet no partition error - err = tk.ExecToErr("update t set a=a+10 where a = 2") - require.True(t, table.ErrNoPartitionForGivenValue.Equal(err)) - } -} - -func TestListPartitionWithGeneratedColumn1(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - // Test for generated column with year type. - tableDefs := []string{ - // Test for virtual generated column for list partition - `create table t (a year, b year GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list (1 + b - 1) (partition p0 values in (2001,2002,2003,2004,2005), partition p1 values in (2006,2007,2008,2009));`, - // Test for stored generated column for list partition - `create table t (a year, b year GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list (1 + b - 1) (partition p0 values in (2001,2002,2003,2004,2005), partition p1 values in (2006,2007,2008,2009));`, - } - for _, tbl := range tableDefs { - tk.MustExec("drop table if exists t") - tk.MustExec(tbl) - // Test for insert - tk.MustExec("insert into t (a) values (1),(3),(5),(7),(9)") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("2001", "2003", "2005")) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("2007", "2009")) - tk.MustQuery("select * from t where a = 1").Check(testkit.Rows("2001 2001")) - // Test for update - tk.MustExec("update t set a=a+1 where a = 1") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("2002", "2003", "2005")) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("2007", "2009")) - tk.MustQuery("select * from t where a = 1").Check(testkit.Rows()) - tk.MustQuery("select * from t where a = 2").Check(testkit.Rows("2002 2002")) - // Test for delete - tk.MustExec("delete from t where a>10") - tk.MustQuery("select count(1) from t").Check(testkit.Rows("5")) - tk.MustExec("delete from t where a=9") - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("2007")) - tk.MustQuery("select count(1) from t").Check(testkit.Rows("4")) - - // Test for insert meet no partition error - err := tk.ExecToErr("insert into t (a) values (11)") - require.EqualError(t, err, "[table:1526]Table has no partition for value 2011") - // Test for update meet no partition error - err = tk.ExecToErr("update t set a=a+10 where a = 2") - require.EqualError(t, err, "[table:1526]Table has no partition for value 2012") - tk.MustExec("delete from t") - - // Test for insert - tk.MustExec("insert into t (a) values (2001),(2003),(2005),(2007),(2009)") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("2001", "2003", "2005")) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("2007", "2009")) - tk.MustQuery("select * from t where a = 2001").Check(testkit.Rows("2001 2001")) - // Test for update - tk.MustExec("update t set a=a+1 where a = 2001") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("2002", "2003", "2005")) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("2007", "2009")) - tk.MustQuery("select * from t where a = 2001").Check(testkit.Rows()) - tk.MustQuery("select * from t where a = 2002").Check(testkit.Rows("2002 2002")) - // Test for delete - tk.MustExec("delete from t where a>2010") - tk.MustQuery("select count(1) from t").Check(testkit.Rows("5")) - tk.MustExec("delete from t where a=2009") - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("2007")) - tk.MustQuery("select count(1) from t").Check(testkit.Rows("4")) - - // Test for insert meet no partition error - tk.MustGetErrMsg("insert into t (a) values (2011)", "[table:1526]Table has no partition for value 2011") - // Test for update meet no partition error - tk.MustGetErrMsg("update t set a=a+10 where a = 2002", "[table:1526]Table has no partition for value 2012") - } -} - -func TestListPartitionWithGeneratedColumn2(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tableDefs := []string{ - // Test for virtual generated column for datetime type in list partition. - `create table t (a datetime, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list (1 + b - 1) ( - partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), - partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41')));`, - // Test for stored generated column for datetime type in list partition. - `create table t (a datetime, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list (1 + b - 1) ( - partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), - partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41')));`, - // Test for virtual generated column for timestamp type in list partition. - `create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list (1 + b - 1) ( - partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), - partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41')));`, - // Test for stored generated column for timestamp type in list partition. - `create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list (1 + b - 1) ( - partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), - partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41')));`, - // Test for virtual generated column for timestamp type in list columns partition. - `create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list columns(b) ( - partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), - partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41')));`, - // Test for stored generated column for timestamp type in list columns partition. - `create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list columns(b) ( - partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), - partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41')));`, - } - for _, tbl := range tableDefs { - tk.MustExec("drop table if exists t") - tk.MustExec(tbl) - tk.MustExec("insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40')") - tk.MustQuery("select a from t partition (p0)").Check(testkit.Rows("2020-09-28 17:03:38")) - tk.MustQuery("select a from t where a = '2020-09-28 17:03:40'").Check(testkit.Rows("2020-09-28 17:03:40")) - tk.MustExec("update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'") - tk.MustQuery("select a from t partition (p0)").Check(testkit.Rows()) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("2020-09-28 17:03:40", "2020-09-28 17:03:41")) - } -} - -func TestListColumnsPartitionWithGeneratedColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - // Test for generated column with substr expression. - tableDefs := []string{ - // Test for virtual generated column - `create table t (a varchar(10), b varchar(1) GENERATED ALWAYS AS (substr(a,1,1)) VIRTUAL, index idx(a)) partition by list columns(b) (partition p0 values in ('a','c'), partition p1 values in ('b','d'));`, - // Test for stored generated column - `create table t (a varchar(10), b varchar(1) GENERATED ALWAYS AS (substr(a,1,1)) STORED, index idx(a)) partition by list columns(b) (partition p0 values in ('a','c'), partition p1 values in ('b','d'));`, - } - for _, tbl := range tableDefs { - tk.MustExec("drop table if exists t") - tk.MustExec(tbl) - tk.MustExec("insert into t (a) values ('aaa'),('abc'),('acd')") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("aaa", "abc", "acd")) - tk.MustQuery("select * from t where a = 'abc' order by a").Check(testkit.Rows("abc a")) - tk.MustExec("update t set a='bbb' where a = 'aaa'") - tk.MustQuery("select a from t partition (p0) order by a").Check(testkit.Rows("abc", "acd")) - tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("bbb")) - tk.MustQuery("select * from t where a = 'bbb' order by a").Check(testkit.Rows("bbb b")) - } -} - -func TestIssue22496(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t12") - tk.MustExec("create table t12(d decimal(15,2));") - err := tk.ExecToErr("insert into t12 values('1,9999.00')") - require.Error(t, err) - tk.MustExec("set sql_mode=''") - tk.MustExec("insert into t12 values('1,999.00');") - tk.MustQuery("SELECT * FROM t12;").Check(testkit.Rows("1.00")) - tk.MustExec("drop table t12") -} - -func TestIssue21232(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a varchar(1), index idx(a))") - tk.MustExec("create table t1(a varchar(5), index idx(a))") - tk.MustExec("insert into t values('a'), ('b')") - tk.MustExec("insert into t1 values('a'), ('bbbbb')") - tk.MustExec("update /*+ INL_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a") - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustQuery("select * from t").Check(testkit.Rows("a", "b")) - tk.MustExec("update /*+ INL_HASH_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a") - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustQuery("select * from t").Check(testkit.Rows("a", "b")) - tk.MustExec("update /*+ INL_MERGE_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a") - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustQuery("select * from t").Check(testkit.Rows("a", "b")) -} - func TestUpdate(t *testing.T) { failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`) defer failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune") @@ -2788,98 +2294,6 @@ func TestListColumnsPartitionWithGlobalIndex(t *testing.T) { } } -func TestIssue20724(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 varchar(10) collate utf8mb4_general_ci)") - tk.MustExec("insert into t1 values ('a')") - tk.MustExec("update t1 set a = 'A'") - tk.MustQuery("select * from t1").Check(testkit.Rows("A")) - tk.MustExec("drop table t1") -} - -func TestIssue20840(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeIntOnly - tk.MustExec("create table t1 (i varchar(20) unique key) collate=utf8mb4_general_ci") - tk.MustExec("insert into t1 values ('a')") - tk.MustExec("replace into t1 values ('A')") - tk.MustQuery("select * from t1").Check(testkit.Rows("A")) - tk.MustExec("drop table t1") -} - -func TestIssueInsertPrefixIndexForNonUTF8Collation(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2, t3") - tk.MustExec("create table t1 ( c_int int, c_str varchar(40) character set ascii collate ascii_bin, primary key(c_int, c_str(8)) clustered , unique key(c_str))") - tk.MustExec("create table t2 ( c_int int, c_str varchar(40) character set latin1 collate latin1_bin, primary key(c_int, c_str(8)) clustered , unique key(c_str))") - tk.MustExec("insert into t1 values (3, 'fervent brattain')") - tk.MustExec("insert into t2 values (3, 'fervent brattain')") - tk.MustExec("admin check table t1") - tk.MustExec("admin check table t2") - - tk.MustExec("create table t3 (x varchar(40) CHARACTER SET ascii COLLATE ascii_bin, UNIQUE KEY uk(x(4)))") - tk.MustExec("insert into t3 select 'abc '") - tk.MustGetErrCode("insert into t3 select 'abc d'", 1062) -} - -func TestIssue40066(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database test_40066") - defer tk.MustExec("drop database test_40066") - tk.MustExec("use test_40066") - tk.MustExec("set @orig_sql_mode = @@sql_mode;") - defer tk.MustExec("set @@sql_mode = @orig_sql_mode;") - - tk.MustExec(`create table t_int(column1 int, column2 int unsigned generated always as(column1-100));`) - tk.MustExec("set @@sql_mode = DEFAULT;") - tk.MustGetErrMsg("insert into t_int(column1) values (99);", "[types:1264]Out of range value for column 'column2' at row 1") - tk.MustExec("set @@sql_mode = '';") - tk.MustExec("insert into t_int(column1) values (99);") - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1264 Out of range value for column 'column2' at row 1")) - tk.MustQuery("select * from t_int;").Check(testkit.Rows("99 0")) - - tk.MustExec(`create table t_float(column1 float, column2 int unsigned generated always as(column1-100));`) - tk.MustExec("set @@sql_mode = DEFAULT;") - tk.MustGetErrMsg("insert into t_float(column1) values (12.95);", "[types:1264]Out of range value for column 'column2' at row 1") - tk.MustExec("set @@sql_mode = '';") - tk.MustExec("insert into t_float(column1) values (12.95);") - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1264 Out of range value for column 'column2' at row 1")) - tk.MustQuery("select * from t_float;").Check(testkit.Rows("12.95 0")) - - tk.MustExec(`create table t_decimal(column1 decimal(20,10), column2 int unsigned generated always as(column1-100));`) - tk.MustExec("set @@sql_mode = DEFAULT;") - tk.MustGetErrMsg("insert into t_decimal(column1) values (123.456e-2);", "[types:1264]Out of range value for column 'column2' at row 1") - tk.MustExec("set @@sql_mode = '';") - tk.MustExec("insert into t_decimal(column1) values (123.456e-2);") - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1264 Out of range value for column 'column2' at row 1")) - tk.MustQuery("select * from t_decimal;").Check(testkit.Rows("1.2345600000 0")) - - tk.MustExec(`create table t_varchar(column1 varchar(10), column2 int unsigned generated always as(column1-100));`) - tk.MustExec("set @@sql_mode = DEFAULT;") - tk.MustGetErrMsg("insert into t_varchar(column1) values ('87.12');", "[types:1264]Out of range value for column 'column2' at row 1") - tk.MustExec("set @@sql_mode = '';") - tk.MustExec("insert into t_varchar(column1) values ('87.12');") - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1264 Out of range value for column 'column2' at row 1")) - tk.MustQuery("select * from t_varchar;").Check(testkit.Rows("87.12 0")) - - tk.MustExec(`create table t_union(column1 float, column2 int unsigned generated always as(column1-100), column3 float unsigned generated always as(column1-100));`) - tk.MustExec("set @@sql_mode = DEFAULT;") - tk.MustGetErrMsg("insert into t_union(column1) values (12.95);", "[types:1264]Out of range value for column 'column2' at row 1") - tk.MustExec("set @@sql_mode = '';") - tk.MustExec("insert into t_union(column1) values (12.95);") - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1264 Out of range value for column 'column2' at row 1", "Warning 1264 Out of range value for column 'column3' at row 1")) - tk.MustQuery("select * from t_union;").Check(testkit.Rows("12.95 0 0")) -} - func TestMutipleReplaceAndInsertInOneSession(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -2899,14 +2313,3 @@ func TestMutipleReplaceAndInsertInOneSession(t *testing.T) { tk2.MustQuery("select * from t_securities").Sort().Check(testkit.Rows("1 1 2 7", "2 7 1 7", "3 8 1 7", "8 9 1 7")) } - -func TestHandleColumnWithOnUpdateCurrentTimestamp(t *testing.T) { - // Test https://github.com/pingcap/tidb/issues/44565 - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (a timestamp on update current_timestamp(0), b int, primary key (a) clustered, key idx (a))") - tk.MustExec("insert into t values ('2023-06-11 10:00:00', 1)") - tk.MustExec("update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'") - tk.MustExec("admin check table t") -} diff --git a/tests/integrationtest/r/executor/join.result b/tests/integrationtest/r/executor/join.result index f412b00a4009b..3832452376d72 100644 --- a/tests/integrationtest/r/executor/join.result +++ b/tests/integrationtest/r/executor/join.result @@ -633,3 +633,40 @@ a1 a2 b1 b2 c1 c2 1 2 1 3 NULL NULL 2 2 2 3 NULL NULL 3 2 NULL NULL 3 4 +set sql_mode = 'ONLY_FULL_GROUP_BY'; +drop table if exists events; +create table events (clock int, source int); +SELECT * FROM events e JOIN (SELECT MAX(clock) AS clock FROM events e2 GROUP BY e2.source) e3 ON e3.clock=e.clock; +clock source clock +SELECT * FROM events e JOIN (SELECT clock FROM events e2 GROUP BY e2.source) e3 ON e3.clock=e.clock; +Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'executor__join.e2.clock' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by +drop table if exists tpj1,tpj2; +create table tpj1 (id int, b int, unique index (id)); +create table tpj2 (id int, b int, unique index (id)); +insert into tpj1 values (1,1); +insert into tpj2 values (1,1); +select tpj1.b,tpj2.b from tpj1 left join tpj2 on tpj1.id=tpj2.id where tpj1.id=1; +b b +1 1 +set sql_mode = default; +drop table if exists t1; +drop table if exists t2; +create table t1 (id int); +create table t2 (id int); +insert into t1 values (1); +insert into t2 values (1); +SELECT * FROM t1 JOIN t2 on (t2.id < all (SELECT 1)); +Error 1105 (HY000): ON condition doesn't support subqueries yet +SELECT * FROM (select null) v NATURAL LEFT JOIN (select null) v1; +NULL +NULL +drop table if exists t0; +drop view if exists v0; +CREATE TABLE t0(c0 TEXT); +CREATE VIEW v0(c0) AS SELECT NULL; +SELECT /*+ HASH_JOIN(v0) */ * FROM v0 NATURAL LEFT JOIN t0; +c0 +NULL +SELECT /*+ MERGE_JOIN(v0) */ * FROM v0 NATURAL LEFT JOIN t0; +c0 +NULL diff --git a/tests/integrationtest/r/executor/write.result b/tests/integrationtest/r/executor/write.result index ee8179fb3b6d6..d0f34e585f8c2 100644 --- a/tests/integrationtest/r/executor/write.result +++ b/tests/integrationtest/r/executor/write.result @@ -789,3 +789,1102 @@ id name 2 b set @@session.tidb_enable_list_partition = default; drop table if exists t; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (id int, name varchar(10)) partition by list (id) ( +partition p0 values in (3,5,6,9,17), +partition p1 values in (1,2,10,11,19,20), +partition p2 values in (4,12,13,14,18), +partition p3 values in (7,8,15,16,null) +); +insert into t values (1, 'a'),(1,'b'); +alter table t add unique index idx (id); +Error 1062 (23000): Duplicate entry '1' for key 't.idx' +delete from t where name='b'; +alter table t add unique index idx (id); +delete from t; +insert into t values (1, 'a'),(2,'b'),(10,'c'); +select * from t partition(p1) order by id; +id name +1 a +2 b +10 c +delete from t; +insert into t values (1, 'a'),(3,'c'),(4,'e'); +select * from t partition(p0) order by id; +id name +3 c +select * from t partition(p1) order by id; +id name +1 a +select * from t partition(p2) order by id; +id name +4 e +select * from t partition(p3) order by id; +id name +insert into t values (1, 'd'), (3,'f'),(5,'g') on duplicate key update name='x'; +select * from t partition(p0) order by id; +id name +3 x +5 g +select * from t partition(p1) order by id; +id name +1 x +select * from t partition(p2) order by id; +id name +4 e +select * from t partition(p3) order by id; +id name +insert into t values (3, 'a'), (11,'x') on duplicate key update id=id+1; +Error 1062 (23000): Duplicate entry '4' for key 't.idx' +select * from t order by id; +id name +1 x +3 x +4 e +5 g +insert ignore into t values (1, 'b'), (5,'a'),(null,'y'); +Level Code Message +Warning 1062 Duplicate entry '1' for key 't.idx' +Warning 1062 Duplicate entry '5' for key 't.idx' +select * from t partition(p0) order by id; +id name +3 x +5 g +select * from t partition(p1) order by id; +id name +1 x +select * from t partition(p2) order by id; +id name +4 e +select * from t partition(p3) order by id; +id name +NULL y +insert ignore into t values (15, 'a'),(17,'a'); +select * from t partition(p0,p1,p2) order by id; +id name +1 x +3 x +4 e +5 g +17 a +select * from t partition(p3) order by id; +id name +NULL y +15 a +insert into t values (100, 'd'); +Error 1526 (HY000): Table has no partition for value 100 +delete from t; +insert into t values (1, 'a'),(2,'b'),(3,'c'); +update t set name='b' where id=2; +select * from t partition(p1); +id name +1 a +2 b +update t set name='x' where id in (1,2); +select * from t partition(p1); +id name +1 x +2 x +update t set name='y' where id < 3; +select * from t order by id; +id name +1 y +2 y +3 c +update t set id=2 where id = 1; +Error 1062 (23000): Duplicate entry '2' for key 't.idx' +select * from t order by id; +id name +1 y +2 y +3 c +update t set name='z' where id in (1,2,3); +select * from t order by id; +id name +1 z +2 z +3 z +update t set name='a' limit 3; +select * from t order by id; +id name +1 a +2 a +3 a +update t set id=id*10 where id in (1,2); +select * from t order by id; +id name +3 a +10 a +20 a +update t set id=id+17 where id in (3,10); +Error 1526 (HY000): Table has no partition for value 27 +select * from t order by id; +id name +3 a +10 a +20 a +update t set id=id*2 where id in (3,20); +Error 1526 (HY000): Table has no partition for value 40 +select * from t order by id; +id name +3 a +10 a +20 a +delete from t; +replace into t values (1, 'a'),(2,'b'); +select * from t order by id; +id name +1 a +2 b +replace into t values (3, 'c'),(4,'d'),(7,'f'); +select * from t partition(p0) order by id; +id name +3 c +select * from t partition(p1) order by id; +id name +1 a +2 b +select * from t partition(p2) order by id; +id name +4 d +select * from t partition(p3) order by id; +id name +7 f +replace into t values (1, 'x'),(7,'x'); +select * from t order by id; +id name +1 x +2 b +3 c +4 d +7 x +replace into t values (10,'x'),(50,'x'); +Error 1526 (HY000): Table has no partition for value 50 +select * from t order by id; +id name +1 x +2 b +3 c +4 d +7 x +delete from t where id = 3; +select * from t partition(p0) order by id; +id name +delete from t where id in (1,2); +select * from t partition(p1) order by id; +id name +delete from t where id in (4,7,10,11); +select * from t; +id name +insert into t values (3, 'c'),(4,'d'),(7,'f'); +delete from t where id < 10; +select * from t; +id name +insert into t values (3, 'c'),(4,'d'),(7,'f'); +delete from t limit 3; +select * from t; +id name +drop table if exists t; +set @@session.tidb_enable_list_partition = default; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (location varchar(10), id int, a int) partition by list columns (location,id) ( +partition p_west values in (('w', 1),('w', 2),('w', 3),('w', 4)), +partition p_east values in (('e', 5),('e', 6),('e', 7),('e', 8)), +partition p_north values in (('n', 9),('n',10),('n',11),('n',12)), +partition p_south values in (('s',13),('s',14),('s',15),('s',16)) +); +insert into t values ('w', 1, 1),('w', 1, 2); +alter table t add unique index idx (location,id); +Error 1062 (23000): Duplicate entry 'w-1' for key 't.idx' +delete from t where a=2; +alter table t add unique index idx (location,id); +delete from t; +insert into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3); +select * from t partition(p_west) order by id; +location id a +w 1 1 +w 2 2 +w 3 3 +delete from t; +insert into t values ('w', 1, 1),('e', 5, 5),('n', 9, 9); +select * from t partition(p_west) order by id; +location id a +w 1 1 +select * from t partition(p_east) order by id; +location id a +e 5 5 +select * from t partition(p_north) order by id; +location id a +n 9 9 +select * from t partition(p_south) order by id; +location id a +insert into t values ('w', 1, 1) on duplicate key update a=a+1; +select * from t partition(p_west) order by id; +location id a +w 1 2 +insert into t values ('w', 1, 1) on duplicate key update location='s', id=13; +select * from t partition(p_south) order by id; +location id a +s 13 2 +select * from t partition(p_west) order by id; +location id a +insert into t values ('w', 2, 2), ('w', 1, 1); +insert into t values ('w', 2, 3) on duplicate key update id=1; +Error 1062 (23000): Duplicate entry 'w-1' for key 't.idx' +select * from t partition(p_west) order by id; +location id a +w 1 1 +w 2 2 +insert ignore into t values ('w', 2, 2), ('w', 3, 3), ('n', 10, 10); +Level Code Message +Warning 1062 Duplicate entry 'w-2' for key 't.idx' +select * from t partition(p_west) order by id; +location id a +w 1 1 +w 2 2 +w 3 3 +select * from t partition(p_north) order by id; +location id a +n 9 9 +n 10 10 +insert ignore into t values ('w', 4, 4), ('s', 14, 14); +select * from t partition(p_west) order by id; +location id a +w 1 1 +w 2 2 +w 3 3 +w 4 4 +select * from t partition(p_south) order by id; +location id a +s 13 2 +s 14 14 +insert into t values ('w', 5, 5); +Error 1526 (HY000): Table has no partition for value from column_list +insert into t values ('s', 5, 5); +Error 1526 (HY000): Table has no partition for value from column_list +insert into t values ('s', 100, 5); +Error 1526 (HY000): Table has no partition for value from column_list +insert into t values ('x', 1, 5); +Error 1526 (HY000): Table has no partition for value from column_list +delete from t; +insert into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3); +update t set a=2 where a=1; +select * from t partition(p_west) order by id; +location id a +w 1 2 +w 2 2 +w 3 3 +update t set a=3 where location='w'; +select * from t partition(p_west) order by id; +location id a +w 1 3 +w 2 3 +w 3 3 +update t set a=4 where location='w' and id=1; +select * from t partition(p_west) order by id; +location id a +w 1 4 +w 2 3 +w 3 3 +update t set a=5 where id=1; +select * from t partition(p_west) order by id; +location id a +w 1 5 +w 2 3 +w 3 3 +update t set a=a+id where id>1; +select * from t partition(p_west) order by id,a; +location id a +w 1 5 +w 2 5 +w 3 6 +update t set id=id+1 where location='w' and id<2; +Error 1062 (23000): Duplicate entry 'w-2' for key 't.idx' +select * from t partition(p_west) order by id,a; +location id a +w 1 5 +w 2 5 +w 3 6 +delete from t; +insert into t values ('w', 1, 1), ('w', 2, 2), ('e', 8, 8),('n', 11, 11); +update t set a=a+1 where id < 20; +select * from t order by id; +location id a +w 1 2 +w 2 3 +e 8 9 +n 11 12 +update t set a=a+1 where location in ('w','s','n'); +select * from t order by id; +location id a +w 1 3 +w 2 4 +e 8 9 +n 11 13 +update t set a=a+1 where location in ('w','s','n') and id in (1,3,5,7,8,9,11); +select * from t order by id; +location id a +w 1 4 +w 2 4 +e 8 9 +n 11 14 +update t set a=a+1 where location='n' and id=12; +select * from t order by id; +location id a +w 1 4 +w 2 4 +e 8 9 +n 11 14 +update t set a=a+1 where location='n' and id=11; +select * from t order by id; +location id a +w 1 4 +w 2 4 +e 8 9 +n 11 15 +update t set id=id+1 where location='w' and id in (1,2); +Error 1062 (23000): Duplicate entry 'w-2' for key 't.idx' +select * from t order by id; +location id a +w 1 4 +w 2 4 +e 8 9 +n 11 15 +update t set id=id+3 where location='w' and id in (1,2); +Error 1526 (HY000): Table has no partition for value from column_list +select * from t order by id; +location id a +w 1 4 +w 2 4 +e 8 9 +n 11 15 +update t set location='s', id=14 where location='e' and id=8; +select * from t order by id; +location id a +w 1 4 +w 2 4 +n 11 15 +s 14 9 +delete from t; +replace into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3); +select * from t partition(p_west) order by id; +location id a +w 1 1 +w 2 2 +w 3 3 +delete from t; +replace into t values ('w', 1, 1),('e', 5, 5),('n', 9, 9); +select * from t order by id; +location id a +w 1 1 +e 5 5 +n 9 9 +replace into t values ('w', 1, 2),('n', 10, 10); +select * from t order by id; +location id a +w 1 2 +e 5 5 +n 9 9 +n 10 10 +replace into t values ('w', 5, 5); +Error 1526 (HY000): Table has no partition for value from column_list +replace into t values ('s', 5, 5); +Error 1526 (HY000): Table has no partition for value from column_list +replace into t values ('s', 100, 5); +Error 1526 (HY000): Table has no partition for value from column_list +replace into t values ('x', 1, 5); +Error 1526 (HY000): Table has no partition for value from column_list +delete from t where location='w' and id=2; +select * from t order by id; +location id a +w 1 2 +e 5 5 +n 9 9 +n 10 10 +delete from t where location='w' and id=1; +select * from t order by id; +location id a +e 5 5 +n 9 9 +n 10 10 +delete from t where location in ('w','e','n') and id in (1,2,3,4,5,8,9); +select * from t order by id; +location id a +n 10 10 +delete from t where a=10; +select * from t order by id; +location id a +replace into t values ('w', 1, 1),('e', 5, 5),('n', 11, 11); +delete from t where id < 10; +select * from t order by id; +location id a +n 11 11 +delete from t limit 1; +select * from t order by id; +location id a +drop table if exists t; +set @@session.tidb_enable_list_partition = default; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a int) partition by list (a%10) (partition p0 values in (0,1)); +replace into t values (null); +Error 1526 (HY000): Table has no partition for value NULL +drop table if exists t; +set @@session.tidb_enable_list_partition = default; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list (5*b - 4*b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +a +1 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +1 1 +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +a +2 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +select * from t where a = 2; +a b +2 2 +delete from t where a>10; +select count(1) from t; +count(1) +5 +delete from t where a=9; +select a from t partition (p1) order by a; +a +7 +select count(1) from t; +count(1) +4 +insert into t (a) values (11); +Error 1526 (HY000): Table has no partition for value 11 +update t set a=a+10 where a = 2; +Error 1526 (HY000): Table has no partition for value 12 +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list (5*b - 4*b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +a +1 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +1 1 +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +a +2 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +select * from t where a = 2; +a b +2 2 +delete from t where a>10; +select count(1) from t; +count(1) +5 +delete from t where a=9; +select a from t partition (p1) order by a; +a +7 +select count(1) from t; +count(1) +4 +insert into t (a) values (11); +Error 1526 (HY000): Table has no partition for value 11 +update t set a=a+10 where a = 2; +Error 1526 (HY000): Table has no partition for value 12 +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list columns(b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +a +1 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +1 1 +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +a +2 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +select * from t where a = 2; +a b +2 2 +delete from t where a>10; +select count(1) from t; +count(1) +5 +delete from t where a=9; +select a from t partition (p1) order by a; +a +7 +select count(1) from t; +count(1) +4 +insert into t (a) values (11); +Error 1526 (HY000): Table has no partition for value from column_list +update t set a=a+10 where a = 2; +Error 1526 (HY000): Table has no partition for value from column_list +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list columns(b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +a +1 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +1 1 +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +a +2 +3 +5 +select a from t partition (p1) order by a; +a +7 +9 +select * from t where a = 1; +a b +select * from t where a = 2; +a b +2 2 +delete from t where a>10; +select count(1) from t; +count(1) +5 +delete from t where a=9; +select a from t partition (p1) order by a; +a +7 +select count(1) from t; +count(1) +4 +insert into t (a) values (11); +Error 1526 (HY000): Table has no partition for value from column_list +update t set a=a+10 where a = 2; +Error 1526 (HY000): Table has no partition for value from column_list +drop table if exists t; +set @@session.tidb_enable_list_partition = default; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a year, b year GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list (1 + b - 1) (partition p0 values in (2001,2002,2003,2004,2005), partition p1 values in (2006,2007,2008,2009)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +a +2001 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 1; +a b +2001 2001 +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +a +2002 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 1; +a b +select * from t where a = 2; +a b +2002 2002 +delete from t where a>10; +select count(1) from t; +count(1) +5 +delete from t where a=9; +select a from t partition (p1) order by a; +a +2007 +select count(1) from t; +count(1) +4 +insert into t (a) values (11); +Error 1526 (HY000): Table has no partition for value 2011 +update t set a=a+10 where a = 2; +Error 1526 (HY000): Table has no partition for value 2012 +delete from t; +insert into t (a) values (2001),(2003),(2005),(2007),(2009); +select a from t partition (p0) order by a; +a +2001 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 2001; +a b +2001 2001 +update t set a=a+1 where a = 2001; +select a from t partition (p0) order by a; +a +2002 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 2001; +a b +select * from t where a = 2002; +a b +2002 2002 +delete from t where a>2010; +select count(1) from t; +count(1) +5 +delete from t where a=2009; +select a from t partition (p1) order by a; +a +2007 +select count(1) from t; +count(1) +4 +insert into t (a) values (2011); +Error 1526 (HY000): Table has no partition for value 2011 +update t set a=a+10 where a = 2002; +Error 1526 (HY000): Table has no partition for value 2012 +drop table if exists t; +create table t (a year, b year GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list (1 + b - 1) (partition p0 values in (2001,2002,2003,2004,2005), partition p1 values in (2006,2007,2008,2009)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +a +2001 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 1; +a b +2001 2001 +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +a +2002 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 1; +a b +select * from t where a = 2; +a b +2002 2002 +delete from t where a>10; +select count(1) from t; +count(1) +5 +delete from t where a=9; +select a from t partition (p1) order by a; +a +2007 +select count(1) from t; +count(1) +4 +insert into t (a) values (11); +Error 1526 (HY000): Table has no partition for value 2011 +update t set a=a+10 where a = 2; +Error 1526 (HY000): Table has no partition for value 2012 +delete from t; +insert into t (a) values (2001),(2003),(2005),(2007),(2009); +select a from t partition (p0) order by a; +a +2001 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 2001; +a b +2001 2001 +update t set a=a+1 where a = 2001; +select a from t partition (p0) order by a; +a +2002 +2003 +2005 +select a from t partition (p1) order by a; +a +2007 +2009 +select * from t where a = 2001; +a b +select * from t where a = 2002; +a b +2002 2002 +delete from t where a>2010; +select count(1) from t; +count(1) +5 +delete from t where a=2009; +select a from t partition (p1) order by a; +a +2007 +select count(1) from t; +count(1) +4 +insert into t (a) values (2011); +Error 1526 (HY000): Table has no partition for value 2011 +update t set a=a+10 where a = 2002; +Error 1526 (HY000): Table has no partition for value 2012 +drop table if exists t; +set @@session.tidb_enable_list_partition = default; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a datetime, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list (1 + b - 1) ( +partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), +partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +a +2020-09-28 17:03:38 +select a from t where a = '2020-09-28 17:03:40'; +a +2020-09-28 17:03:40 +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +a +select a from t partition (p1) order by a; +a +2020-09-28 17:03:40 +2020-09-28 17:03:41 +drop table if exists t; +create table t (a datetime, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list (1 + b - 1) ( +partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), +partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +a +2020-09-28 17:03:38 +select a from t where a = '2020-09-28 17:03:40'; +a +2020-09-28 17:03:40 +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +a +select a from t partition (p1) order by a; +a +2020-09-28 17:03:40 +2020-09-28 17:03:41 +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list (1 + b - 1) ( +partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), +partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +a +2020-09-28 17:03:38 +select a from t where a = '2020-09-28 17:03:40'; +a +2020-09-28 17:03:40 +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +a +select a from t partition (p1) order by a; +a +2020-09-28 17:03:40 +2020-09-28 17:03:41 +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list (1 + b - 1) ( +partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), +partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +a +2020-09-28 17:03:38 +select a from t where a = '2020-09-28 17:03:40'; +a +2020-09-28 17:03:40 +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +a +select a from t partition (p1) order by a; +a +2020-09-28 17:03:40 +2020-09-28 17:03:41 +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list columns(b) ( +partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), +partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +a +2020-09-28 17:03:38 +select a from t where a = '2020-09-28 17:03:40'; +a +2020-09-28 17:03:40 +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +a +select a from t partition (p1) order by a; +a +2020-09-28 17:03:40 +2020-09-28 17:03:41 +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list columns(b) ( +partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), +partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +a +2020-09-28 17:03:38 +select a from t where a = '2020-09-28 17:03:40'; +a +2020-09-28 17:03:40 +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +a +select a from t partition (p1) order by a; +a +2020-09-28 17:03:40 +2020-09-28 17:03:41 +drop table if exists t; +set @@session.tidb_enable_list_partition = default; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a varchar(10), b varchar(1) GENERATED ALWAYS AS (substr(a,1,1)) VIRTUAL, index idx(a)) partition by list columns(b) (partition p0 values in ('a','c'), partition p1 values in ('b','d')); +insert into t (a) values ('aaa'),('abc'),('acd'); +select a from t partition (p0) order by a; +a +aaa +abc +acd +select * from t where a = 'abc' order by a; +a b +abc a +update t set a='bbb' where a = 'aaa'; +select a from t partition (p0) order by a; +a +abc +acd +select a from t partition (p1) order by a; +a +bbb +select * from t where a = 'bbb' order by a; +a b +bbb b +drop table if exists t; +create table t (a varchar(10), b varchar(1) GENERATED ALWAYS AS (substr(a,1,1)) STORED, index idx(a)) partition by list columns(b) (partition p0 values in ('a','c'), partition p1 values in ('b','d')); +insert into t (a) values ('aaa'),('abc'),('acd'); +select a from t partition (p0) order by a; +a +aaa +abc +acd +select * from t where a = 'abc' order by a; +a b +abc a +update t set a='bbb' where a = 'aaa'; +select a from t partition (p0) order by a; +a +abc +acd +select a from t partition (p1) order by a; +a +bbb +select * from t where a = 'bbb' order by a; +a b +bbb b +drop table if exists t; +set @@session.tidb_enable_list_partition = default; +drop table if exists t12; +create table t12(d decimal(15,2)); +insert into t12 values('1,9999.00'); +Error 1366 (HY000): Incorrect decimal value: '1,9999.00' for column 'd' at row 1 +set sql_mode=''; +insert into t12 values('1,999.00'); +SELECT * FROM t12; +d +1.00 +drop table t12; +set sql_mode=default; +drop table if exists t, t1; +create table t(a varchar(1), index idx(a)); +create table t1(a varchar(5), index idx(a)); +insert into t values('a'), ('b'); +insert into t1 values('a'), ('bbbbb'); +update /*+ INL_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a; +select * from t; +a +a +b +update /*+ INL_HASH_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a; +select * from t; +a +a +b +update /*+ INL_MERGE_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a; +select * from t; +a +a +b +drop table if exists t, t1; +drop table if exists t1; +create table t1(a varchar(10) collate utf8mb4_general_ci); +insert into t1 values ('a'); +update t1 set a = 'A'; +select * from t1; +a +A +drop table t1; +drop table if exists t1; +set @@tidb_enable_clustered_index = 'int_only'; +create table t1 (i varchar(20) unique key) collate=utf8mb4_general_ci; +insert into t1 values ('a'); +replace into t1 values ('A'); +select * from t1; +i +A +drop table t1; +drop table if exists t1, t2, t3; +create table t1 ( c_int int, c_str varchar(40) character set ascii collate ascii_bin, primary key(c_int, c_str(8)) clustered , unique key(c_str)); +create table t2 ( c_int int, c_str varchar(40) character set latin1 collate latin1_bin, primary key(c_int, c_str(8)) clustered , unique key(c_str)); +insert into t1 values (3, 'fervent brattain'); +insert into t2 values (3, 'fervent brattain'); +admin check table t1; + +admin check table t2; + +create table t3 (x varchar(40) CHARACTER SET ascii COLLATE ascii_bin, UNIQUE KEY uk(x(4))); +insert into t3 select 'abc '; +insert into t3 select 'abc d'; +Error 1062 (23000): Duplicate entry 'abc ' for key 't3.uk' +drop table if exists t1, t2, t3; +drop table if exists t_int; +create table t_int(column1 int, column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +insert into t_int(column1) values (99); +Error 1264 (22003): Out of range value for column 'column2' at row 1 +set @@sql_mode = ''; +insert into t_int(column1) values (99); +Level Code Message +Warning 1264 Out of range value for column 'column2' at row 1 +select * from t_int; +column1 column2 +99 0 +drop table if exists t_float; +create table t_float(column1 float, column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +insert into t_float(column1) values (12.95); +Error 1264 (22003): Out of range value for column 'column2' at row 1 +set @@sql_mode = ''; +insert into t_float(column1) values (12.95); +Level Code Message +Warning 1264 Out of range value for column 'column2' at row 1 +select * from t_float; +column1 column2 +12.95 0 +drop table if exists t_decimal; +create table t_decimal(column1 decimal(20,10), column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +insert into t_decimal(column1) values (123.456e-2); +Error 1264 (22003): Out of range value for column 'column2' at row 1 +set @@sql_mode = ''; +insert into t_decimal(column1) values (123.456e-2); +Level Code Message +Warning 1264 Out of range value for column 'column2' at row 1 +select * from t_decimal; +column1 column2 +1.2345600000 0 +drop table if exists t_varchar; +create table t_varchar(column1 varchar(10), column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +insert into t_varchar(column1) values ('87.12'); +Error 1264 (22003): Out of range value for column 'column2' at row 1 +set @@sql_mode = ''; +insert into t_varchar(column1) values ('87.12'); +Level Code Message +Warning 1264 Out of range value for column 'column2' at row 1 +select * from t_varchar; +column1 column2 +87.12 0 +drop table if exists t_union; +create table t_union(column1 float, column2 int unsigned generated always as(column1-100), column3 float unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +insert into t_union(column1) values (12.95); +Error 1264 (22003): Out of range value for column 'column2' at row 1 +set @@sql_mode = ''; +insert into t_union(column1) values (12.95); +Level Code Message +Warning 1264 Out of range value for column 'column2' at row 1 +Warning 1264 Out of range value for column 'column3' at row 1 +select * from t_union; +column1 column2 column3 +12.95 0 0 +set @@sql_mode = default; +drop table t_int, t_float, t_decimal, t_varchar, t_union; +drop table if exists t; +create table t (a timestamp on update current_timestamp(0), b int, primary key (a) clustered, key idx (a)); +insert into t values ('2023-06-11 10:00:00', 1); +update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'; +admin check table t; + +drop table if exists t; diff --git a/tests/integrationtest/t/executor/join.test b/tests/integrationtest/t/executor/join.test index f9485e8de4cc3..0c5d99b1eecf4 100644 --- a/tests/integrationtest/t/executor/join.test +++ b/tests/integrationtest/t/executor/join.test @@ -458,3 +458,41 @@ insert into t1 values (1,2), (2,2), (3,2); insert into t2 values (1,3), (2,3); insert into t3 values (2,4), (3,4); select * from t1 left join t2 on b1 = a1 left join t3 on c1 = a1 and b1 is null order by 1, 2, 3, 4, 5, 6; + +# TestJoinPanic2 +set sql_mode = 'ONLY_FULL_GROUP_BY'; +drop table if exists events; +create table events (clock int, source int); +SELECT * FROM events e JOIN (SELECT MAX(clock) AS clock FROM events e2 GROUP BY e2.source) e3 ON e3.clock=e.clock; +--error 1055 +SELECT * FROM events e JOIN (SELECT clock FROM events e2 GROUP BY e2.source) e3 ON e3.clock=e.clock; +drop table if exists tpj1,tpj2; +create table tpj1 (id int, b int, unique index (id)); +create table tpj2 (id int, b int, unique index (id)); +insert into tpj1 values (1,1); +insert into tpj2 values (1,1); +select tpj1.b,tpj2.b from tpj1 left join tpj2 on tpj1.id=tpj2.id where tpj1.id=1; +set sql_mode = default; + +# TestSubqueryInJoinOn +drop table if exists t1; +drop table if exists t2; +create table t1 (id int); +create table t2 (id int); +insert into t1 values (1); +insert into t2 values (1); +--error 1105 +SELECT * FROM t1 JOIN t2 on (t2.id < all (SELECT 1)); + +# TestIssue15850JoinNullValue +--enable_warnings +SELECT * FROM (select null) v NATURAL LEFT JOIN (select null) v1; +--disable_warnings +drop table if exists t0; +drop view if exists v0; +CREATE TABLE t0(c0 TEXT); +CREATE VIEW v0(c0) AS SELECT NULL; +--enable_warnings +SELECT /*+ HASH_JOIN(v0) */ * FROM v0 NATURAL LEFT JOIN t0; +SELECT /*+ MERGE_JOIN(v0) */ * FROM v0 NATURAL LEFT JOIN t0; +--disable_warnings diff --git a/tests/integrationtest/t/executor/write.test b/tests/integrationtest/t/executor/write.test index 77e949d34bfbf..8c3ac8c33bfe5 100644 --- a/tests/integrationtest/t/executor/write.test +++ b/tests/integrationtest/t/executor/write.test @@ -546,3 +546,604 @@ delete from t partition (p3,p2); select * from t order by id; set @@session.tidb_enable_list_partition = default; drop table if exists t; + +# TestWriteListPartitionTable1 +## TestWriteListPartitionTable1 test for write list partition when the partition expression is simple. +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (id int, name varchar(10)) partition by list (id) ( + partition p0 values in (3,5,6,9,17), + partition p1 values in (1,2,10,11,19,20), + partition p2 values in (4,12,13,14,18), + partition p3 values in (7,8,15,16,null) + ); +insert into t values (1, 'a'),(1,'b'); +--error 1062 +alter table t add unique index idx (id); +delete from t where name='b'; +alter table t add unique index idx (id); +delete from t; +insert into t values (1, 'a'),(2,'b'),(10,'c'); +select * from t partition(p1) order by id; +delete from t; +insert into t values (1, 'a'),(3,'c'),(4,'e'); +select * from t partition(p0) order by id; +select * from t partition(p1) order by id; +select * from t partition(p2) order by id; +select * from t partition(p3) order by id; +insert into t values (1, 'd'), (3,'f'),(5,'g') on duplicate key update name='x'; +select * from t partition(p0) order by id; +select * from t partition(p1) order by id; +select * from t partition(p2) order by id; +select * from t partition(p3) order by id; +--error 1062 +insert into t values (3, 'a'), (11,'x') on duplicate key update id=id+1; +select * from t order by id; +--enable_warnings +insert ignore into t values (1, 'b'), (5,'a'),(null,'y'); +--disable_warnings +select * from t partition(p0) order by id; +select * from t partition(p1) order by id; +select * from t partition(p2) order by id; +select * from t partition(p3) order by id; +insert ignore into t values (15, 'a'),(17,'a'); +select * from t partition(p0,p1,p2) order by id; +select * from t partition(p3) order by id; +--error 1062 +insert into t values (100, 'd'); +delete from t; +insert into t values (1, 'a'),(2,'b'),(3,'c'); +update t set name='b' where id=2; +select * from t partition(p1); +update t set name='x' where id in (1,2); +select * from t partition(p1); +update t set name='y' where id < 3; +select * from t order by id; +--error 1062 +update t set id=2 where id = 1; +select * from t order by id; +update t set name='z' where id in (1,2,3); +select * from t order by id; +update t set name='a' limit 3; +select * from t order by id; +update t set id=id*10 where id in (1,2); +select * from t order by id; +--error 1062 +update t set id=id+17 where id in (3,10); +select * from t order by id; +--error 1062 +update t set id=id*2 where id in (3,20); +select * from t order by id; +delete from t; +replace into t values (1, 'a'),(2,'b'); +select * from t order by id; +replace into t values (3, 'c'),(4,'d'),(7,'f'); +select * from t partition(p0) order by id; +select * from t partition(p1) order by id; +select * from t partition(p2) order by id; +select * from t partition(p3) order by id; +replace into t values (1, 'x'),(7,'x'); +select * from t order by id; +--error 1062 +replace into t values (10,'x'),(50,'x'); +select * from t order by id; +delete from t where id = 3; +select * from t partition(p0) order by id; +delete from t where id in (1,2); +select * from t partition(p1) order by id; +delete from t where id in (4,7,10,11); +select * from t; +insert into t values (3, 'c'),(4,'d'),(7,'f'); +delete from t where id < 10; +select * from t; +insert into t values (3, 'c'),(4,'d'),(7,'f'); +delete from t limit 3; +select * from t; +drop table if exists t; +set @@session.tidb_enable_list_partition = default; + +# TestWriteListColumnsPartitionTable2 +## TestWriteListColumnsPartitionTable2 test for write list partition when the partition by multi-columns. +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (location varchar(10), id int, a int) partition by list columns (location,id) ( + partition p_west values in (('w', 1),('w', 2),('w', 3),('w', 4)), + partition p_east values in (('e', 5),('e', 6),('e', 7),('e', 8)), + partition p_north values in (('n', 9),('n',10),('n',11),('n',12)), + partition p_south values in (('s',13),('s',14),('s',15),('s',16)) + ); +insert into t values ('w', 1, 1),('w', 1, 2); +--error 1062 +alter table t add unique index idx (location,id); +delete from t where a=2; +alter table t add unique index idx (location,id); +delete from t; +insert into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3); +select * from t partition(p_west) order by id; +delete from t; +insert into t values ('w', 1, 1),('e', 5, 5),('n', 9, 9); +select * from t partition(p_west) order by id; +select * from t partition(p_east) order by id; +select * from t partition(p_north) order by id; +select * from t partition(p_south) order by id; +insert into t values ('w', 1, 1) on duplicate key update a=a+1; +select * from t partition(p_west) order by id; +insert into t values ('w', 1, 1) on duplicate key update location='s', id=13; +select * from t partition(p_south) order by id; +select * from t partition(p_west) order by id; +insert into t values ('w', 2, 2), ('w', 1, 1); +-- error 1062 +insert into t values ('w', 2, 3) on duplicate key update id=1; +select * from t partition(p_west) order by id; +--enable_warnings +insert ignore into t values ('w', 2, 2), ('w', 3, 3), ('n', 10, 10); +--disable_warnings +select * from t partition(p_west) order by id; +select * from t partition(p_north) order by id; +insert ignore into t values ('w', 4, 4), ('s', 14, 14); +select * from t partition(p_west) order by id; +select * from t partition(p_south) order by id; +-- error 1526 +insert into t values ('w', 5, 5); +-- error 1526 +insert into t values ('s', 5, 5); +-- error 1526 +insert into t values ('s', 100, 5); +-- error 1526 +insert into t values ('x', 1, 5); +delete from t; +insert into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3); +update t set a=2 where a=1; +select * from t partition(p_west) order by id; +update t set a=3 where location='w'; +select * from t partition(p_west) order by id; +update t set a=4 where location='w' and id=1; +select * from t partition(p_west) order by id; +update t set a=5 where id=1; +select * from t partition(p_west) order by id; +update t set a=a+id where id>1; +select * from t partition(p_west) order by id,a; +--error 1062 +update t set id=id+1 where location='w' and id<2; +select * from t partition(p_west) order by id,a; +delete from t; +insert into t values ('w', 1, 1), ('w', 2, 2), ('e', 8, 8),('n', 11, 11); +update t set a=a+1 where id < 20; +select * from t order by id; +update t set a=a+1 where location in ('w','s','n'); +select * from t order by id; +update t set a=a+1 where location in ('w','s','n') and id in (1,3,5,7,8,9,11); +select * from t order by id; +update t set a=a+1 where location='n' and id=12; +select * from t order by id; +update t set a=a+1 where location='n' and id=11; +select * from t order by id; +--error 1062 +update t set id=id+1 where location='w' and id in (1,2); +select * from t order by id; +--error 1062 +update t set id=id+3 where location='w' and id in (1,2); +select * from t order by id; +update t set location='s', id=14 where location='e' and id=8; +select * from t order by id; +delete from t; +replace into t values ('w', 1, 1),('w', 2, 2),('w', 3, 3); +select * from t partition(p_west) order by id; +delete from t; +replace into t values ('w', 1, 1),('e', 5, 5),('n', 9, 9); +select * from t order by id; +replace into t values ('w', 1, 2),('n', 10, 10); +select * from t order by id; +-- error 1526 +replace into t values ('w', 5, 5); +-- error 1526 +replace into t values ('s', 5, 5); +-- error 1526 +replace into t values ('s', 100, 5); +-- error 1526 +replace into t values ('x', 1, 5); +delete from t where location='w' and id=2; +select * from t order by id; +delete from t where location='w' and id=1; +select * from t order by id; +delete from t where location in ('w','e','n') and id in (1,2,3,4,5,8,9); +select * from t order by id; +delete from t where a=10; +select * from t order by id; +replace into t values ('w', 1, 1),('e', 5, 5),('n', 11, 11); +delete from t where id < 10; +select * from t order by id; +delete from t limit 1; +select * from t order by id; +drop table if exists t; +set @@session.tidb_enable_list_partition = default; + +# TestWriteListPartitionTableIssue21437 +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a int) partition by list (a%10) (partition p0 values in (0,1)); +--error 1526 +replace into t values (null); +drop table if exists t; +set @@session.tidb_enable_list_partition = default; + +# TestListPartitionWithGeneratedColumn +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list (5*b - 4*b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +select * from t where a = 2; +delete from t where a>10; +select count(1) from t; +delete from t where a=9; +select a from t partition (p1) order by a; +select count(1) from t; +--error 1526 +insert into t (a) values (11); +--error 1526 +update t set a=a+10 where a = 2; +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list (5*b - 4*b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +select * from t where a = 2; +delete from t where a>10; +select count(1) from t; +delete from t where a=9; +select a from t partition (p1) order by a; +select count(1) from t; +--error 1526 +insert into t (a) values (11); +--error 1526 +update t set a=a+10 where a = 2; +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list columns(b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +select * from t where a = 2; +delete from t where a>10; +select count(1) from t; +delete from t where a=9; +select a from t partition (p1) order by a; +select count(1) from t; +--error 1526 +insert into t (a) values (11); +--error 1526 +update t set a=a+10 where a = 2; +drop table if exists t; +create table t (a bigint, b bigint GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list columns(b) (partition p0 values in (1,2,3,4,5), partition p1 values in (6,7,8,9,10)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +select * from t where a = 2; +delete from t where a>10; +select count(1) from t; +delete from t where a=9; +select a from t partition (p1) order by a; +select count(1) from t; +--error 1526 +insert into t (a) values (11); +--error 1526 +update t set a=a+10 where a = 2; +drop table if exists t; +set @@session.tidb_enable_list_partition = default; + +# TestListPartitionWithGeneratedColumn1 +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a year, b year GENERATED ALWAYS AS (3*a - 2*a) VIRTUAL, index idx(a)) partition by list (1 + b - 1) (partition p0 values in (2001,2002,2003,2004,2005), partition p1 values in (2006,2007,2008,2009)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +select * from t where a = 2; +delete from t where a>10; +select count(1) from t; +delete from t where a=9; +select a from t partition (p1) order by a; +select count(1) from t; +--error 1526 +insert into t (a) values (11); +--error 1526 +update t set a=a+10 where a = 2; +delete from t; +insert into t (a) values (2001),(2003),(2005),(2007),(2009); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 2001; +update t set a=a+1 where a = 2001; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 2001; +select * from t where a = 2002; +delete from t where a>2010; +select count(1) from t; +delete from t where a=2009; +select a from t partition (p1) order by a; +select count(1) from t; +-- error 1526 +insert into t (a) values (2011); +-- error 1526 +update t set a=a+10 where a = 2002; +drop table if exists t; +create table t (a year, b year GENERATED ALWAYS AS (3*a - 2*a) STORED, index idx(a)) partition by list (1 + b - 1) (partition p0 values in (2001,2002,2003,2004,2005), partition p1 values in (2006,2007,2008,2009)); +insert into t (a) values (1),(3),(5),(7),(9); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +update t set a=a+1 where a = 1; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 1; +select * from t where a = 2; +delete from t where a>10; +select count(1) from t; +delete from t where a=9; +select a from t partition (p1) order by a; +select count(1) from t; +--error 1526 +insert into t (a) values (11); +--error 1526 +update t set a=a+10 where a = 2; +delete from t; +insert into t (a) values (2001),(2003),(2005),(2007),(2009); +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 2001; +update t set a=a+1 where a = 2001; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 2001; +select * from t where a = 2002; +delete from t where a>2010; +select count(1) from t; +delete from t where a=2009; +select a from t partition (p1) order by a; +select count(1) from t; +-- error 1526 +insert into t (a) values (2011); +-- error 1526 +update t set a=a+10 where a = 2002; +drop table if exists t; +set @@session.tidb_enable_list_partition = default; + +# TestListPartitionWithGeneratedColumn2 +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a datetime, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list (1 + b - 1) ( + partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), + partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +select a from t where a = '2020-09-28 17:03:40'; +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +select a from t partition (p1) order by a; +drop table if exists t; +create table t (a datetime, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list (1 + b - 1) ( + partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), + partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +select a from t where a = '2020-09-28 17:03:40'; +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +select a from t partition (p1) order by a; +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list (1 + b - 1) ( + partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), + partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +select a from t where a = '2020-09-28 17:03:40'; +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +select a from t partition (p1) order by a; +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list (1 + b - 1) ( + partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), + partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +select a from t where a = '2020-09-28 17:03:40'; +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +select a from t partition (p1) order by a; +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list columns(b) ( + partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), + partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +select a from t where a = '2020-09-28 17:03:40'; +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +select a from t partition (p1) order by a; +drop table if exists t; +create table t (a timestamp, b bigint GENERATED ALWAYS AS (to_seconds(a)) STORED, index idx(a)) partition by list columns(b) ( + partition p0 values in (to_seconds('2020-09-28 17:03:38'),to_seconds('2020-09-28 17:03:39')), + partition p1 values in (to_seconds('2020-09-28 17:03:40'),to_seconds('2020-09-28 17:03:41'))); +insert into t (a) values ('2020-09-28 17:03:38'),('2020-09-28 17:03:40'); +select a from t partition (p0); +select a from t where a = '2020-09-28 17:03:40'; +update t set a='2020-09-28 17:03:41' where a = '2020-09-28 17:03:38'; +select a from t partition (p0); +select a from t partition (p1) order by a; +drop table if exists t; +set @@session.tidb_enable_list_partition = default; + +# TestListColumnsPartitionWithGeneratedColumn +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a varchar(10), b varchar(1) GENERATED ALWAYS AS (substr(a,1,1)) VIRTUAL, index idx(a)) partition by list columns(b) (partition p0 values in ('a','c'), partition p1 values in ('b','d')); +insert into t (a) values ('aaa'),('abc'),('acd'); +select a from t partition (p0) order by a; +select * from t where a = 'abc' order by a; +update t set a='bbb' where a = 'aaa'; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 'bbb' order by a; +drop table if exists t; +create table t (a varchar(10), b varchar(1) GENERATED ALWAYS AS (substr(a,1,1)) STORED, index idx(a)) partition by list columns(b) (partition p0 values in ('a','c'), partition p1 values in ('b','d')); +insert into t (a) values ('aaa'),('abc'),('acd'); +select a from t partition (p0) order by a; +select * from t where a = 'abc' order by a; +update t set a='bbb' where a = 'aaa'; +select a from t partition (p0) order by a; +select a from t partition (p1) order by a; +select * from t where a = 'bbb' order by a; +drop table if exists t; +set @@session.tidb_enable_list_partition = default; + +# TestIssue22496 +drop table if exists t12; +create table t12(d decimal(15,2)); +--error 1366 +insert into t12 values('1,9999.00'); +set sql_mode=''; +insert into t12 values('1,999.00'); +SELECT * FROM t12; +drop table t12; +set sql_mode=default; + +# TestIssue21232 +drop table if exists t, t1; +create table t(a varchar(1), index idx(a)); +create table t1(a varchar(5), index idx(a)); +insert into t values('a'), ('b'); +insert into t1 values('a'), ('bbbbb'); +--enable_warnings +update /*+ INL_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a; +--disable_warnings +select * from t; +--enable_warnings +update /*+ INL_HASH_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a; +--disable_warnings +select * from t; +--enable_warnings +update /*+ INL_MERGE_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a; +--disable_warnings +select * from t; +drop table if exists t, t1; + +# TestIssue20724 +drop table if exists t1; +create table t1(a varchar(10) collate utf8mb4_general_ci); +insert into t1 values ('a'); +update t1 set a = 'A'; +select * from t1; +drop table t1; + +# TestIssue20840 +drop table if exists t1; +set @@tidb_enable_clustered_index = 'int_only'; +create table t1 (i varchar(20) unique key) collate=utf8mb4_general_ci; +insert into t1 values ('a'); +replace into t1 values ('A'); +select * from t1; +drop table t1; + +# TestIssueInsertPrefixIndexForNonUTF8Collation +drop table if exists t1, t2, t3; +create table t1 ( c_int int, c_str varchar(40) character set ascii collate ascii_bin, primary key(c_int, c_str(8)) clustered , unique key(c_str)); +create table t2 ( c_int int, c_str varchar(40) character set latin1 collate latin1_bin, primary key(c_int, c_str(8)) clustered , unique key(c_str)); +insert into t1 values (3, 'fervent brattain'); +insert into t2 values (3, 'fervent brattain'); +admin check table t1; +admin check table t2; +create table t3 (x varchar(40) CHARACTER SET ascii COLLATE ascii_bin, UNIQUE KEY uk(x(4))); +insert into t3 select 'abc '; +-- error 1062 +insert into t3 select 'abc d'; +drop table if exists t1, t2, t3; + +# TestIssue40066 +drop table if exists t_int; +create table t_int(column1 int, column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +-- error 1264 +insert into t_int(column1) values (99); +set @@sql_mode = ''; +--enable_warnings +insert into t_int(column1) values (99); +--disable_warnings +select * from t_int; +drop table if exists t_float; +create table t_float(column1 float, column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +-- error 1264 +insert into t_float(column1) values (12.95); +set @@sql_mode = ''; +--enable_warnings +insert into t_float(column1) values (12.95); +--disable_warnings +select * from t_float; +drop table if exists t_decimal; +create table t_decimal(column1 decimal(20,10), column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +-- error 1264 +insert into t_decimal(column1) values (123.456e-2); +set @@sql_mode = ''; +--enable_warnings +insert into t_decimal(column1) values (123.456e-2); +--disable_warnings +select * from t_decimal; +drop table if exists t_varchar; +create table t_varchar(column1 varchar(10), column2 int unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +-- error 1264 +insert into t_varchar(column1) values ('87.12'); +set @@sql_mode = ''; +--enable_warnings +insert into t_varchar(column1) values ('87.12'); +--disable_warnings +select * from t_varchar; +drop table if exists t_union; +create table t_union(column1 float, column2 int unsigned generated always as(column1-100), column3 float unsigned generated always as(column1-100)); +set @@sql_mode = DEFAULT; +-- error 1264 +insert into t_union(column1) values (12.95); +set @@sql_mode = ''; +--enable_warnings +insert into t_union(column1) values (12.95); +--disable_warnings +select * from t_union; +set @@sql_mode = default; +drop table t_int, t_float, t_decimal, t_varchar, t_union; + +# TestHandleColumnWithOnUpdateCurrentTimestamp +## Test https://github.com/pingcap/tidb/issues/44565 +drop table if exists t; +create table t (a timestamp on update current_timestamp(0), b int, primary key (a) clustered, key idx (a)); +insert into t values ('2023-06-11 10:00:00', 1); +update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'; +admin check table t; +drop table if exists t;