diff --git a/executor/test/executor/BUILD.bazel b/executor/test/executor/BUILD.bazel index 7671d43abe2fa..2d9a52b367388 100644 --- a/executor/test/executor/BUILD.bazel +++ b/executor/test/executor/BUILD.bazel @@ -14,7 +14,6 @@ go_test( "//ddl", "//domain", "//domain/infosync", - "//errno", "//executor", "//expression", "//infoschema", @@ -41,7 +40,6 @@ go_test( "//testkit/testdata", "//types", "//util", - "//util/dbterror", "//util/memory", "//util/mock", "//util/replayer", diff --git a/executor/test/executor/executor_test.go b/executor/test/executor/executor_test.go index 6ce0d2f59047a..bf2517e89bb6d 100644 --- a/executor/test/executor/executor_test.go +++ b/executor/test/executor/executor_test.go @@ -35,7 +35,6 @@ import ( "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/domain/infosync" - "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -62,7 +61,6 @@ import ( "github.com/pingcap/tidb/testkit/testdata" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util" - "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/replayer" @@ -100,19 +98,6 @@ func checkFileName(s string) bool { return false } -func TestPessimisticSelectForUpdate(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id int primary key, a int)") - tk.MustExec("insert into t values(1, 1)") - tk.MustExec("begin PESSIMISTIC") - tk.MustQuery("select a from t where id=1 for update").Check(testkit.Rows("1")) - tk.MustExec("update t set a=a+1 where id=1") - tk.MustExec("commit") - tk.MustQuery("select a from t where id=1").Check(testkit.Rows("2")) -} - func TestBind(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -129,15 +114,6 @@ func TestBind(t *testing.T) { tk.MustExec("drop session binding for select * from testbind") } -func TestChangePumpAndDrainer(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - // change pump or drainer's state need connect to etcd - // so will meet error "URL scheme must be http, https, unix, or unixs: /tmp/tidb" - tk.MustMatchErrMsg("change pump to node_state ='paused' for node_id 'pump1'", "URL scheme must be http, https, unix, or unixs.*") - tk.MustMatchErrMsg("change drainer to node_state ='paused' for node_id 'drainer1'", "URL scheme must be http, https, unix, or unixs.*") -} - func TestLoadStats(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -602,481 +578,6 @@ func TestSelectStringLiteral(t *testing.T) { require.NoError(t, rs.Close()) } -func TestSelectLimit(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table select_limit(id int not null default 1, name varchar(255), PRIMARY KEY(id));") - // insert data - tk.MustExec("insert INTO select_limit VALUES (1, \"hello\");") - tk.CheckExecResult(1, 0) - tk.MustExec("insert into select_limit values (2, \"hello\");") - tk.CheckExecResult(1, 0) - - tk.MustExec("insert INTO select_limit VALUES (3, \"hello\");") - tk.CheckExecResult(1, 0) - tk.MustExec("insert INTO select_limit VALUES (4, \"hello\");") - tk.CheckExecResult(1, 0) - - tk.MustQuery("select * from select_limit limit 1;").Check(testkit.Rows("1 hello")) - - tk.MustQuery("select id from (select * from select_limit limit 1) k where id != 1;").Check(testkit.Rows()) - - tk.MustQuery("select * from select_limit limit 18446744073709551615 offset 0;").Check(testkit.Rows("1 hello", "2 hello", "3 hello", "4 hello")) - - tk.MustQuery("select * from select_limit limit 18446744073709551615 offset 1;").Check(testkit.Rows("2 hello", "3 hello", "4 hello")) - - tk.MustQuery("select * from select_limit limit 18446744073709551615 offset 3;").Check(testkit.Rows("4 hello")) - - err := tk.ExecToErr("select * from select_limit limit 18446744073709551616 offset 3;") - require.Error(t, err) -} - -func TestSelectOrderBy(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table select_order_test(id int not null default 1, name varchar(255), PRIMARY KEY(id));") - - // insert data - tk.MustExec("insert INTO select_order_test VALUES (1, \"hello\");") - tk.CheckExecResult(1, 0) - tk.MustExec("insert into select_order_test values (2, \"hello\");") - tk.CheckExecResult(1, 0) - - // Test star field - tk.MustQuery("select * from select_order_test where id = 1 order by id limit 1 offset 0;").Check(testkit.Rows("1 hello")) - tk.MustQuery("select id from select_order_test order by id desc limit 1 ").Check(testkit.Rows("2")) - tk.MustQuery("select id from select_order_test order by id + 1 desc limit 1 ").Check(testkit.Rows("2")) - // Test limit - tk.MustQuery("select * from select_order_test order by name, id limit 1 offset 0;").Check(testkit.Rows("1 hello")) - // Test limit - tk.MustQuery("select id as c1, name from select_order_test order by 2, id limit 1 offset 0;").Check(testkit.Rows("1 hello")) - // Test limit overflow - tk.MustQuery("select * from select_order_test order by name, id limit 100 offset 0;").Check(testkit.Rows("1 hello", "2 hello")) - // Test offset overflow - tk.MustQuery("select * from select_order_test order by name, id limit 1 offset 100;").Check(testkit.Rows()) - // Test limit exceeds int range. - tk.MustQuery("select id from select_order_test order by name, id limit 18446744073709551615;").Check(testkit.Rows("1", "2")) - // Test multiple field - tk.MustQuery("select id, name from select_order_test where id = 1 group by id, name limit 1 offset 0;").Check(testkit.Rows("1 hello")) - - // Test limit + order by - for i := 3; i <= 10; i += 1 { - tk.MustExec(fmt.Sprintf("insert INTO select_order_test VALUES (%d, \"zz\");", i)) - } - tk.MustExec("insert INTO select_order_test VALUES (10086, \"hi\");") - for i := 11; i <= 20; i += 1 { - tk.MustExec(fmt.Sprintf("insert INTO select_order_test VALUES (%d, \"hh\");", i)) - } - for i := 21; i <= 30; i += 1 { - tk.MustExec(fmt.Sprintf("insert INTO select_order_test VALUES (%d, \"zz\");", i)) - } - tk.MustExec("insert INTO select_order_test VALUES (1501, \"aa\");") - tk.MustQuery("select * from select_order_test order by name, id limit 1 offset 3;").Check(testkit.Rows("11 hh")) - tk.MustExec("drop table select_order_test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c int, d int)") - tk.MustExec("insert t values (1, 1)") - tk.MustExec("insert t values (1, 2)") - tk.MustExec("insert t values (1, 3)") - tk.MustQuery("select 1-d as d from t order by d;").Check(testkit.Rows("-2", "-1", "0")) - tk.MustQuery("select 1-d as d from t order by d + 1;").Check(testkit.Rows("0", "-1", "-2")) - tk.MustQuery("select t.d from t order by d;").Check(testkit.Rows("1", "2", "3")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int, b int, c int)") - tk.MustExec("insert t values (1, 2, 3)") - tk.MustQuery("select b from (select a,b from t order by a,c) t").Check(testkit.Rows("2")) - tk.MustQuery("select b from (select a,b from t order by a,c limit 1) t").Check(testkit.Rows("2")) - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b int, index idx(a))") - tk.MustExec("insert into t values(1, 1), (2, 2)") - tk.MustQuery("select * from t where 1 order by b").Check(testkit.Rows("1 1", "2 2")) - tk.MustQuery("select * from t where a between 1 and 2 order by a desc").Check(testkit.Rows("2 2", "1 1")) - - // Test double read and topN is pushed down to first read plannercore. - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int primary key, b int, c int, index idx(b))") - tk.MustExec("insert into t values(1, 3, 1)") - tk.MustExec("insert into t values(2, 2, 2)") - tk.MustExec("insert into t values(3, 1, 3)") - tk.MustQuery("select * from t use index(idx) order by a desc limit 1").Check(testkit.Rows("3 1 3")) - - // Test double read which needs to keep order. - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b int, key b (b))") - tk.Session().GetSessionVars().IndexLookupSize = 3 - for i := 0; i < 10; i++ { - tk.MustExec(fmt.Sprintf("insert into t values(%d, %d)", i, 10-i)) - } - tk.MustQuery("select a from t use index(b) order by b").Check(testkit.Rows("9", "8", "7", "6", "5", "4", "3", "2", "1", "0")) -} - -func TestSelectErrorRow(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - require.Error(t, tk.ExecToErr("select row(1, 1) from test")) - require.Error(t, tk.ExecToErr("select * from test group by row(1, 1);")) - require.Error(t, tk.ExecToErr("select * from test order by row(1, 1);")) - require.Error(t, tk.ExecToErr("select * from test having row(1, 1);")) - require.Error(t, tk.ExecToErr("select (select 1, 1) from test;")) - require.Error(t, tk.ExecToErr("select * from test group by (select 1, 1);")) - require.Error(t, tk.ExecToErr("select * from test order by (select 1, 1);")) - require.Error(t, tk.ExecToErr("select * from test having (select 1, 1);")) -} - -func TestIn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t (c1 int primary key, c2 int, key c (c2));`) - for i := 0; i <= 200; i++ { - tk.MustExec(fmt.Sprintf("insert t values(%d, %d)", i, i)) - } - queryStr := `select c2 from t where c1 in ('7', '10', '112', '111', '98', '106', '100', '9', '18', '17') order by c2` - tk.MustQuery(queryStr).Check(testkit.Rows("7", "9", "10", "17", "18", "98", "100", "106", "111", "112")) - - queryStr = `select c2 from t where c1 in ('7a')` - tk.MustQuery(queryStr).Check(testkit.Rows("7")) -} - -func TestTablePKisHandleScan(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int PRIMARY KEY AUTO_INCREMENT)") - tk.MustExec("insert t values (),()") - tk.MustExec("insert t values (-100),(0)") - - tests := []struct { - sql string - result [][]interface{} - }{ - { - "select * from t", - testkit.Rows("-100", "1", "2", "3"), - }, - { - "select * from t where a = 1", - testkit.Rows("1"), - }, - { - "select * from t where a != 1", - testkit.Rows("-100", "2", "3"), - }, - { - "select * from t where a >= '1.1'", - testkit.Rows("2", "3"), - }, - { - "select * from t where a < '1.1'", - testkit.Rows("-100", "1"), - }, - { - "select * from t where a > '-100.1' and a < 2", - testkit.Rows("-100", "1"), - }, - { - "select * from t where a is null", - testkit.Rows(), - }, { - "select * from t where a is true", - testkit.Rows("-100", "1", "2", "3"), - }, { - "select * from t where a is false", - testkit.Rows(), - }, - { - "select * from t where a in (1, 2)", - testkit.Rows("1", "2"), - }, - { - "select * from t where a between 1 and 2", - testkit.Rows("1", "2"), - }, - } - - for _, tt := range tests { - tk.MustQuery(tt.sql).Check(tt.result) - } -} - -func TestDefaultNull(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int primary key auto_increment, b int default 1, c int)") - tk.MustExec("insert t values ()") - tk.MustQuery("select * from t").Check(testkit.Rows("1 1 ")) - tk.MustExec("update t set b = NULL where a = 1") - tk.MustQuery("select * from t").Check(testkit.Rows("1 ")) - tk.MustExec("update t set c = 1") - tk.MustQuery("select * from t ").Check(testkit.Rows("1 1")) - tk.MustExec("delete from t where a = 1") - tk.MustExec("insert t (a) values (1)") - tk.MustQuery("select * from t").Check(testkit.Rows("1 1 ")) -} - -func TestJSON(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists test_json") - tk.MustExec("create table test_json (id int, a json)") - tk.MustExec(`insert into test_json (id, a) values (1, '{"a":[1,"2",{"aa":"bb"},4],"b":true}')`) - tk.MustExec(`insert into test_json (id, a) values (2, "null")`) - tk.MustExec(`insert into test_json (id, a) values (3, null)`) - tk.MustExec(`insert into test_json (id, a) values (4, 'true')`) - tk.MustExec(`insert into test_json (id, a) values (5, '3')`) - tk.MustExec(`insert into test_json (id, a) values (5, '4.0')`) - tk.MustExec(`insert into test_json (id, a) values (6, '"string"')`) - - tk.MustQuery(`select tj.a from test_json tj order by tj.id`).Check(testkit.Rows(`{"a": [1, "2", {"aa": "bb"}, 4], "b": true}`, "null", "", "true", "3", "4", `"string"`)) - - // Check json_type function - tk.MustQuery(`select json_type(a) from test_json tj order by tj.id`).Check(testkit.Rows("OBJECT", "NULL", "", "BOOLEAN", "INTEGER", "DOUBLE", "STRING")) - - // Check json compare with primitives. - tk.MustQuery(`select a from test_json tj where a = 3`).Check(testkit.Rows("3")) - tk.MustQuery(`select a from test_json tj where a = 4.0`).Check(testkit.Rows("4")) - tk.MustQuery(`select a from test_json tj where a = true`).Check(testkit.Rows("true")) - tk.MustQuery(`select a from test_json tj where a = "string"`).Check(testkit.Rows(`"string"`)) - - // Check cast(true/false as JSON). - tk.MustQuery(`select cast(true as JSON)`).Check(testkit.Rows(`true`)) - tk.MustQuery(`select cast(false as JSON)`).Check(testkit.Rows(`false`)) - - // Check two json grammar sugar. - tk.MustQuery(`select a->>'$.a[2].aa' as x, a->'$.b' as y from test_json having x is not null order by id`).Check(testkit.Rows(`bb true`)) - tk.MustQuery(`select a->'$.a[2].aa' as x, a->>'$.b' as y from test_json having x is not null order by id`).Check(testkit.Rows(`"bb" true`)) - - // Check some DDL limits for TEXT/BLOB/JSON column. - tk.MustGetErrCode(`create table test_bad_json(a json default '{}')`, mysql.ErrBlobCantHaveDefault) - tk.MustGetErrCode(`create table test_bad_json(a blob default 'hello')`, mysql.ErrBlobCantHaveDefault) - tk.MustGetErrCode(`create table test_bad_json(a text default 'world')`, mysql.ErrBlobCantHaveDefault) - - // check json fields cannot be used as key. - tk.MustGetErrCode(`create table test_bad_json(id int, a json, key (a))`, mysql.ErrJSONUsedAsKey) - - // check CAST AS JSON. - tk.MustQuery(`select CAST('3' AS JSON), CAST('{}' AS JSON), CAST(null AS JSON)`).Check(testkit.Rows(`3 {} `)) - //nolint:revive,all_revive - tk.MustQuery("select a, count(1) from test_json group by a order by a").Check(testkit.Rows( - " 1", - "null 1", - "3 1", - "4 1", - `"string" 1`, - "{\"a\": [1, \"2\", {\"aa\": \"bb\"}, 4], \"b\": true} 1", - "true 1")) - - // Check cast json to decimal. - tk.MustExec("drop table if exists test_json") - tk.MustExec("create table test_json ( a decimal(60,2) as (JSON_EXTRACT(b,'$.c')), b json );") - tk.MustExec(`insert into test_json (b) values - ('{"c": "1267.1"}'), - ('{"c": "1267.01"}'), - ('{"c": "1267.1234"}'), - ('{"c": "1267.3456"}'), - ('{"c": "1234567890123456789012345678901234567890123456789012345"}'), - ('{"c": "1234567890123456789012345678901234567890123456789012345.12345"}');`) - - tk.MustQuery("select a from test_json;").Check(testkit.Rows("1267.10", "1267.01", "1267.12", - "1267.35", "1234567890123456789012345678901234567890123456789012345.00", - "1234567890123456789012345678901234567890123456789012345.12")) -} - -func TestGeneratedColumnWrite(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustGetErrMsg(`CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (a+8) virtual)`, dbterror.ErrGeneratedColumnRefAutoInc.GenWithStackByArgs("c").Error()) - tk.MustExec(`CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (b+8) virtual)`) - tk.MustExec(`CREATE TABLE test_gc_write_1 (a int primary key, b int, c int)`) - - tests := []struct { - stmt string - err int - }{ - // Can't modify generated column by values. - {`insert into test_gc_write (a, b, c) values (1, 1, 1)`, mysql.ErrBadGeneratedColumn}, - {`insert into test_gc_write values (1, 1, 1)`, mysql.ErrBadGeneratedColumn}, - // Can't modify generated column by select clause. - {`insert into test_gc_write select 1, 1, 1`, mysql.ErrBadGeneratedColumn}, - // Can't modify generated column by on duplicate clause. - {`insert into test_gc_write (a, b) values (1, 1) on duplicate key update c = 1`, mysql.ErrBadGeneratedColumn}, - // Can't modify generated column by set. - {`insert into test_gc_write set a = 1, b = 1, c = 1`, mysql.ErrBadGeneratedColumn}, - // Can't modify generated column by update clause. - {`update test_gc_write set c = 1`, mysql.ErrBadGeneratedColumn}, - // Can't modify generated column by multi-table update clause. - {`update test_gc_write, test_gc_write_1 set test_gc_write.c = 1`, mysql.ErrBadGeneratedColumn}, - - // Can insert without generated columns. - {`insert into test_gc_write (a, b) values (1, 1)`, 0}, - {`insert into test_gc_write set a = 2, b = 2`, 0}, - {`insert into test_gc_write (b) select c from test_gc_write`, 0}, - // Can update without generated columns. - {`update test_gc_write set b = 2 where a = 2`, 0}, - {`update test_gc_write t1, test_gc_write_1 t2 set t1.b = 3, t2.b = 4`, 0}, - - // But now we can't do this, just as same with MySQL 5.7: - {`insert into test_gc_write values (1, 1)`, mysql.ErrWrongValueCountOnRow}, - {`insert into test_gc_write select 1, 1`, mysql.ErrWrongValueCountOnRow}, - {`insert into test_gc_write (c) select a, b from test_gc_write`, mysql.ErrWrongValueCountOnRow}, - {`insert into test_gc_write (b, c) select a, b from test_gc_write`, mysql.ErrBadGeneratedColumn}, - } - for _, tt := range tests { - if tt.err != 0 { - tk.MustGetErrCode(tt.stmt, tt.err) - } else { - tk.MustExec(tt.stmt) - } - } -} - -// TestGeneratedColumnRead tests select generated columns from table. -// They should be calculated from their generation expressions. -func TestGeneratedColumnRead(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`CREATE TABLE test_gc_read(a int primary key, b int, c int as (a+b), d int as (a*b) stored, e int as (c*2))`) - - tk.MustQuery(`SELECT generation_expression FROM information_schema.columns WHERE table_name = 'test_gc_read' AND column_name = 'd'`).Check(testkit.Rows("`a` * `b`")) - - // Insert only column a and b, leave c and d be calculated from them. - tk.MustExec(`INSERT INTO test_gc_read (a, b) VALUES (0,null),(1,2),(3,4)`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 2 3 2 6`, `3 4 7 12 14`)) - - tk.MustExec(`INSERT INTO test_gc_read SET a = 5, b = 10`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 2 3 2 6`, `3 4 7 12 14`, `5 10 15 50 30`)) - - tk.MustExec(`REPLACE INTO test_gc_read (a, b) VALUES (5, 6)`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 2 3 2 6`, `3 4 7 12 14`, `5 6 11 30 22`)) - - tk.MustExec(`INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE b = 9`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 2 3 2 6`, `3 4 7 12 14`, `5 9 14 45 28`)) - - // Test select only-generated-column-without-dependences. - tk.MustQuery(`SELECT c, d FROM test_gc_read`).Check(testkit.Rows(` `, `3 2`, `7 12`, `14 45`)) - - // Test select only virtual generated column that refers to other virtual generated columns. - tk.MustQuery(`SELECT e FROM test_gc_read`).Check(testkit.Rows(``, `6`, `14`, `28`)) - - // Test order of on duplicate key update list. - tk.MustExec(`INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE a = 6, b = a`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 2 3 2 6`, `3 4 7 12 14`, `6 6 12 36 24`)) - - tk.MustExec(`INSERT INTO test_gc_read (a, b) VALUES (6, 8) ON DUPLICATE KEY UPDATE b = 8, a = b`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 2 3 2 6`, `3 4 7 12 14`, `8 8 16 64 32`)) - - // Test where-conditions on virtual/stored generated columns. - tk.MustQuery(`SELECT * FROM test_gc_read WHERE c = 7`).Check(testkit.Rows(`3 4 7 12 14`)) - - tk.MustQuery(`SELECT * FROM test_gc_read WHERE d = 64`).Check(testkit.Rows(`8 8 16 64 32`)) - - tk.MustQuery(`SELECT * FROM test_gc_read WHERE e = 6`).Check(testkit.Rows(`1 2 3 2 6`)) - - // Test update where-conditions on virtual/generated columns. - tk.MustExec(`UPDATE test_gc_read SET a = a + 100 WHERE c = 7`) - tk.MustQuery(`SELECT * FROM test_gc_read WHERE c = 107`).Check(testkit.Rows(`103 4 107 412 214`)) - - // Test update where-conditions on virtual/generated columns. - tk.MustExec(`UPDATE test_gc_read m SET m.a = m.a + 100 WHERE c = 107`) - tk.MustQuery(`SELECT * FROM test_gc_read WHERE c = 207`).Check(testkit.Rows(`203 4 207 812 414`)) - - tk.MustExec(`UPDATE test_gc_read SET a = a - 200 WHERE d = 812`) - tk.MustQuery(`SELECT * FROM test_gc_read WHERE d = 12`).Check(testkit.Rows(`3 4 7 12 14`)) - - tk.MustExec(`INSERT INTO test_gc_read set a = 4, b = d + 1`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 2 3 2 6`, `3 4 7 12 14`, - `4 `, `8 8 16 64 32`)) - tk.MustExec(`DELETE FROM test_gc_read where a = 4`) - - // Test on-conditions on virtual/stored generated columns. - tk.MustExec(`CREATE TABLE test_gc_help(a int primary key, b int, c int, d int, e int)`) - tk.MustExec(`INSERT INTO test_gc_help(a, b, c, d, e) SELECT * FROM test_gc_read`) - - tk.MustQuery(`SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.c = t2.c ORDER BY t1.a`).Check(testkit.Rows(`1 2 3 2 6`, `3 4 7 12 14`, `8 8 16 64 32`)) - - tk.MustQuery(`SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.d = t2.d ORDER BY t1.a`).Check(testkit.Rows(`1 2 3 2 6`, `3 4 7 12 14`, `8 8 16 64 32`)) - - tk.MustQuery(`SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.e = t2.e ORDER BY t1.a`).Check(testkit.Rows(`1 2 3 2 6`, `3 4 7 12 14`, `8 8 16 64 32`)) - - // Test generated column in subqueries. - tk.MustQuery(`SELECT * FROM test_gc_read t WHERE t.a not in (SELECT t.a FROM test_gc_read t where t.c > 5)`).Sort().Check(testkit.Rows(`0 `, `1 2 3 2 6`)) - tk.MustQuery(`SELECT * FROM test_gc_read t WHERE t.c in (SELECT t.c FROM test_gc_read t where t.c > 5)`).Sort().Check(testkit.Rows(`3 4 7 12 14`, `8 8 16 64 32`)) - - tk.MustQuery(`SELECT tt.b FROM test_gc_read tt WHERE tt.a = (SELECT max(t.a) FROM test_gc_read t WHERE t.c = tt.c) ORDER BY b`).Check(testkit.Rows(`2`, `4`, `8`)) - - // Test aggregation on virtual/stored generated columns. - tk.MustQuery(`SELECT c, sum(a) aa, max(d) dd, sum(e) ee FROM test_gc_read GROUP BY c ORDER BY aa`).Check(testkit.Rows(` 0 `, `3 1 2 6`, `7 3 12 14`, `16 8 64 32`)) - - tk.MustQuery(`SELECT a, sum(c), sum(d), sum(e) FROM test_gc_read GROUP BY a ORDER BY a`).Check(testkit.Rows(`0 `, `1 3 2 6`, `3 7 12 14`, `8 16 64 32`)) - - // Test multi-update on generated columns. - tk.MustExec(`UPDATE test_gc_read m, test_gc_read n SET m.b = m.b + 10, n.b = n.b + 10`) - tk.MustQuery(`SELECT * FROM test_gc_read ORDER BY a`).Check(testkit.Rows(`0 `, `1 12 13 12 26`, `3 14 17 42 34`, `8 18 26 144 52`)) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - tk.MustExec("insert into t values(8)") - tk.MustExec("update test_gc_read set a = a+1 where a in (select a from t)") - tk.MustQuery("select * from test_gc_read order by a").Check(testkit.Rows(`0 `, `1 12 13 12 26`, `3 14 17 42 34`, `9 18 27 162 54`)) - - // Test different types between generation expression and generated column. - tk.MustExec(`CREATE TABLE test_gc_read_cast(a VARCHAR(255), b VARCHAR(255), c INT AS (JSON_EXTRACT(a, b)), d INT AS (JSON_EXTRACT(a, b)) STORED)`) - tk.MustExec(`INSERT INTO test_gc_read_cast (a, b) VALUES ('{"a": "3"}', '$.a')`) - tk.MustQuery(`SELECT c, d FROM test_gc_read_cast`).Check(testkit.Rows(`3 3`)) - - tk.MustExec(`CREATE TABLE test_gc_read_cast_1(a VARCHAR(255), b VARCHAR(255), c ENUM("red", "yellow") AS (JSON_UNQUOTE(JSON_EXTRACT(a, b))))`) - tk.MustExec(`INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "yellow"}', '$.a')`) - tk.MustQuery(`SELECT c FROM test_gc_read_cast_1`).Check(testkit.Rows(`yellow`)) - - tk.MustExec(`CREATE TABLE test_gc_read_cast_2( a JSON, b JSON AS (a->>'$.a'))`) - tk.MustExec(`INSERT INTO test_gc_read_cast_2(a) VALUES ('{"a": "{ \\\"key\\\": \\\"\\u6d4b\\\" }"}')`) - tk.MustQuery(`SELECT b FROM test_gc_read_cast_2`).Check(testkit.Rows(`{"key": "测"}`)) - - tk.MustExec(`CREATE TABLE test_gc_read_cast_3( a JSON, b JSON AS (a->>'$.a'), c INT AS (b * 3.14) )`) - tk.MustExec(`INSERT INTO test_gc_read_cast_3(a) VALUES ('{"a": "5"}')`) - tk.MustQuery(`SELECT c FROM test_gc_read_cast_3`).Check(testkit.Rows(`16`)) - - require.Error(t, tk.ExecToErr(`INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "invalid"}', '$.a')`)) - - // Test read generated columns after drop some irrelevant column - tk.MustExec(`DROP TABLE IF EXISTS test_gc_read_m`) - tk.MustExec(`CREATE TABLE test_gc_read_m (a int primary key, b int, c int as (a+1), d int as (c*2))`) - tk.MustExec(`INSERT INTO test_gc_read_m(a) values (1), (2)`) - tk.MustExec(`ALTER TABLE test_gc_read_m DROP b`) - tk.MustQuery(`SELECT * FROM test_gc_read_m`).Check(testkit.Rows(`1 2 4`, `2 3 6`)) - - // Test not null generated columns. - tk.MustExec(`CREATE TABLE test_gc_read_1(a int primary key, b int, c int as (a+b) not null, d int as (a*b) stored)`) - tk.MustExec(`CREATE TABLE test_gc_read_2(a int primary key, b int, c int as (a+b), d int as (a*b) stored not null)`) - tests := []struct { - stmt string - err int - }{ - // Can't insert these records, because generated columns are not null. - {`insert into test_gc_read_1(a, b) values (1, null)`, mysql.ErrBadNull}, - {`insert into test_gc_read_2(a, b) values (1, null)`, mysql.ErrBadNull}, - } - for _, tt := range tests { - if tt.err != 0 { - tk.MustGetErrCode(tt.stmt, tt.err) - } else { - tk.MustExec(tt.stmt) - } - } -} - func TestUpdateClustered(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1245,80 +746,6 @@ func TestUpdateClustered(t *testing.T) { } } -func TestSelectPartition(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(`create table th (a int, b int) partition by hash(a) partitions 3;`) - tk.MustExec(`create table tr (a int, b int) - partition by range (a) ( - partition r0 values less than (4), - partition r1 values less than (7), - partition r3 values less than maxvalue)`) - tk.MustExec(`create table tl (a int, b int, unique index idx(a)) partition by list (a) ( - 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));`) - tk.MustExec(`insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);`) - tk.MustExec("insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8);") - tk.MustExec(`insert into tr values (-3,-3),(3,3),(4,4),(7,7),(8,8);`) - tk.MustExec(`insert into tl values (3,3),(1,1),(4,4),(7,7),(8,8),(null,null);`) - // select 1 partition. - tk.MustQuery("select b from th partition (p0) order by a").Check(testkit.Rows("-6", "-3", "0", "3", "6")) - tk.MustQuery("select b from tr partition (r0) order by a").Check(testkit.Rows("-3", "3")) - tk.MustQuery("select b from tl partition (p0) order by a").Check(testkit.Rows("3")) - tk.MustQuery("select b from th partition (p0,P0) order by a").Check(testkit.Rows("-6", "-3", "0", "3", "6")) - tk.MustQuery("select b from tr partition (r0,R0,r0) order by a").Check(testkit.Rows("-3", "3")) - tk.MustQuery("select b from tl partition (p0,P0,p0) order by a").Check(testkit.Rows("3")) - // select multi partition. - tk.MustQuery("select b from th partition (P2,p0) order by a").Check(testkit.Rows("-8", "-6", "-5", "-3", "-2", "0", "2", "3", "5", "6", "8")) - tk.MustQuery("select b from tr partition (r1,R3) order by a").Check(testkit.Rows("4", "7", "8")) - tk.MustQuery("select b from tl partition (p0,P3) order by a").Check(testkit.Rows("", "3", "7", "8")) - - // test select unknown partition error - tk.MustGetErrMsg("select b from th partition (p0,p4)", "[table:1735]Unknown partition 'p4' in table 'th'") - tk.MustGetErrMsg("select b from tr partition (r1,r4)", "[table:1735]Unknown partition 'r4' in table 'tr'") - tk.MustGetErrMsg("select b from tl partition (p0,p4)", "[table:1735]Unknown partition 'p4' in table 'tl'") - - // test select partition table in transaction. - tk.MustExec("begin") - tk.MustExec("insert into th values (10,10),(11,11)") - tk.MustQuery("select a, b from th where b>10").Check(testkit.Rows("11 11")) - tk.MustExec("commit") - tk.MustQuery("select a, b from th where b>10").Check(testkit.Rows("11 11")) - - // test partition function is scalar func - tk.MustExec("drop table if exists tscalar") - tk.MustExec(`create table tscalar (c1 int) partition by range (c1 % 30) ( - partition p0 values less than (0), - partition p1 values less than (10), - partition p2 values less than (20), - partition pm values less than (maxvalue));`) - tk.MustExec("insert into tscalar values(0), (10), (40), (50), (55)") - // test IN expression - tk.MustExec("insert into tscalar values(-0), (-10), (-40), (-50), (-55)") - tk.MustQuery("select * from tscalar where c1 in (55, 55)").Check(testkit.Rows("55")) - tk.MustQuery("select * from tscalar where c1 in (40, 40)").Check(testkit.Rows("40")) - tk.MustQuery("select * from tscalar where c1 in (40)").Check(testkit.Rows("40")) - tk.MustQuery("select * from tscalar where c1 in (-40)").Check(testkit.Rows("-40")) - tk.MustQuery("select * from tscalar where c1 in (-40, -40)").Check(testkit.Rows("-40")) - tk.MustQuery("select * from tscalar where c1 in (-1)").Check(testkit.Rows()) -} - -func TestPrepareLoadData(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustGetErrCode(`prepare stmt from "load data local infile '/tmp/load_data_test.csv' into table test";`, mysql.ErrUnsupportedPs) -} - -func TestPrepareImportInto(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustGetErrCode(`prepare stmt from "import into test from 'xx' format 'delimited'";`, mysql.ErrUnsupportedPs) -} - func TestClusterIndexOuterJoinElimination(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1412,32 +839,6 @@ func TestNotFillCacheFlag(t *testing.T) { require.Equal(t, len(tests), count) // Make sure the hook function is called. } -func TestHandleTransfer(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int, index idx(a))") - tk.MustExec("insert into t values(1), (2), (4)") - tk.MustExec("begin") - tk.MustExec("update t set a = 3 where a = 4") - // test table scan read whose result need handle. - tk.MustQuery("select * from t ignore index(idx)").Check(testkit.Rows("1", "2", "3")) - tk.MustExec("insert into t values(4)") - // test single read whose result need handle - tk.MustQuery("select * from t use index(idx)").Check(testkit.Rows("1", "2", "3", "4")) - tk.MustQuery("select * from t use index(idx) order by a desc").Check(testkit.Rows("4", "3", "2", "1")) - tk.MustExec("update t set a = 5 where a = 3") - tk.MustQuery("select * from t use index(idx)").Check(testkit.Rows("1", "2", "4", "5")) - tk.MustExec("commit") - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b int, index idx(a))") - tk.MustExec("insert into t values(3, 3), (1, 1), (2, 2)") - // Second test double read. - tk.MustQuery("select * from t use index(idx) order by a").Check(testkit.Rows("1 1", "2 2", "3 3")) -} - func TestExecutorBit(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1501,70 +902,6 @@ func TestExecutorBit(t *testing.T) { tk.MustQuery("select * from t where c1").Check(testkit.Rows("\xff\xff\xff\xff\xff\xff\xff\xff", "12345678")) } -// TestMaxInt64Handle Issue #4810 -func TestMaxInt64Handle(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id bigint, PRIMARY KEY (id))") - tk.MustExec("insert into t values(9223372036854775807)") - tk.MustExec("select * from t where id = 9223372036854775807") - tk.MustQuery("select * from t where id = 9223372036854775807;").Check(testkit.Rows("9223372036854775807")) - tk.MustQuery("select * from t").Check(testkit.Rows("9223372036854775807")) - err := tk.ExecToErr("insert into t values(9223372036854775807)") - require.Error(t, err) - tk.MustExec("delete from t where id = 9223372036854775807") - tk.MustQuery("select * from t").Check(nil) -} - -func TestUnsignedPk(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id bigint unsigned primary key)") - var num1, num2 uint64 = math.MaxInt64 + 1, math.MaxInt64 + 2 - tk.MustExec(fmt.Sprintf("insert into t values(%v), (%v), (1), (2)", num1, num2)) - num1Str := strconv.FormatUint(num1, 10) - num2Str := strconv.FormatUint(num2, 10) - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1", "2", num1Str, num2Str)) - tk.MustQuery("select * from t where id not in (2)").Check(testkit.Rows(num1Str, num2Str, "1")) - tk.MustExec("drop table t") - tk.MustExec("create table t(a bigint unsigned primary key, b int, index idx(b))") - tk.MustExec("insert into t values(9223372036854775808, 1), (1, 1)") - tk.MustQuery("select * from t use index(idx) where b = 1 and a < 2").Check(testkit.Rows("1 1")) - tk.MustQuery("select * from t use index(idx) where b = 1 order by b, a").Check(testkit.Rows("1 1", "9223372036854775808 1")) -} - -func TestSignedCommonHandle(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - tk.MustExec("use test") - tk.MustExec("create table t(k1 int, k2 int, primary key(k1, k2))") - tk.MustExec("insert into t(k1, k2) value(-100, 1), (-50, 1), (0, 0), (1, 1), (3, 3)") - tk.MustQuery("select k1 from t order by k1").Check(testkit.Rows("-100", "-50", "0", "1", "3")) - tk.MustQuery("select k1 from t order by k1 desc").Check(testkit.Rows("3", "1", "0", "-50", "-100")) - tk.MustQuery("select k1 from t where k1 < -51").Check(testkit.Rows("-100")) - tk.MustQuery("select k1 from t where k1 < -1").Check(testkit.Rows("-100", "-50")) - tk.MustQuery("select k1 from t where k1 <= 0").Check(testkit.Rows("-100", "-50", "0")) - tk.MustQuery("select k1 from t where k1 < 2").Check(testkit.Rows("-100", "-50", "0", "1")) - tk.MustQuery("select k1 from t where k1 < -1 and k1 > -90").Check(testkit.Rows("-50")) -} - -func TestContainDotColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table test.t1(t1.a char)") - tk.MustExec("create table t2(a char, t2.b int)") - - tk.MustGetErrCode("create table t3(s.a char);", mysql.ErrWrongTableName) -} - func TestCheckIndex(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) @@ -1683,35 +1020,6 @@ func setColValue(t *testing.T, txn kv.Transaction, key kv.Key, v types.Datum) { require.NoError(t, err) } -func TestCheckTableClusterIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - tk.MustExec("use test;") - tk.MustExec("drop table if exists admin_test;") - tk.MustExec("create table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1, c2), index (c1), unique key(c2));") - tk.MustExec("insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") - tk.MustExec("admin check table admin_test;") -} - -func TestIncorrectLimitArg(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test;`) - tk.MustExec(`create table t(a bigint);`) - tk.MustExec(`prepare stmt1 from 'select * from t limit ?';`) - tk.MustExec(`prepare stmt2 from 'select * from t limit ?, ?';`) - tk.MustExec(`set @a = -1;`) - tk.MustExec(`set @b = 1;`) - - tk.MustGetErrMsg(`execute stmt1 using @a;`, `[planner:1210]Incorrect arguments to LIMIT`) - tk.MustGetErrMsg(`execute stmt2 using @b, @a;`, `[planner:1210]Incorrect arguments to LIMIT`) - tk.MustGetErrMsg(`execute stmt2 using @a, @b;`, `[planner:1210]Incorrect arguments to LIMIT`) - tk.MustGetErrMsg(`execute stmt2 using @a, @a;`, `[planner:1210]Incorrect arguments to LIMIT`) -} - func TestTimestampTimeZone(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2122,37 +1430,6 @@ func TestSelectForUpdateOf(t *testing.T) { tk1.MustExec("rollback") } -func TestEmptyEnum(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (e enum('Y', 'N'))") - tk.MustExec("set sql_mode='STRICT_TRANS_TABLES'") - err := tk.ExecToErr("insert into t values (0)") - require.True(t, terror.ErrorEqual(err, types.ErrTruncated), fmt.Sprintf("err: %v", err)) - err = tk.ExecToErr("insert into t values ('abc')") - require.True(t, terror.ErrorEqual(err, types.ErrTruncated), fmt.Sprintf("err: %v", err)) - - tk.MustExec("set sql_mode=''") - tk.MustExec("insert into t values (0)") - tk.MustQuery("select * from t").Check(testkit.Rows("")) - tk.MustExec("insert into t values ('abc')") - tk.MustQuery("select * from t").Check(testkit.Rows("", "")) - tk.MustExec("insert into t values (null)") - tk.MustQuery("select * from t").Check(testkit.Rows("", "", "")) - - // Test https://github.com/pingcap/tidb/issues/29525. - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t (id int auto_increment primary key, c1 enum('a', '', 'c'));") - tk.MustExec("insert into t(c1) values (0);") - tk.MustQuery("select id, c1+0, c1 from t;").Check(testkit.Rows("1 0 ")) - tk.MustExec("alter table t change c1 c1 enum('a', '') not null;") - tk.MustQuery("select id, c1+0, c1 from t;").Check(testkit.Rows("1 0 ")) - tk.MustExec("insert into t(c1) values (0);") - tk.MustQuery("select id, c1+0, c1 from t;").Check(testkit.Rows("1 0 ", "2 0 ")) -} - func TestPartitionHashCode(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2211,87 +1488,6 @@ func TestInsertValuesWithSubQuery(t *testing.T) { "Insert's SET operation or VALUES_LIST doesn't support complex subqueries now") } -func TestDIVZeroInPartitionExpr(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("create table t1(a int) partition by range (10 div a) (partition p0 values less than (10), partition p1 values less than maxvalue)") - - tk.MustExec("set @@sql_mode=''") - tk.MustExec("insert into t1 values (NULL), (0), (1)") - tk.MustExec("set @@sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO'") - tk.MustGetErrCode("insert into t1 values (NULL), (0), (1)", mysql.ErrDivisionByZero) -} - -func TestInsertIntoGivenPartitionSet(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec(`create table t1( - a int(11) DEFAULT NULL, - b varchar(10) DEFAULT NULL, - UNIQUE KEY idx_a (a)) PARTITION BY RANGE (a) - (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, - PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, - PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, - PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, - PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB)`) - - // insert into - tk.MustExec("insert into t1 partition(p0) values(1, 'a'), (2, 'b')") - tk.MustQuery("select * from t1 partition(p0) order by a").Check(testkit.Rows("1 a", "2 b")) - tk.MustExec("insert into t1 partition(p0, p1) values(3, 'c'), (4, 'd')") - tk.MustQuery("select * from t1 partition(p1)").Check(testkit.Rows()) - - tk.MustGetErrMsg("insert into t1 values(1, 'a')", "[kv:1062]Duplicate entry '1' for key 't1.idx_a'") - tk.MustGetErrMsg("insert into t1 partition(p0, p_non_exist) values(1, 'a')", "[table:1735]Unknown partition 'p_non_exist' in table 't1'") - tk.MustGetErrMsg("insert into t1 partition(p0, p1) values(40, 'a')", "[table:1748]Found a row not matching the given partition set") - - // replace into - tk.MustExec("replace into t1 partition(p0) values(1, 'replace')") - tk.MustExec("replace into t1 partition(p0, p1) values(3, 'replace'), (4, 'replace')") - tk.MustExec("replace into t1 values(1, 'a')") - tk.MustQuery("select * from t1 partition (p0) order by a").Check(testkit.Rows("1 a", "2 b", "3 replace", "4 replace")) - - tk.MustGetErrMsg("replace into t1 partition(p0, p_non_exist) values(1, 'a')", "[table:1735]Unknown partition 'p_non_exist' in table 't1'") - tk.MustGetErrMsg("replace into t1 partition(p0, p1) values(40, 'a')", "[table:1748]Found a row not matching the given partition set") - - tk.MustExec("truncate table t1") - - tk.MustExec("create table t(a int, b char(10))") - - // insert into general table - tk.MustGetErrMsg("insert into t partition(p0, p1) values(1, 'a')", "[planner:1747]PARTITION () clause on non partitioned table") - - // insert into from select - tk.MustExec("insert into t values(1, 'a'), (2, 'b')") - tk.MustExec("insert into t1 partition(p0) select * from t") - tk.MustQuery("select * from t1 partition(p0) order by a").Check(testkit.Rows("1 a", "2 b")) - - tk.MustExec("truncate table t") - tk.MustExec("insert into t values(3, 'c'), (4, 'd')") - tk.MustExec("insert into t1 partition(p0, p1) select * from t") - tk.MustQuery("select * from t1 partition(p1) order by a").Check(testkit.Rows()) - tk.MustQuery("select * from t1 partition(p0) order by a").Check(testkit.Rows("1 a", "2 b", "3 c", "4 d")) - - tk.MustGetErrMsg("insert into t1 select 1, 'a'", "[kv:1062]Duplicate entry '1' for key 't1.idx_a'") - tk.MustGetErrMsg("insert into t1 partition(p0, p_non_exist) select 1, 'a'", "[table:1735]Unknown partition 'p_non_exist' in table 't1'") - tk.MustGetErrMsg("insert into t1 partition(p0, p1) select 40, 'a'", "[table:1748]Found a row not matching the given partition set") - - // replace into from select - tk.MustExec("replace into t1 partition(p0) select 1, 'replace'") - tk.MustExec("truncate table t") - tk.MustExec("insert into t values(3, 'replace'), (4, 'replace')") - tk.MustExec("replace into t1 partition(p0, p1) select * from t") - - tk.MustExec("replace into t1 select 1, 'a'") - tk.MustQuery("select * from t1 partition (p0) order by a").Check(testkit.Rows("1 a", "2 b", "3 replace", "4 replace")) - tk.MustGetErrMsg("replace into t1 partition(p0, p_non_exist) select 1, 'a'", "[table:1735]Unknown partition 'p_non_exist' in table 't1'") - tk.MustGetErrMsg("replace into t1 partition(p0, p1) select 40, 'a'", "[table:1748]Found a row not matching the given partition set") -} - // fix issue https://github.com/pingcap/tidb/issues/32871 func TestBitColumnIn(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2306,61 +1502,6 @@ func TestBitColumnIn(t *testing.T) { "[expression:1582]Incorrect parameter count in the call to native function 'in'") } -func TestUpdateGivenPartitionSet(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec(`create table t1( - a int(11), - b varchar(10) DEFAULT NULL, - primary key idx_a (a)) PARTITION BY RANGE (a) - (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, - PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, - PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, - PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, - PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB)`) - - tk.MustExec(`create table t2( - a int(11) DEFAULT NULL, - b varchar(10) DEFAULT NULL) PARTITION BY RANGE (a) - (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, - PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, - PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, - PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, - PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB)`) - - tk.MustExec(`create table t3 (a int(11), b varchar(10) default null)`) - tk.MustExec("insert into t3 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd')") - tk.MustGetErrMsg( - "update t3 partition(p0) set a = 40 where a = 2", - "[planner:1747]PARTITION () clause on non partitioned table") - - // update with primary key change - tk.MustExec("insert into t1 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd')") - tk.MustGetErrMsg("update t1 partition(p0, p1) set a = 40", "[table:1748]Found a row not matching the given partition set") - tk.MustGetErrMsg("update t1 partition(p0) set a = 40 where a = 2", "[table:1748]Found a row not matching the given partition set") - // test non-exist partition. - tk.MustGetErrMsg("update t1 partition (p0, p_non_exist) set a = 40", "[table:1735]Unknown partition 'p_non_exist' in table 't1'") - // test join. - tk.MustGetErrMsg("update t1 partition (p0), t3 set t1.a = 40 where t3.a = 2", "[table:1748]Found a row not matching the given partition set") - - tk.MustExec("update t1 partition(p0) set a = 3 where a = 2") - tk.MustExec("update t1 partition(p0, p3) set a = 33 where a = 1") - - // update without partition change - tk.MustExec("insert into t2 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd')") - tk.MustGetErrMsg("update t2 partition(p0, p1) set a = 40", "[table:1748]Found a row not matching the given partition set") - tk.MustGetErrMsg("update t2 partition(p0) set a = 40 where a = 2", "[table:1748]Found a row not matching the given partition set") - - tk.MustExec("update t2 partition(p0) set a = 3 where a = 2") - tk.MustExec("update t2 partition(p0, p3) set a = 33 where a = 1") - - tk.MustExec("create table t4(a int primary key, b int) partition by hash(a) partitions 2") - tk.MustExec("insert into t4(a, b) values(1, 1),(2, 2),(3, 3);") - tk.MustGetErrMsg("update t4 partition(p0) set a = 5 where a = 2", "[table:1748]Found a row not matching the given partition set") -} - func TestIndexLookupRuntimeStats(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2445,128 +1586,6 @@ func TestIssue19148(t *testing.T) { require.Zero(t, tblInfo.Meta().Columns[0].GetFlag()) } -func TestIssue19667(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("CREATE TABLE t (a DATETIME)") - tk.MustExec("INSERT INTO t VALUES('1988-04-17 01:59:59')") - tk.MustQuery(`SELECT DATE_ADD(a, INTERVAL 1 SECOND) FROM t`).Check(testkit.Rows("1988-04-17 02:00:00")) -} - -func TestZeroDateTimeCompatibility(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - - sqls := []string{ - `select YEAR(0000-00-00), YEAR("0000-00-00")`, - `select MONTH(0000-00-00), MONTH("0000-00-00")`, - `select DAYOFMONTH(0000-00-00), DAYOFMONTH("0000-00-00")`, - `select QUARTER(0000-00-00), QUARTER("0000-00-00")`, - `select EXTRACT(DAY FROM 0000-00-00), EXTRACT(DAY FROM "0000-00-00")`, - `select EXTRACT(MONTH FROM 0000-00-00), EXTRACT(MONTH FROM "0000-00-00")`, - `select EXTRACT(YEAR FROM 0000-00-00), EXTRACT(YEAR FROM "0000-00-00")`, - `select EXTRACT(WEEK FROM 0000-00-00), EXTRACT(WEEK FROM "0000-00-00")`, - `select EXTRACT(QUARTER FROM 0000-00-00), EXTRACT(QUARTER FROM "0000-00-00")`, - } - for _, sql := range sqls { - tk.MustQuery(sql).Check(testkit.Rows("0 ")) - require.Equal(t, uint16(1), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - } - - sqls = []string{ - `select DAYOFWEEK(0000-00-00), DAYOFWEEK("0000-00-00")`, - `select DAYOFYEAR(0000-00-00), DAYOFYEAR("0000-00-00")`, - } - for _, sql := range sqls { - tk.MustQuery(sql).Check(testkit.Rows(" ")) - require.Equal(t, uint16(2), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - } - - tk.MustExec("use test") - tk.MustExec("create table t(v1 datetime, v2 datetime(3))") - tk.MustExec("insert ignore into t values(0,0)") - - sqls = []string{ - `select YEAR(v1), YEAR(v2) from t`, - `select MONTH(v1), MONTH(v2) from t`, - `select DAYOFMONTH(v1), DAYOFMONTH(v2) from t`, - `select QUARTER(v1), QUARTER(v2) from t`, - `select EXTRACT(DAY FROM v1), EXTRACT(DAY FROM v2) from t`, - `select EXTRACT(MONTH FROM v1), EXTRACT(MONTH FROM v2) from t`, - `select EXTRACT(YEAR FROM v1), EXTRACT(YEAR FROM v2) from t`, - `select EXTRACT(WEEK FROM v1), EXTRACT(WEEK FROM v2) from t`, - `select EXTRACT(QUARTER FROM v1), EXTRACT(QUARTER FROM v2) from t`, - } - for _, sql := range sqls { - tk.MustQuery(sql).Check(testkit.Rows("0 0")) - require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - } - - sqls = []string{ - `select DAYOFWEEK(v1), DAYOFWEEK(v2) from t`, - `select DAYOFYEAR(v1), DAYOFYEAR(v2) from t`, - } - for _, sql := range sqls { - tk.MustQuery(sql).Check(testkit.Rows(" ")) - require.Equal(t, uint16(2), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - } -} - -// https://github.com/pingcap/tidb/issues/24165. -func TestInvalidDateValueInCreateTable(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t;") - - // Test for sql mode 'NO_ZERO_IN_DATE'. - tk.MustExec("set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE';") - tk.MustGetErrCode("create table t (a datetime default '2999-00-00 00:00:00');", errno.ErrInvalidDefault) - tk.MustExec("create table t (a datetime);") - tk.MustGetErrCode("alter table t modify column a datetime default '2999-00-00 00:00:00';", errno.ErrInvalidDefault) - tk.MustExec("drop table if exists t;") - - // Test for sql mode 'NO_ZERO_DATE'. - tk.MustExec("set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE';") - tk.MustGetErrCode("create table t (a datetime default '0000-00-00 00:00:00');", errno.ErrInvalidDefault) - tk.MustExec("create table t (a datetime);") - tk.MustGetErrCode("alter table t modify column a datetime default '0000-00-00 00:00:00';", errno.ErrInvalidDefault) - tk.MustExec("drop table if exists t;") - - // Remove NO_ZERO_DATE and NO_ZERO_IN_DATE. - tk.MustExec("set @@sql_mode='STRICT_TRANS_TABLES';") - // Test create table with zero datetime as a default value. - tk.MustExec("create table t (a datetime default '2999-00-00 00:00:00');") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t (a datetime default '0000-00-00 00:00:00');") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t (a datetime);") - tk.MustExec("alter table t modify column a datetime default '2999-00-00 00:00:00';") - tk.MustExec("alter table t modify column a datetime default '0000-00-00 00:00:00';") - tk.MustExec("drop table if exists t;") - - // Test create table with invalid datetime(02-30) as a default value. - tk.MustExec("set @@sql_mode='STRICT_TRANS_TABLES';") - tk.MustGetErrCode("create table t (a datetime default '2999-02-30 00:00:00');", errno.ErrInvalidDefault) - tk.MustExec("drop table if exists t;") - // NO_ZERO_IN_DATE and NO_ZERO_DATE have nothing to do with invalid datetime(02-30). - tk.MustExec("set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE';") - tk.MustGetErrCode("create table t (a datetime default '2999-02-30 00:00:00');", errno.ErrInvalidDefault) - tk.MustExec("drop table if exists t;") - // ALLOW_INVALID_DATES allows invalid datetime(02-30). - tk.MustExec("set @@sql_mode='STRICT_TRANS_TABLES,ALLOW_INVALID_DATES';") - tk.MustExec("create table t (a datetime default '2999-02-30 00:00:00');") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t (a datetime);") - tk.MustExec("alter table t modify column a datetime default '2999-02-30 00:00:00';") - tk.MustExec("drop table if exists t;") -} - func TestOOMActionPriority(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2850,22 +1869,6 @@ func TestUnreasonablyClose(t *testing.T) { require.Equal(t, opsNeedsCoveredMask, opsAlreadyCoveredMask, fmt.Sprintf("these operators are not covered %s", commentBuf.String())) } -func TestEncodingSet(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `enum-set` (`set` SET(" + - "'x00','x01','x02','x03','x04','x05','x06','x07','x08','x09','x10','x11','x12','x13','x14','x15'," + - "'x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31'," + - "'x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47'," + - "'x48','x49','x50','x51','x52','x53','x54','x55','x56','x57','x58','x59','x60','x61','x62','x63'" + - ")NOT NULL PRIMARY KEY)") - tk.MustExec("INSERT INTO `enum-set` VALUES\n(\"x00,x59\");") - tk.MustQuery("select `set` from `enum-set` use index(PRIMARY)").Check(testkit.Rows("x00,x59")) - tk.MustExec("admin check table `enum-set`") -} - func TestOOMPanicAction(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) @@ -4062,17 +3065,6 @@ func TestStaleReadAtFutureTime(t *testing.T) { require.Zero(t, tk.Session().GetSessionVars().TxnReadTS.PeakTxnReadTS()) } -func TestYearTypeDeleteIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a YEAR, PRIMARY KEY(a));") - tk.MustExec("insert into t set a = '2151';") - tk.MustExec("delete from t;") - tk.MustExec("admin check table t") -} - func TestSQLMode(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -4931,30 +3923,6 @@ func TestMaxOneRow(t *testing.T) { require.NoError(t, rs.Close()) } -func TestRowID(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`drop table if exists t`) - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeIntOnly - tk.MustExec(`create table t(a varchar(10), b varchar(10), c varchar(1), index idx(a, b, c));`) - tk.MustExec(`insert into t values('a', 'b', 'c');`) - tk.MustExec(`insert into t values('a', 'b', 'c');`) - tk.MustQuery(`select b, _tidb_rowid from t use index(idx) where a = 'a';`).Check(testkit.Rows( - `b 1`, - `b 2`, - )) - tk.MustExec(`begin;`) - tk.MustExec(`select * from t for update`) - tk.MustQuery(`select distinct b from t use index(idx) where a = 'a';`).Check(testkit.Rows(`b`)) - tk.MustExec(`commit;`) - - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a varchar(5) primary key)`) - tk.MustExec(`insert into t values('a')`) - tk.MustQuery("select *, _tidb_rowid from t use index(`primary`) where _tidb_rowid=1").Check(testkit.Rows("a 1")) -} - func TestDoSubquery(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -4968,96 +3936,6 @@ func TestDoSubquery(t *testing.T) { require.Nil(t, r) } -func TestSubqueryTableAlias(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`drop table if exists t`) - - tk.MustExec("set sql_mode = ''") - tk.MustGetErrCode("select a, b from (select 1 a) ``, (select 2 b) ``;", mysql.ErrDerivedMustHaveAlias) - tk.MustGetErrCode("select a, b from (select 1 a) `x`, (select 2 b) `x`;", mysql.ErrNonuniqTable) - tk.MustGetErrCode("select a, b from (select 1 a), (select 2 b);", mysql.ErrDerivedMustHaveAlias) - // ambiguous column name - tk.MustGetErrCode("select a from (select 1 a) ``, (select 2 a) ``;", mysql.ErrDerivedMustHaveAlias) - tk.MustGetErrCode("select a from (select 1 a) `x`, (select 2 a) `x`;", mysql.ErrNonuniqTable) - tk.MustGetErrCode("select x.a from (select 1 a) `x`, (select 2 a) `x`;", mysql.ErrNonuniqTable) - tk.MustGetErrCode("select a from (select 1 a), (select 2 a);", mysql.ErrDerivedMustHaveAlias) - - tk.MustExec("set sql_mode = 'oracle';") - tk.MustQuery("select a, b from (select 1 a) ``, (select 2 b) ``;").Check(testkit.Rows("1 2")) - tk.MustQuery("select a, b from (select 1 a) `x`, (select 2 b) `x`;").Check(testkit.Rows("1 2")) - tk.MustQuery("select a, b from (select 1 a), (select 2 b);").Check(testkit.Rows("1 2")) - // ambiguous column name - tk.MustGetErrCode("select a from (select 1 a) ``, (select 2 a) ``;", mysql.ErrNonUniq) - tk.MustGetErrCode("select a from (select 1 a) `x`, (select 2 a) `x`;", mysql.ErrNonUniq) - tk.MustGetErrCode("select x.a from (select 1 a) `x`, (select 2 a) `x`;", mysql.ErrNonUniq) - tk.MustGetErrCode("select a from (select 1 a), (select 2 a);", mysql.ErrNonUniq) -} - -func TestSelectHashPartitionTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`use test`) - tk.MustExec(`drop table if exists th`) - tk.MustExec("set @@session.tidb_enable_table_partition = '1';") - tk.MustExec(`create table th (a int, b int) partition by hash(a) partitions 3;`) - defer tk.MustExec(`drop table if exists th`) - tk.MustExec(`insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);`) - tk.MustExec("insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8);") - tk.MustQuery("select b from th order by a").Check(testkit.Rows("-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0", "1", "2", "3", "4", "5", "6", "7", "8")) - tk.MustQuery(" select * from th where a=-2;").Check(testkit.Rows("-2 -2")) - tk.MustQuery(" select * from th where a=5;").Check(testkit.Rows("5 5")) -} - -func TestSelectView(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table view_t (a int,b int)") - tk.MustExec("insert into view_t values(1,2)") - tk.MustExec("create definer='root'@'localhost' view view1 as select * from view_t") - tk.MustExec("create definer='root'@'localhost' view view2(c,d) as select * from view_t") - tk.MustExec("create definer='root'@'localhost' view view3(c,d) as select a,b from view_t") - tk.MustExec("create definer='root'@'localhost' view view4 as select * from (select * from (select * from view_t) tb1) tb;") - tk.MustQuery("select * from view1;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view2;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view3;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view4;").Check(testkit.Rows("1 2")) - tk.MustExec("drop table view_t;") - tk.MustExec("create table view_t(c int,d int)") - tk.MustGetErrMsg("select * from view1", "[planner:1356]View 'test.view1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them") - tk.MustGetErrMsg("select * from view2", "[planner:1356]View 'test.view2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them") - tk.MustGetErrMsg("select * from view3", plannercore.ErrViewInvalid.GenWithStackByArgs("test", "view3").Error()) - tk.MustExec("drop table view_t;") - tk.MustExec("create table view_t(a int,b int,c int)") - tk.MustExec("insert into view_t values(1,2,3)") - tk.MustQuery("select * from view1;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view2;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view3;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view4;").Check(testkit.Rows("1 2")) - tk.MustExec("alter table view_t drop column a") - tk.MustExec("alter table view_t add column a int after b") - tk.MustExec("update view_t set a=1;") - tk.MustQuery("select * from view1;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view2;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view3;").Check(testkit.Rows("1 2")) - tk.MustQuery("select * from view4;").Check(testkit.Rows("1 2")) - tk.MustExec("drop table view_t;") - tk.MustExec("drop view view1,view2,view3,view4;") - - tk.MustExec("set @@tidb_enable_window_function = 1") - defer func() { - tk.MustExec("set @@tidb_enable_window_function = 0") - }() - tk.MustExec("create table t(a int, b int)") - tk.MustExec("insert into t values (1,1),(1,2),(2,1),(2,2)") - tk.MustExec("create definer='root'@'localhost' view v as select a, first_value(a) over(rows between 1 preceding and 1 following), last_value(a) over(rows between 1 preceding and 1 following) from t") - result := tk.MustQuery("select * from v") - result.Check(testkit.Rows("1 1 1", "1 1 2", "2 1 2", "2 2 2")) - tk.MustExec("drop view v;") -} - func TestSummaryFailedUpdate(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) @@ -5150,28 +4028,6 @@ func TestHashJoinJSON(t *testing.T) { tk.MustQuery("select /*+inl_hash_join(t2)*/ t1.id, t2.id from t t1 join t t2 on t1.j = t2.d;").Check(testkit.Rows("0 0", "1 1", "2 2")) } -func TestBinaryStrNumericOperator(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // Test normal warnings. - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varbinary(10))") - tk.MustExec("insert into t values ('123.12')") - tk.MustQuery("select 1+a from t").Check(testkit.Rows( - "124.12")) - tk.MustQuery("select a-1 from t").Check(testkit.Rows( - "122.12")) - tk.MustQuery("select -10*a from t").Check(testkit.Rows( - "-1231.2")) - tk.MustQuery("select a/-2 from t").Check(testkit.Rows( - "-61.56")) - // there should be no warning. - tk.MustQuery("show warnings").Check(testkit.Rows()) -} - func TestTableLockPrivilege(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/r/executor/executor.result b/tests/integrationtest/r/executor/executor.result index 40956390a2c78..469772256a1bd 100644 --- a/tests/integrationtest/r/executor/executor.result +++ b/tests/integrationtest/r/executor/executor.result @@ -1246,3 +1246,1558 @@ select * from t where (a,b) not in (select a, b from s); a b set @@tidb_max_chunk_size=default; set @@tidb_enable_null_aware_anti_join=default; +drop table if exists t; +create table t(id int primary key, a int); +insert into t values(1, 1); +begin PESSIMISTIC; +select a from t where id=1 for update; +a +1 +update t set a=a+1 where id=1; +commit; +select a from t where id=1; +a +2 +change pump to node_state ='paused' for node_id 'pump1'; +Error 1105 (HY000): URL scheme must be http, https, unix, or unixs: +change drainer to node_state ='paused' for node_id 'drainer1'; +Error 1105 (HY000): URL scheme must be http, https, unix, or unixs: +drop table if exists select_limit; +create table select_limit(id int not null default 1, name varchar(255), PRIMARY KEY(id)); +insert INTO select_limit VALUES (1, "hello"); +insert into select_limit values (2, "hello"); +insert INTO select_limit VALUES (3, "hello"); +insert INTO select_limit VALUES (4, "hello"); +select * from select_limit limit 1; +id name +1 hello +select id from (select * from select_limit limit 1) k where id != 1; +id +select * from select_limit limit 18446744073709551615 offset 0; +id name +1 hello +2 hello +3 hello +4 hello +select * from select_limit limit 18446744073709551615 offset 1; +id name +2 hello +3 hello +4 hello +select * from select_limit limit 18446744073709551615 offset 3; +id name +4 hello +select * from select_limit limit 18446744073709551616 offset 3; +[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 53 near "18446744073709551616 offset 3;" +drop table if exists select_order_test; +create table select_order_test(id int not null default 1, name varchar(255), PRIMARY KEY(id)); +insert INTO select_order_test VALUES (1, "hello"); +insert into select_order_test values (2, "hello"); +select * from select_order_test where id = 1 order by id limit 1 offset 0; +id name +1 hello +select id from select_order_test order by id desc limit 1 ; +id +2 +select id from select_order_test order by id + 1 desc limit 1 ; +id +2 +select * from select_order_test order by name, id limit 1 offset 0; +id name +1 hello +select id as c1, name from select_order_test order by 2, id limit 1 offset 0; +c1 name +1 hello +select * from select_order_test order by name, id limit 100 offset 0; +id name +1 hello +2 hello +select * from select_order_test order by name, id limit 1 offset 100; +id name +select id from select_order_test order by name, id limit 18446744073709551615; +id +1 +2 +select id, name from select_order_test where id = 1 group by id, name limit 1 offset 0; +id name +1 hello +insert INTO select_order_test VALUES (3, "zz"); +insert INTO select_order_test VALUES (4, "zz"); +insert INTO select_order_test VALUES (5, "zz"); +insert INTO select_order_test VALUES (6, "zz"); +insert INTO select_order_test VALUES (7, "zz"); +insert INTO select_order_test VALUES (8, "zz"); +insert INTO select_order_test VALUES (9, "zz"); +insert INTO select_order_test VALUES (10, "zz"); +insert INTO select_order_test VALUES (10086, "hi"); +insert INTO select_order_test VALUES (11, "hh"); +insert INTO select_order_test VALUES (12, "hh"); +insert INTO select_order_test VALUES (13, "hh"); +insert INTO select_order_test VALUES (14, "hh"); +insert INTO select_order_test VALUES (15, "hh"); +insert INTO select_order_test VALUES (16, "hh"); +insert INTO select_order_test VALUES (17, "hh"); +insert INTO select_order_test VALUES (18, "hh"); +insert INTO select_order_test VALUES (19, "hh"); +insert INTO select_order_test VALUES (20, "hh"); +insert INTO select_order_test VALUES (21, "zz"); +insert INTO select_order_test VALUES (22, "zz"); +insert INTO select_order_test VALUES (23, "zz"); +insert INTO select_order_test VALUES (24, "zz"); +insert INTO select_order_test VALUES (25, "zz"); +insert INTO select_order_test VALUES (26, "zz"); +insert INTO select_order_test VALUES (27, "zz"); +insert INTO select_order_test VALUES (28, "zz"); +insert INTO select_order_test VALUES (29, "zz"); +insert INTO select_order_test VALUES (30, "zz"); +insert INTO select_order_test VALUES (1501, "aa"); +select * from select_order_test order by name, id limit 1 offset 3; +id name +11 hh +drop table if exists select_order_test; +drop table if exists t; +create table t (c int, d int); +insert t values (1, 1); +insert t values (1, 2); +insert t values (1, 3); +select 1-d as d from t order by d; +d +-2 +-1 +0 +select 1-d as d from t order by d + 1; +d +0 +-1 +-2 +select t.d from t order by d; +d +1 +2 +3 +drop table if exists t; +create table t (a int, b int, c int); +insert t values (1, 2, 3); +select b from (select a,b from t order by a,c) t; +b +2 +select b from (select a,b from t order by a,c limit 1) t; +b +2 +drop table if exists t; +create table t(a int, b int, index idx(a)); +insert into t values(1, 1), (2, 2); +select * from t where 1 order by b; +a b +1 1 +2 2 +select * from t where a between 1 and 2 order by a desc; +a b +2 2 +1 1 +drop table if exists t; +create table t(a int primary key, b int, c int, index idx(b)); +insert into t values(1, 3, 1); +insert into t values(2, 2, 2); +insert into t values(3, 1, 3); +select * from t use index(idx) order by a desc limit 1; +a b c +3 1 3 +drop table if exists t; +create table t(a int, b int, key b (b)); +set @@tidb_index_lookup_size = 3; +insert into t values(0, 10); +insert into t values(1, 9); +insert into t values(2, 8); +insert into t values(3, 7); +insert into t values(4, 6); +insert into t values(5, 5); +insert into t values(6, 4); +insert into t values(7, 3); +insert into t values(8, 2); +insert into t values(9, 1); +select a from t use index(b) order by b; +a +9 +8 +7 +6 +5 +4 +3 +2 +1 +0 +set @@tidb_index_lookup_size = default; +select row(1, 1) from test; +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +select * from test group by row(1, 1); +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +select * from test order by row(1, 1); +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +select * from test having row(1, 1); +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +select (select 1, 1) from test; +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +select * from test group by (select 1, 1); +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +select * from test order by (select 1, 1); +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +select * from test having (select 1, 1); +Error 1146 (42S02): Table 'executor__executor.test' doesn't exist +drop table if exists t; +create table t (c1 int primary key, c2 int, key c (c2)); +insert t values(0, 0); +insert t values(1, 1); +insert t values(2, 2); +insert t values(3, 3); +insert t values(4, 4); +insert t values(5, 5); +insert t values(6, 6); +insert t values(7, 7); +insert t values(8, 8); +insert t values(9, 9); +insert t values(10, 10); +insert t values(11, 11); +insert t values(12, 12); +insert t values(13, 13); +insert t values(14, 14); +insert t values(15, 15); +insert t values(16, 16); +insert t values(17, 17); +insert t values(18, 18); +insert t values(19, 19); +insert t values(20, 20); +insert t values(21, 21); +insert t values(22, 22); +insert t values(23, 23); +insert t values(24, 24); +insert t values(25, 25); +insert t values(26, 26); +insert t values(27, 27); +insert t values(28, 28); +insert t values(29, 29); +insert t values(30, 30); +insert t values(31, 31); +insert t values(32, 32); +insert t values(33, 33); +insert t values(34, 34); +insert t values(35, 35); +insert t values(36, 36); +insert t values(37, 37); +insert t values(38, 38); +insert t values(39, 39); +insert t values(40, 40); +insert t values(41, 41); +insert t values(42, 42); +insert t values(43, 43); +insert t values(44, 44); +insert t values(45, 45); +insert t values(46, 46); +insert t values(47, 47); +insert t values(48, 48); +insert t values(49, 49); +insert t values(50, 50); +insert t values(51, 51); +insert t values(52, 52); +insert t values(53, 53); +insert t values(54, 54); +insert t values(55, 55); +insert t values(56, 56); +insert t values(57, 57); +insert t values(58, 58); +insert t values(59, 59); +insert t values(60, 60); +insert t values(61, 61); +insert t values(62, 62); +insert t values(63, 63); +insert t values(64, 64); +insert t values(65, 65); +insert t values(66, 66); +insert t values(67, 67); +insert t values(68, 68); +insert t values(69, 69); +insert t values(70, 70); +insert t values(71, 71); +insert t values(72, 72); +insert t values(73, 73); +insert t values(74, 74); +insert t values(75, 75); +insert t values(76, 76); +insert t values(77, 77); +insert t values(78, 78); +insert t values(79, 79); +insert t values(80, 80); +insert t values(81, 81); +insert t values(82, 82); +insert t values(83, 83); +insert t values(84, 84); +insert t values(85, 85); +insert t values(86, 86); +insert t values(87, 87); +insert t values(88, 88); +insert t values(89, 89); +insert t values(90, 90); +insert t values(91, 91); +insert t values(92, 92); +insert t values(93, 93); +insert t values(94, 94); +insert t values(95, 95); +insert t values(96, 96); +insert t values(97, 97); +insert t values(98, 98); +insert t values(99, 99); +insert t values(100, 100); +insert t values(101, 101); +insert t values(102, 102); +insert t values(103, 103); +insert t values(104, 104); +insert t values(105, 105); +insert t values(106, 106); +insert t values(107, 107); +insert t values(108, 108); +insert t values(109, 109); +insert t values(110, 110); +insert t values(111, 111); +insert t values(112, 112); +insert t values(113, 113); +insert t values(114, 114); +insert t values(115, 115); +insert t values(116, 116); +insert t values(117, 117); +insert t values(118, 118); +insert t values(119, 119); +insert t values(120, 120); +insert t values(121, 121); +insert t values(122, 122); +insert t values(123, 123); +insert t values(124, 124); +insert t values(125, 125); +insert t values(126, 126); +insert t values(127, 127); +insert t values(128, 128); +insert t values(129, 129); +insert t values(130, 130); +insert t values(131, 131); +insert t values(132, 132); +insert t values(133, 133); +insert t values(134, 134); +insert t values(135, 135); +insert t values(136, 136); +insert t values(137, 137); +insert t values(138, 138); +insert t values(139, 139); +insert t values(140, 140); +insert t values(141, 141); +insert t values(142, 142); +insert t values(143, 143); +insert t values(144, 144); +insert t values(145, 145); +insert t values(146, 146); +insert t values(147, 147); +insert t values(148, 148); +insert t values(149, 149); +insert t values(150, 150); +insert t values(151, 151); +insert t values(152, 152); +insert t values(153, 153); +insert t values(154, 154); +insert t values(155, 155); +insert t values(156, 156); +insert t values(157, 157); +insert t values(158, 158); +insert t values(159, 159); +insert t values(160, 160); +insert t values(161, 161); +insert t values(162, 162); +insert t values(163, 163); +insert t values(164, 164); +insert t values(165, 165); +insert t values(166, 166); +insert t values(167, 167); +insert t values(168, 168); +insert t values(169, 169); +insert t values(170, 170); +insert t values(171, 171); +insert t values(172, 172); +insert t values(173, 173); +insert t values(174, 174); +insert t values(175, 175); +insert t values(176, 176); +insert t values(177, 177); +insert t values(178, 178); +insert t values(179, 179); +insert t values(180, 180); +insert t values(181, 181); +insert t values(182, 182); +insert t values(183, 183); +insert t values(184, 184); +insert t values(185, 185); +insert t values(186, 186); +insert t values(187, 187); +insert t values(188, 188); +insert t values(189, 189); +insert t values(190, 190); +insert t values(191, 191); +insert t values(192, 192); +insert t values(193, 193); +insert t values(194, 194); +insert t values(195, 195); +insert t values(196, 196); +insert t values(197, 197); +insert t values(198, 198); +insert t values(199, 199); +insert t values(200, 200); +select c2 from t where c1 in ('7', '10', '112', '111', '98', '106', '100', '9', '18', '17') order by c2; +c2 +7 +9 +10 +17 +18 +98 +100 +106 +111 +112 +select c2 from t where c1 in ('7a'); +c2 +7 +drop table if exists t; +create table t (a int PRIMARY KEY AUTO_INCREMENT); +insert t values (),(); +insert t values (-100),(0); +select * from t; +a +-100 +1 +2 +3 +select * from t where a = 1; +a +1 +select * from t where a != 1; +a +-100 +2 +3 +select * from t where a >= '1.1'; +a +2 +3 +select * from t where a < '1.1'; +a +-100 +1 +select * from t where a > '-100.1' and a < 2; +a +-100 +1 +select * from t where a is null; +a +select * from t where a is true; +a +-100 +1 +2 +3 +select * from t where a is false; +a +select * from t where a in (1, 2); +a +1 +2 +select * from t where a between 1 and 2; +a +1 +2 +drop table if exists t; +create table t (a int primary key auto_increment, b int default 1, c int); +insert t values (); +select * from t; +a b c +1 1 NULL +update t set b = NULL where a = 1; +select * from t; +a b c +1 NULL NULL +update t set c = 1; +select * from t ; +a b c +1 NULL 1 +delete from t where a = 1; +insert t (a) values (1); +select * from t; +a b c +1 1 NULL +drop table if exists test_json; +create table test_json (id int, a json); +insert into test_json (id, a) values (1, '{"a":[1,"2",{"aa":"bb"},4],"b":true}'); +insert into test_json (id, a) values (2, "null"); +insert into test_json (id, a) values (3, null); +insert into test_json (id, a) values (4, 'true'); +insert into test_json (id, a) values (5, '3'); +insert into test_json (id, a) values (5, '4.0'); +insert into test_json (id, a) values (6, '"string"'); +select tj.a from test_json tj order by tj.id; +a +{"a": [1, "2", {"aa": "bb"}, 4], "b": true} +null +NULL +true +3 +4 +"string" +select json_type(a) from test_json tj order by tj.id; +json_type(a) +OBJECT +NULL +NULL +BOOLEAN +INTEGER +DOUBLE +STRING +select a from test_json tj where a = 3; +a +3 +select a from test_json tj where a = 4.0; +a +4 +select a from test_json tj where a = true; +a +true +select a from test_json tj where a = "string"; +a +"string" +select cast(true as JSON); +cast(true as JSON) +true +select cast(false as JSON); +cast(false as JSON) +false +select a->>'$.a[2].aa' as x, a->'$.b' as y from test_json having x is not null order by id; +x y +bb true +select a->'$.a[2].aa' as x, a->>'$.b' as y from test_json having x is not null order by id; +x y +"bb" true +create table test_bad_json(a json default '{}'); +Error 1101 (42000): BLOB/TEXT/JSON column 'a' can't have a default value +create table test_bad_json(a blob default 'hello'); +Error 1101 (42000): BLOB/TEXT/JSON column 'a' can't have a default value +create table test_bad_json(a text default 'world'); +Error 1101 (42000): BLOB/TEXT/JSON column 'a' can't have a default value +create table test_bad_json(id int, a json, key (a)); +Error 3152 (42000): JSON column 'a' cannot be used in key specification. +select CAST('3' AS JSON), CAST('{}' AS JSON), CAST(null AS JSON); +CAST('3' AS JSON) CAST('{}' AS JSON) CAST(null AS JSON) +3 {} NULL +select a, count(1) from test_json group by a order by a; +a count(1) +NULL 1 +null 1 +3 1 +4 1 +"string" 1 +{"a": [1, "2", {"aa": "bb"}, 4], "b": true} 1 +true 1 +drop table if exists test_json; +create table test_json ( a decimal(60,2) as (JSON_EXTRACT(b,'$.c')), b json ); +insert into test_json (b) values +('{"c": "1267.1"}'), +('{"c": "1267.01"}'), +('{"c": "1267.1234"}'), +('{"c": "1267.3456"}'), +('{"c": "1234567890123456789012345678901234567890123456789012345"}'), +('{"c": "1234567890123456789012345678901234567890123456789012345.12345"}'); +select a from test_json; +a +1267.10 +1267.01 +1267.12 +1267.35 +1234567890123456789012345678901234567890123456789012345.00 +1234567890123456789012345678901234567890123456789012345.12 +drop table if exists test_gc_write, test_gc_write_1; +CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (a+8) virtual); +Error 3109 (HY000): Generated column 'c' cannot refer to auto-increment column. +CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (b+8) virtual); +CREATE TABLE test_gc_write_1 (a int primary key, b int, c int); +insert into test_gc_write (a, b, c) values (1, 1, 1); +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +insert into test_gc_write values (1, 1, 1); +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +insert into test_gc_write select 1, 1, 1; +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +insert into test_gc_write (a, b) values (1, 1) on duplicate key update c = 1; +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +insert into test_gc_write set a = 1, b = 1, c = 1; +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +update test_gc_write set c = 1; +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +update test_gc_write, test_gc_write_1 set test_gc_write.c = 1; +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +insert into test_gc_write (a, b) values (1, 1); +insert into test_gc_write set a = 2, b = 2; +insert into test_gc_write (b) select c from test_gc_write; +update test_gc_write set b = 2 where a = 2; +update test_gc_write t1, test_gc_write_1 t2 set t1.b = 3, t2.b = 4; +insert into test_gc_write values (1, 1); +Error 1136 (21S01): Column count doesn't match value count at row 1 +insert into test_gc_write select 1, 1; +Error 1136 (21S01): Column count doesn't match value count at row 1 +insert into test_gc_write (c) select a, b from test_gc_write; +Error 1136 (21S01): Column count doesn't match value count at row 1 +insert into test_gc_write (b, c) select a, b from test_gc_write; +Error 3105 (HY000): The value specified for generated column 'c' in table 'test_gc_write' is not allowed. +drop table if exists test_gc_read; +CREATE TABLE test_gc_read(a int primary key, b int, c int as (a+b), d int as (a*b) stored, e int as (c*2)); +SELECT generation_expression FROM information_schema.columns WHERE table_name = 'test_gc_read' AND column_name = 'd'; +generation_expression +`a` * `b` +INSERT INTO test_gc_read (a, b) VALUES (0,null),(1,2),(3,4); +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +3 4 7 12 14 +INSERT INTO test_gc_read SET a = 5, b = 10; +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +3 4 7 12 14 +5 10 15 50 30 +REPLACE INTO test_gc_read (a, b) VALUES (5, 6); +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +3 4 7 12 14 +5 6 11 30 22 +INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE b = 9; +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +3 4 7 12 14 +5 9 14 45 28 +SELECT c, d FROM test_gc_read; +c d +NULL NULL +3 2 +7 12 +14 45 +SELECT e FROM test_gc_read; +e +NULL +6 +14 +28 +INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE a = 6, b = a; +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +3 4 7 12 14 +6 6 12 36 24 +INSERT INTO test_gc_read (a, b) VALUES (6, 8) ON DUPLICATE KEY UPDATE b = 8, a = b; +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +3 4 7 12 14 +8 8 16 64 32 +SELECT * FROM test_gc_read WHERE c = 7; +a b c d e +3 4 7 12 14 +SELECT * FROM test_gc_read WHERE d = 64; +a b c d e +8 8 16 64 32 +SELECT * FROM test_gc_read WHERE e = 6; +a b c d e +1 2 3 2 6 +UPDATE test_gc_read SET a = a + 100 WHERE c = 7; +SELECT * FROM test_gc_read WHERE c = 107; +a b c d e +103 4 107 412 214 +UPDATE test_gc_read m SET m.a = m.a + 100 WHERE c = 107; +SELECT * FROM test_gc_read WHERE c = 207; +a b c d e +203 4 207 812 414 +UPDATE test_gc_read SET a = a - 200 WHERE d = 812; +SELECT * FROM test_gc_read WHERE d = 12; +a b c d e +3 4 7 12 14 +INSERT INTO test_gc_read set a = 4, b = d + 1; +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +3 4 7 12 14 +4 NULL NULL NULL NULL +8 8 16 64 32 +DELETE FROM test_gc_read where a = 4; +CREATE TABLE test_gc_help(a int primary key, b int, c int, d int, e int); +INSERT INTO test_gc_help(a, b, c, d, e) SELECT * FROM test_gc_read; +SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.c = t2.c ORDER BY t1.a; +a b c d e +1 2 3 2 6 +3 4 7 12 14 +8 8 16 64 32 +SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.d = t2.d ORDER BY t1.a; +a b c d e +1 2 3 2 6 +3 4 7 12 14 +8 8 16 64 32 +SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.e = t2.e ORDER BY t1.a; +a b c d e +1 2 3 2 6 +3 4 7 12 14 +8 8 16 64 32 +SELECT * FROM test_gc_read t WHERE t.a not in (SELECT t.a FROM test_gc_read t where t.c > 5); +a b c d e +0 NULL NULL NULL NULL +1 2 3 2 6 +SELECT * FROM test_gc_read t WHERE t.c in (SELECT t.c FROM test_gc_read t where t.c > 5); +a b c d e +3 4 7 12 14 +8 8 16 64 32 +SELECT tt.b FROM test_gc_read tt WHERE tt.a = (SELECT max(t.a) FROM test_gc_read t WHERE t.c = tt.c) ORDER BY b; +b +2 +4 +8 +SELECT c, sum(a) aa, max(d) dd, sum(e) ee FROM test_gc_read GROUP BY c ORDER BY aa; +c aa dd ee +NULL 0 NULL NULL +3 1 2 6 +7 3 12 14 +16 8 64 32 +SELECT a, sum(c), sum(d), sum(e) FROM test_gc_read GROUP BY a ORDER BY a; +a sum(c) sum(d) sum(e) +0 NULL NULL NULL +1 3 2 6 +3 7 12 14 +8 16 64 32 +UPDATE test_gc_read m, test_gc_read n SET m.b = m.b + 10, n.b = n.b + 10; +SELECT * FROM test_gc_read ORDER BY a; +a b c d e +0 NULL NULL NULL NULL +1 12 13 12 26 +3 14 17 42 34 +8 18 26 144 52 +drop table if exists t; +create table t(a int); +insert into t values(8); +update test_gc_read set a = a+1 where a in (select a from t); +select * from test_gc_read order by a; +a b c d e +0 NULL NULL NULL NULL +1 12 13 12 26 +3 14 17 42 34 +9 18 27 162 54 +CREATE TABLE test_gc_read_cast(a VARCHAR(255), b VARCHAR(255), c INT AS (JSON_EXTRACT(a, b)), d INT AS (JSON_EXTRACT(a, b)) STORED); +INSERT INTO test_gc_read_cast (a, b) VALUES ('{"a": "3"}', '$.a'); +SELECT c, d FROM test_gc_read_cast; +c d +3 3 +CREATE TABLE test_gc_read_cast_1(a VARCHAR(255), b VARCHAR(255), c ENUM("red", "yellow") AS (JSON_UNQUOTE(JSON_EXTRACT(a, b)))); +INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "yellow"}', '$.a'); +SELECT c FROM test_gc_read_cast_1; +c +yellow +CREATE TABLE test_gc_read_cast_2( a JSON, b JSON AS (a->>'$.a')); +INSERT INTO test_gc_read_cast_2(a) VALUES ('{"a": "{ \\\"key\\\": \\\"\\u6d4b\\\" }"}'); +SELECT b FROM test_gc_read_cast_2; +b +{"key": "测"} +CREATE TABLE test_gc_read_cast_3( a JSON, b JSON AS (a->>'$.a'), c INT AS (b * 3.14) ); +INSERT INTO test_gc_read_cast_3(a) VALUES ('{"a": "5"}'); +SELECT c FROM test_gc_read_cast_3; +c +16 +INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "invalid"}', '$.a'); +Error 1265 (01000): Data truncated for column 'c' at row 1 +DROP TABLE IF EXISTS test_gc_read_m; +CREATE TABLE test_gc_read_m (a int primary key, b int, c int as (a+1), d int as (c*2)); +INSERT INTO test_gc_read_m(a) values (1), (2); +ALTER TABLE test_gc_read_m DROP b; +SELECT * FROM test_gc_read_m; +a c d +1 2 4 +2 3 6 +CREATE TABLE test_gc_read_1(a int primary key, b int, c int as (a+b) not null, d int as (a*b) stored); +CREATE TABLE test_gc_read_2(a int primary key, b int, c int as (a+b), d int as (a*b) stored not null); +insert into test_gc_read_1(a, b) values (1, null); +Error 1048 (23000): Column 'c' cannot be null +insert into test_gc_read_2(a, b) values (1, null); +Error 1048 (23000): Column 'd' cannot be null +set @@session.tidb_enable_list_partition = ON; +drop table if exists th, tr, tl; +create table th (a int, b int) partition by hash(a) partitions 3; +create table tr (a int, b int) +partition by range (a) ( +partition r0 values less than (4), +partition r1 values less than (7), +partition r3 values less than maxvalue); +create table tl (a int, b int, unique index idx(a)) partition by list (a) ( +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 th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); +insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); +insert into tr values (-3,-3),(3,3),(4,4),(7,7),(8,8); +insert into tl values (3,3),(1,1),(4,4),(7,7),(8,8),(null,null); +select b from th partition (p0) order by a; +b +-6 +-3 +0 +3 +6 +select b from tr partition (r0) order by a; +b +-3 +3 +select b from tl partition (p0) order by a; +b +3 +select b from th partition (p0,P0) order by a; +b +-6 +-3 +0 +3 +6 +select b from tr partition (r0,R0,r0) order by a; +b +-3 +3 +select b from tl partition (p0,P0,p0) order by a; +b +3 +select b from th partition (P2,p0) order by a; +b +-8 +-6 +-5 +-3 +-2 +0 +2 +3 +5 +6 +8 +select b from tr partition (r1,R3) order by a; +b +4 +7 +8 +select b from tl partition (p0,P3) order by a; +b +NULL +3 +7 +8 +select b from th partition (p0,p4); +Error 1735 (HY000): Unknown partition 'p4' in table 'th' +select b from tr partition (r1,r4); +Error 1735 (HY000): Unknown partition 'r4' in table 'tr' +select b from tl partition (p0,p4); +Error 1735 (HY000): Unknown partition 'p4' in table 'tl' +begin; +insert into th values (10,10),(11,11); +select a, b from th where b>10; +a b +11 11 +commit; +select a, b from th where b>10; +a b +11 11 +drop table if exists tscalar; +create table tscalar (c1 int) partition by range (c1 % 30) ( +partition p0 values less than (0), +partition p1 values less than (10), +partition p2 values less than (20), +partition pm values less than (maxvalue)); +insert into tscalar values(0), (10), (40), (50), (55); +insert into tscalar values(-0), (-10), (-40), (-50), (-55); +select * from tscalar where c1 in (55, 55); +c1 +55 +select * from tscalar where c1 in (40, 40); +c1 +40 +select * from tscalar where c1 in (40); +c1 +40 +select * from tscalar where c1 in (-40); +c1 +-40 +select * from tscalar where c1 in (-40, -40); +c1 +-40 +select * from tscalar where c1 in (-1); +c1 +set @@session.tidb_enable_list_partition = default; +prepare stmt from "load data local infile '/tmp/load_data_test.csv' into table test"; +Error 1295 (HY000): This command is not supported in the prepared statement protocol yet +prepare stmt from "import into test from 'xx' format 'delimited'"; +Error 1295 (HY000): This command is not supported in the prepared statement protocol yet +drop table if exists t; +create table t(a int, index idx(a)); +insert into t values(1), (2), (4); +begin; +update t set a = 3 where a = 4; +select * from t ignore index(idx); +a +1 +2 +3 +insert into t values(4); +select * from t use index(idx); +a +1 +2 +3 +4 +select * from t use index(idx) order by a desc; +a +4 +3 +2 +1 +update t set a = 5 where a = 3; +select * from t use index(idx); +a +1 +2 +4 +5 +commit; +drop table if exists t; +create table t(a int, b int, index idx(a)); +insert into t values(3, 3), (1, 1), (2, 2); +select * from t use index(idx) order by a; +a b +1 1 +2 2 +3 3 +drop table if exists t; +create table t(id bigint, PRIMARY KEY (id)); +insert into t values(9223372036854775807); +select * from t where id = 9223372036854775807; +id +9223372036854775807 +select * from t where id = 9223372036854775807; +id +9223372036854775807 +select * from t; +id +9223372036854775807 +insert into t values(9223372036854775807); +Error 1062 (23000): Duplicate entry '9223372036854775807' for key 't.PRIMARY' +delete from t where id = 9223372036854775807; +select * from t; +id +drop table if exists t; +create table t(id bigint unsigned primary key); +insert into t values(9223372036854775808), (9223372036854775809), (1), (2); +select * from t order by id; +id +1 +2 +9223372036854775808 +9223372036854775809 +select * from t where id not in (2); +id +9223372036854775808 +9223372036854775809 +1 +drop table if exists t; +create table t(a bigint unsigned primary key, b int, index idx(b)); +insert into t values(9223372036854775808, 1), (1, 1); +select * from t use index(idx) where b = 1 and a < 2; +a b +1 1 +select * from t use index(idx) where b = 1 order by b, a; +a b +1 1 +9223372036854775808 1 +set @@tidb_enable_clustered_index = 1; +drop table if exists t; +create table t(k1 int, k2 int, primary key(k1, k2)); +insert into t(k1, k2) value(-100, 1), (-50, 1), (0, 0), (1, 1), (3, 3); +select k1 from t order by k1; +k1 +-100 +-50 +0 +1 +3 +select k1 from t order by k1 desc; +k1 +3 +1 +0 +-50 +-100 +select k1 from t where k1 < -51; +k1 +-100 +select k1 from t where k1 < -1; +k1 +-100 +-50 +select k1 from t where k1 <= 0; +k1 +-100 +-50 +0 +select k1 from t where k1 < 2; +k1 +-100 +-50 +0 +1 +select k1 from t where k1 < -1 and k1 > -90; +k1 +-50 +set @@tidb_enable_clustered_index = default; +drop table if exists t1, t2, t3; +create table t1(t1.a char); +create table t2(a char, t2.b int); +create table t3(s.a char); +Error 1103 (42000): Incorrect table name 's' +set @@tidb_enable_clustered_index = 1; +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1, c2), index (c1), unique key(c2)); +insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3); +admin check table admin_test; + +set @@tidb_enable_clustered_index = default; +drop table if exists t; +create table t(a bigint); +prepare stmt1 from 'select * from t limit ?'; +prepare stmt2 from 'select * from t limit ?, ?'; +set @a = -1; +set @b = 1; +execute stmt1 using @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +execute stmt2 using @b, @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +execute stmt2 using @a, @b; +Error 1210 (HY000): Incorrect arguments to LIMIT +execute stmt2 using @a, @a; +Error 1210 (HY000): Incorrect arguments to LIMIT +drop table if exists t; +create table t (e enum('Y', 'N')); +set sql_mode='STRICT_TRANS_TABLES'; +insert into t values (0); +Error 1265 (01000): Data truncated for column 'e' at row 1 +insert into t values ('abc'); +Error 1265 (01000): Data truncated for column 'e' at row 1 +set sql_mode=''; +insert into t values (0); +select * from t; +e + +insert into t values ('abc'); +select * from t; +e + + +insert into t values (null); +select * from t; +e + + +NULL +drop table if exists t; +create table t (id int auto_increment primary key, c1 enum('a', '', 'c')); +insert into t(c1) values (0); +select id, c1+0, c1 from t; +id c1+0 c1 +1 0 +alter table t change c1 c1 enum('a', '') not null; +select id, c1+0, c1 from t; +id c1+0 c1 +1 0 +insert into t(c1) values (0); +select id, c1+0, c1 from t; +id c1+0 c1 +1 0 +2 0 +set sql_mode=default; +drop table if exists t1; +create table t1(a int) partition by range (10 div a) (partition p0 values less than (10), partition p1 values less than maxvalue); +set @@sql_mode=''; +insert into t1 values (NULL), (0), (1); +set @@sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO'; +insert into t1 values (NULL), (0), (1); +Error 1365 (22012): Division by 0 +set @@sql_mode=default; +drop table if exists t1; +create table t1( +a int(11) DEFAULT NULL, +b varchar(10) DEFAULT NULL, +UNIQUE KEY idx_a (a)) PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, +PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, +PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, +PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, +PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +insert into t1 partition(p0) values(1, 'a'), (2, 'b'); +select * from t1 partition(p0) order by a; +a b +1 a +2 b +insert into t1 partition(p0, p1) values(3, 'c'), (4, 'd'); +select * from t1 partition(p1); +a b +insert into t1 values(1, 'a'); +Error 1062 (23000): Duplicate entry '1' for key 't1.idx_a' +insert into t1 partition(p0, p_non_exist) values(1, 'a'); +Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' +insert into t1 partition(p0, p1) values(40, 'a'); +Error 1748 (HY000): Found a row not matching the given partition set +replace into t1 partition(p0) values(1, 'replace'); +replace into t1 partition(p0, p1) values(3, 'replace'), (4, 'replace'); +replace into t1 values(1, 'a'); +select * from t1 partition (p0) order by a; +a b +1 a +2 b +3 replace +4 replace +replace into t1 partition(p0, p_non_exist) values(1, 'a'); +Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' +replace into t1 partition(p0, p1) values(40, 'a'); +Error 1748 (HY000): Found a row not matching the given partition set +truncate table t1; +drop table if exists t; +create table t(a int, b char(10)); +insert into t partition(p0, p1) values(1, 'a'); +Error 1747 (HY000): PARTITION () clause on non partitioned table +insert into t values(1, 'a'), (2, 'b'); +insert into t1 partition(p0) select * from t; +select * from t1 partition(p0) order by a; +a b +1 a +2 b +truncate table t; +insert into t values(3, 'c'), (4, 'd'); +insert into t1 partition(p0, p1) select * from t; +select * from t1 partition(p1) order by a; +a b +select * from t1 partition(p0) order by a; +a b +1 a +2 b +3 c +4 d +insert into t1 select 1, 'a'; +Error 1062 (23000): Duplicate entry '1' for key 't1.idx_a' +insert into t1 partition(p0, p_non_exist) select 1, 'a'; +Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' +insert into t1 partition(p0, p1) select 40, 'a'; +Error 1748 (HY000): Found a row not matching the given partition set +replace into t1 partition(p0) select 1, 'replace'; +truncate table t; +insert into t values(3, 'replace'), (4, 'replace'); +replace into t1 partition(p0, p1) select * from t; +replace into t1 select 1, 'a'; +select * from t1 partition (p0) order by a; +a b +1 a +2 b +3 replace +4 replace +replace into t1 partition(p0, p_non_exist) select 1, 'a'; +Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' +replace into t1 partition(p0, p1) select 40, 'a'; +Error 1748 (HY000): Found a row not matching the given partition set +drop table if exists t1, t2, t3; +create table t1( +a int(11), +b varchar(10) DEFAULT NULL, +primary key idx_a (a)) PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, +PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, +PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, +PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, +PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +create table t2( +a int(11) DEFAULT NULL, +b varchar(10) DEFAULT NULL) PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, +PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, +PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, +PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, +PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +create table t3 (a int(11), b varchar(10) default null); +insert into t3 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); +update t3 partition(p0) set a = 40 where a = 2; +Error 1747 (HY000): PARTITION () clause on non partitioned table +insert into t1 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); +update t1 partition(p0, p1) set a = 40; +Error 1748 (HY000): Found a row not matching the given partition set +update t1 partition(p0) set a = 40 where a = 2; +Error 1748 (HY000): Found a row not matching the given partition set +update t1 partition (p0, p_non_exist) set a = 40; +Error 1735 (HY000): Unknown partition 'p_non_exist' in table 't1' +update t1 partition (p0), t3 set t1.a = 40 where t3.a = 2; +Error 1748 (HY000): Found a row not matching the given partition set +update t1 partition(p0) set a = 3 where a = 2; +update t1 partition(p0, p3) set a = 33 where a = 1; +insert into t2 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); +update t2 partition(p0, p1) set a = 40; +Error 1748 (HY000): Found a row not matching the given partition set +update t2 partition(p0) set a = 40 where a = 2; +Error 1748 (HY000): Found a row not matching the given partition set +update t2 partition(p0) set a = 3 where a = 2; +update t2 partition(p0, p3) set a = 33 where a = 1; +drop table if exists t4; +create table t4(a int primary key, b int) partition by hash(a) partitions 2; +insert into t4(a, b) values(1, 1),(2, 2),(3, 3); +update t4 partition(p0) set a = 5 where a = 2; +Error 1748 (HY000): Found a row not matching the given partition set +drop table if exists t; +CREATE TABLE t (a DATETIME); +INSERT INTO t VALUES('1988-04-17 01:59:59'); +SELECT DATE_ADD(a, INTERVAL 1 SECOND) FROM t; +DATE_ADD(a, INTERVAL 1 SECOND) +1988-04-17 02:00:00 +select YEAR(0000-00-00), YEAR("0000-00-00"); +YEAR(0000-00-00) YEAR("0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select MONTH(0000-00-00), MONTH("0000-00-00"); +MONTH(0000-00-00) MONTH("0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select DAYOFMONTH(0000-00-00), DAYOFMONTH("0000-00-00"); +DAYOFMONTH(0000-00-00) DAYOFMONTH("0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select QUARTER(0000-00-00), QUARTER("0000-00-00"); +QUARTER(0000-00-00) QUARTER("0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select EXTRACT(DAY FROM 0000-00-00), EXTRACT(DAY FROM "0000-00-00"); +EXTRACT(DAY FROM 0000-00-00) EXTRACT(DAY FROM "0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select EXTRACT(MONTH FROM 0000-00-00), EXTRACT(MONTH FROM "0000-00-00"); +EXTRACT(MONTH FROM 0000-00-00) EXTRACT(MONTH FROM "0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select EXTRACT(YEAR FROM 0000-00-00), EXTRACT(YEAR FROM "0000-00-00"); +EXTRACT(YEAR FROM 0000-00-00) EXTRACT(YEAR FROM "0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select EXTRACT(WEEK FROM 0000-00-00), EXTRACT(WEEK FROM "0000-00-00"); +EXTRACT(WEEK FROM 0000-00-00) EXTRACT(WEEK FROM "0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select EXTRACT(QUARTER FROM 0000-00-00), EXTRACT(QUARTER FROM "0000-00-00"); +EXTRACT(QUARTER FROM 0000-00-00) EXTRACT(QUARTER FROM "0000-00-00") +0 NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select DAYOFWEEK(0000-00-00), DAYOFWEEK("0000-00-00"); +DAYOFWEEK(0000-00-00) DAYOFWEEK("0000-00-00") +NULL NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +select DAYOFYEAR(0000-00-00), DAYOFYEAR("0000-00-00"); +DAYOFYEAR(0000-00-00) DAYOFYEAR("0000-00-00") +NULL NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000000' +drop table if exists t; +create table t(v1 datetime, v2 datetime(3)); +insert ignore into t values(0,0); +select YEAR(v1), YEAR(v2) from t; +YEAR(v1) YEAR(v2) +0 0 +select MONTH(v1), MONTH(v2) from t; +MONTH(v1) MONTH(v2) +0 0 +select DAYOFMONTH(v1), DAYOFMONTH(v2) from t; +DAYOFMONTH(v1) DAYOFMONTH(v2) +0 0 +select QUARTER(v1), QUARTER(v2) from t; +QUARTER(v1) QUARTER(v2) +0 0 +select EXTRACT(DAY FROM v1), EXTRACT(DAY FROM v2) from t; +EXTRACT(DAY FROM v1) EXTRACT(DAY FROM v2) +0 0 +select EXTRACT(MONTH FROM v1), EXTRACT(MONTH FROM v2) from t; +EXTRACT(MONTH FROM v1) EXTRACT(MONTH FROM v2) +0 0 +select EXTRACT(YEAR FROM v1), EXTRACT(YEAR FROM v2) from t; +EXTRACT(YEAR FROM v1) EXTRACT(YEAR FROM v2) +0 0 +select EXTRACT(WEEK FROM v1), EXTRACT(WEEK FROM v2) from t; +EXTRACT(WEEK FROM v1) EXTRACT(WEEK FROM v2) +0 0 +select EXTRACT(QUARTER FROM v1), EXTRACT(QUARTER FROM v2) from t; +EXTRACT(QUARTER FROM v1) EXTRACT(QUARTER FROM v2) +0 0 +select DAYOFWEEK(v1), DAYOFWEEK(v2) from t; +DAYOFWEEK(v1) DAYOFWEEK(v2) +NULL NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000' +select DAYOFYEAR(v1), DAYOFYEAR(v2) from t; +DAYOFYEAR(v1) DAYOFYEAR(v2) +NULL NULL +Level Code Message +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00' +Warning 1292 Incorrect datetime value: '0000-00-00 00:00:00.000' +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE'; +create table t (a datetime default '2999-00-00 00:00:00'); +Error 1067 (42000): Invalid default value for 'a' +create table t (a datetime); +alter table t modify column a datetime default '2999-00-00 00:00:00'; +Error 1067 (42000): Invalid default value for 'a' +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE'; +create table t (a datetime default '0000-00-00 00:00:00'); +Error 1067 (42000): Invalid default value for 'a' +create table t (a datetime); +alter table t modify column a datetime default '0000-00-00 00:00:00'; +Error 1067 (42000): Invalid default value for 'a' +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES'; +create table t (a datetime default '2999-00-00 00:00:00'); +drop table if exists t; +create table t (a datetime default '0000-00-00 00:00:00'); +drop table if exists t; +create table t (a datetime); +alter table t modify column a datetime default '2999-00-00 00:00:00'; +alter table t modify column a datetime default '0000-00-00 00:00:00'; +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES'; +create table t (a datetime default '2999-02-30 00:00:00'); +Error 1067 (42000): Invalid default value for 'a' +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE'; +create table t (a datetime default '2999-02-30 00:00:00'); +Error 1067 (42000): Invalid default value for 'a' +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,ALLOW_INVALID_DATES'; +create table t (a datetime default '2999-02-30 00:00:00'); +drop table if exists t; +create table t (a datetime); +alter table t modify column a datetime default '2999-02-30 00:00:00'; +drop table if exists t; +set @@sql_mode=default; +drop table if exists `enum-set`; +CREATE TABLE `enum-set` (`set` SET('x00','x01','x02','x03','x04','x05','x06','x07','x08','x09','x10','x11','x12','x13','x14','x15','x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31','x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47','x48','x49','x50','x51','x52','x53','x54','x55','x56','x57','x58','x59','x60','x61','x62','x63')NOT NULL PRIMARY KEY); +INSERT INTO `enum-set` VALUES ("x00,x59"); +select `set` from `enum-set` use index(PRIMARY); +set +x00,x59 +admin check table `enum-set`; + +drop table if exists t; +create table t(a YEAR, PRIMARY KEY(a)); +insert into t set a = '2151'; +delete from t; +admin check table t; + +drop table if exists t; +set @@tidb_enable_clustered_index = 'int_only'; +create table t(a varchar(10), b varchar(10), c varchar(1), index idx(a, b, c)); +insert into t values('a', 'b', 'c'); +insert into t values('a', 'b', 'c'); +select b, _tidb_rowid from t use index(idx) where a = 'a'; +b _tidb_rowid +b 1 +b 2 +begin; +select * from t for update; +a b c +a b c +a b c +select distinct b from t use index(idx) where a = 'a'; +b +b +commit; +drop table if exists t; +create table t(a varchar(5) primary key); +insert into t values('a'); +select *, _tidb_rowid from t use index(`primary`) where _tidb_rowid=1; +a _tidb_rowid +a 1 +set @@tidb_enable_clustered_index = default; +drop table if exists t; +set sql_mode = ''; +select a, b from (select 1 a) ``, (select 2 b) ``; +Error 1248 (42000): Every derived table must have its own alias +select a, b from (select 1 a) `x`, (select 2 b) `x`; +Error 1066 (42000): Not unique table/alias: 'x' +select a, b from (select 1 a), (select 2 b); +Error 1248 (42000): Every derived table must have its own alias +select a from (select 1 a) ``, (select 2 a) ``; +Error 1248 (42000): Every derived table must have its own alias +select a from (select 1 a) `x`, (select 2 a) `x`; +Error 1066 (42000): Not unique table/alias: 'x' +select x.a from (select 1 a) `x`, (select 2 a) `x`; +Error 1066 (42000): Not unique table/alias: 'x' +select a from (select 1 a), (select 2 a); +Error 1248 (42000): Every derived table must have its own alias +set sql_mode = 'oracle'; +select a, b from (select 1 a) ``, (select 2 b) ``; +a b +1 2 +select a, b from (select 1 a) `x`, (select 2 b) `x`; +a b +1 2 +select a, b from (select 1 a), (select 2 b); +a b +1 2 +select a from (select 1 a) ``, (select 2 a) ``; +Error 1052 (23000): Column 'a' in field list is ambiguous +select a from (select 1 a) `x`, (select 2 a) `x`; +Error 1052 (23000): Column 'a' in field list is ambiguous +select x.a from (select 1 a) `x`, (select 2 a) `x`; +Error 1052 (23000): Column 'a' in field list is ambiguous +select a from (select 1 a), (select 2 a); +Error 1052 (23000): Column 'a' in field list is ambiguous +set sql_mode = default; +drop table if exists th; +set @@session.tidb_enable_table_partition = '1'; +create table th (a int, b int) partition by hash(a) partitions 3; +insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); +insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); +select b from th order by a; +b +-8 +-7 +-6 +-5 +-4 +-3 +-2 +-1 +0 +1 +2 +3 +4 +5 +6 +7 +8 +select * from th where a=-2; +a b +-2 -2 +select * from th where a=5; +a b +5 5 +drop table if exists th; +set @@session.tidb_enable_table_partition = default; +drop table if exists view_t; +create table view_t (a int,b int); +insert into view_t values(1,2); +create definer='root'@'localhost' view view1 as select * from view_t; +create definer='root'@'localhost' view view2(c,d) as select * from view_t; +create definer='root'@'localhost' view view3(c,d) as select a,b from view_t; +create definer='root'@'localhost' view view4 as select * from (select * from (select * from view_t) tb1) tb; +select * from view1; +a b +1 2 +select * from view2; +c d +1 2 +select * from view3; +c d +1 2 +select * from view4; +a b +1 2 +drop table view_t; +create table view_t(c int,d int); +select * from view1; +Error 1356 (HY000): View 'executor__executor.view1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +select * from view2; +Error 1356 (HY000): View 'executor__executor.view2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +select * from view3; +Error 1356 (HY000): View 'executor__executor.view3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +drop table view_t; +create table view_t(a int,b int,c int); +insert into view_t values(1,2,3); +select * from view1; +a b +1 2 +select * from view2; +c d +1 2 +select * from view3; +c d +1 2 +select * from view4; +a b +1 2 +alter table view_t drop column a; +alter table view_t add column a int after b; +update view_t set a=1; +select * from view1; +a b +1 2 +select * from view2; +c d +1 2 +select * from view3; +c d +1 2 +select * from view4; +a b +1 2 +drop table view_t; +drop view view1,view2,view3,view4; +set @@tidb_enable_window_function = 1; +create table t(a int, b int); +insert into t values (1,1),(1,2),(2,1),(2,2); +create definer='root'@'localhost' view v as select a, first_value(a) over(rows between 1 preceding and 1 following), last_value(a) over(rows between 1 preceding and 1 following) from t; +select * from v; +a first_value(a) over(rows between 1 preceding and 1 following) last_value(a) over(rows between 1 preceding and 1 following) +1 1 1 +1 1 2 +2 1 2 +2 2 2 +drop view v; +set @@tidb_enable_window_function = default; +drop table if exists t; +create table t(a varbinary(10)); +insert into t values ('123.12'); +select 1+a from t; +1+a +124.12 +select a-1 from t; +a-1 +122.12 +select -10*a from t; +-10*a +-1231.2 +select a/-2 from t; +a/-2 +-61.56 diff --git a/tests/integrationtest/t/executor/executor.test b/tests/integrationtest/t/executor/executor.test index a41519b5ad688..60e3e6ff51158 100644 --- a/tests/integrationtest/t/executor/executor.test +++ b/tests/integrationtest/t/executor/executor.test @@ -677,3 +677,1022 @@ set @@tidb_enable_null_aware_anti_join=true; select * from t where (a,b) not in (select a, b from s); set @@tidb_max_chunk_size=default; set @@tidb_enable_null_aware_anti_join=default; + +# TestPessimisticSelectForUpdate +drop table if exists t; +create table t(id int primary key, a int); +insert into t values(1, 1); +begin PESSIMISTIC; +select a from t where id=1 for update; +update t set a=a+1 where id=1; +commit; +select a from t where id=1; + +# TestChangePumpAndDrainer +--error 1105 +change pump to node_state ='paused' for node_id 'pump1'; +--error 1105 +change drainer to node_state ='paused' for node_id 'drainer1'; + +# TestSelectLimit +drop table if exists select_limit; +create table select_limit(id int not null default 1, name varchar(255), PRIMARY KEY(id)); +insert INTO select_limit VALUES (1, "hello"); +insert into select_limit values (2, "hello"); +insert INTO select_limit VALUES (3, "hello"); +insert INTO select_limit VALUES (4, "hello"); +select * from select_limit limit 1; +select id from (select * from select_limit limit 1) k where id != 1; +select * from select_limit limit 18446744073709551615 offset 0; +select * from select_limit limit 18446744073709551615 offset 1; +select * from select_limit limit 18446744073709551615 offset 3; +--error 1064 +select * from select_limit limit 18446744073709551616 offset 3; + +# TestSelectOrderBy +drop table if exists select_order_test; +create table select_order_test(id int not null default 1, name varchar(255), PRIMARY KEY(id)); +insert INTO select_order_test VALUES (1, "hello"); +insert into select_order_test values (2, "hello"); +select * from select_order_test where id = 1 order by id limit 1 offset 0; +select id from select_order_test order by id desc limit 1 ; +select id from select_order_test order by id + 1 desc limit 1 ; +select * from select_order_test order by name, id limit 1 offset 0; +select id as c1, name from select_order_test order by 2, id limit 1 offset 0; +select * from select_order_test order by name, id limit 100 offset 0; +select * from select_order_test order by name, id limit 1 offset 100; +select id from select_order_test order by name, id limit 18446744073709551615; +select id, name from select_order_test where id = 1 group by id, name limit 1 offset 0; +insert INTO select_order_test VALUES (3, "zz"); +insert INTO select_order_test VALUES (4, "zz"); +insert INTO select_order_test VALUES (5, "zz"); +insert INTO select_order_test VALUES (6, "zz"); +insert INTO select_order_test VALUES (7, "zz"); +insert INTO select_order_test VALUES (8, "zz"); +insert INTO select_order_test VALUES (9, "zz"); +insert INTO select_order_test VALUES (10, "zz"); +insert INTO select_order_test VALUES (10086, "hi"); +insert INTO select_order_test VALUES (11, "hh"); +insert INTO select_order_test VALUES (12, "hh"); +insert INTO select_order_test VALUES (13, "hh"); +insert INTO select_order_test VALUES (14, "hh"); +insert INTO select_order_test VALUES (15, "hh"); +insert INTO select_order_test VALUES (16, "hh"); +insert INTO select_order_test VALUES (17, "hh"); +insert INTO select_order_test VALUES (18, "hh"); +insert INTO select_order_test VALUES (19, "hh"); +insert INTO select_order_test VALUES (20, "hh"); +insert INTO select_order_test VALUES (21, "zz"); +insert INTO select_order_test VALUES (22, "zz"); +insert INTO select_order_test VALUES (23, "zz"); +insert INTO select_order_test VALUES (24, "zz"); +insert INTO select_order_test VALUES (25, "zz"); +insert INTO select_order_test VALUES (26, "zz"); +insert INTO select_order_test VALUES (27, "zz"); +insert INTO select_order_test VALUES (28, "zz"); +insert INTO select_order_test VALUES (29, "zz"); +insert INTO select_order_test VALUES (30, "zz"); +insert INTO select_order_test VALUES (1501, "aa"); +select * from select_order_test order by name, id limit 1 offset 3; +drop table if exists select_order_test; +drop table if exists t; +create table t (c int, d int); +insert t values (1, 1); +insert t values (1, 2); +insert t values (1, 3); +select 1-d as d from t order by d; +select 1-d as d from t order by d + 1; +select t.d from t order by d; +drop table if exists t; +create table t (a int, b int, c int); +insert t values (1, 2, 3); +select b from (select a,b from t order by a,c) t; +select b from (select a,b from t order by a,c limit 1) t; +drop table if exists t; +create table t(a int, b int, index idx(a)); +insert into t values(1, 1), (2, 2); +select * from t where 1 order by b; +select * from t where a between 1 and 2 order by a desc; +drop table if exists t; +create table t(a int primary key, b int, c int, index idx(b)); +insert into t values(1, 3, 1); +insert into t values(2, 2, 2); +insert into t values(3, 1, 3); +select * from t use index(idx) order by a desc limit 1; +drop table if exists t; +create table t(a int, b int, key b (b)); +set @@tidb_index_lookup_size = 3; +insert into t values(0, 10); +insert into t values(1, 9); +insert into t values(2, 8); +insert into t values(3, 7); +insert into t values(4, 6); +insert into t values(5, 5); +insert into t values(6, 4); +insert into t values(7, 3); +insert into t values(8, 2); +insert into t values(9, 1); +select a from t use index(b) order by b; +set @@tidb_index_lookup_size = default; + +# TestSelectErrorRow +--error 1146 +select row(1, 1) from test; +--error 1146 +select * from test group by row(1, 1); +--error 1146 +select * from test order by row(1, 1); +--error 1146 +select * from test having row(1, 1); +--error 1146 +select (select 1, 1) from test; +--error 1146 +select * from test group by (select 1, 1); +--error 1146 +select * from test order by (select 1, 1); +--error 1146 +select * from test having (select 1, 1); + +# TestIn +drop table if exists t; +create table t (c1 int primary key, c2 int, key c (c2)); +insert t values(0, 0); +insert t values(1, 1); +insert t values(2, 2); +insert t values(3, 3); +insert t values(4, 4); +insert t values(5, 5); +insert t values(6, 6); +insert t values(7, 7); +insert t values(8, 8); +insert t values(9, 9); +insert t values(10, 10); +insert t values(11, 11); +insert t values(12, 12); +insert t values(13, 13); +insert t values(14, 14); +insert t values(15, 15); +insert t values(16, 16); +insert t values(17, 17); +insert t values(18, 18); +insert t values(19, 19); +insert t values(20, 20); +insert t values(21, 21); +insert t values(22, 22); +insert t values(23, 23); +insert t values(24, 24); +insert t values(25, 25); +insert t values(26, 26); +insert t values(27, 27); +insert t values(28, 28); +insert t values(29, 29); +insert t values(30, 30); +insert t values(31, 31); +insert t values(32, 32); +insert t values(33, 33); +insert t values(34, 34); +insert t values(35, 35); +insert t values(36, 36); +insert t values(37, 37); +insert t values(38, 38); +insert t values(39, 39); +insert t values(40, 40); +insert t values(41, 41); +insert t values(42, 42); +insert t values(43, 43); +insert t values(44, 44); +insert t values(45, 45); +insert t values(46, 46); +insert t values(47, 47); +insert t values(48, 48); +insert t values(49, 49); +insert t values(50, 50); +insert t values(51, 51); +insert t values(52, 52); +insert t values(53, 53); +insert t values(54, 54); +insert t values(55, 55); +insert t values(56, 56); +insert t values(57, 57); +insert t values(58, 58); +insert t values(59, 59); +insert t values(60, 60); +insert t values(61, 61); +insert t values(62, 62); +insert t values(63, 63); +insert t values(64, 64); +insert t values(65, 65); +insert t values(66, 66); +insert t values(67, 67); +insert t values(68, 68); +insert t values(69, 69); +insert t values(70, 70); +insert t values(71, 71); +insert t values(72, 72); +insert t values(73, 73); +insert t values(74, 74); +insert t values(75, 75); +insert t values(76, 76); +insert t values(77, 77); +insert t values(78, 78); +insert t values(79, 79); +insert t values(80, 80); +insert t values(81, 81); +insert t values(82, 82); +insert t values(83, 83); +insert t values(84, 84); +insert t values(85, 85); +insert t values(86, 86); +insert t values(87, 87); +insert t values(88, 88); +insert t values(89, 89); +insert t values(90, 90); +insert t values(91, 91); +insert t values(92, 92); +insert t values(93, 93); +insert t values(94, 94); +insert t values(95, 95); +insert t values(96, 96); +insert t values(97, 97); +insert t values(98, 98); +insert t values(99, 99); +insert t values(100, 100); +insert t values(101, 101); +insert t values(102, 102); +insert t values(103, 103); +insert t values(104, 104); +insert t values(105, 105); +insert t values(106, 106); +insert t values(107, 107); +insert t values(108, 108); +insert t values(109, 109); +insert t values(110, 110); +insert t values(111, 111); +insert t values(112, 112); +insert t values(113, 113); +insert t values(114, 114); +insert t values(115, 115); +insert t values(116, 116); +insert t values(117, 117); +insert t values(118, 118); +insert t values(119, 119); +insert t values(120, 120); +insert t values(121, 121); +insert t values(122, 122); +insert t values(123, 123); +insert t values(124, 124); +insert t values(125, 125); +insert t values(126, 126); +insert t values(127, 127); +insert t values(128, 128); +insert t values(129, 129); +insert t values(130, 130); +insert t values(131, 131); +insert t values(132, 132); +insert t values(133, 133); +insert t values(134, 134); +insert t values(135, 135); +insert t values(136, 136); +insert t values(137, 137); +insert t values(138, 138); +insert t values(139, 139); +insert t values(140, 140); +insert t values(141, 141); +insert t values(142, 142); +insert t values(143, 143); +insert t values(144, 144); +insert t values(145, 145); +insert t values(146, 146); +insert t values(147, 147); +insert t values(148, 148); +insert t values(149, 149); +insert t values(150, 150); +insert t values(151, 151); +insert t values(152, 152); +insert t values(153, 153); +insert t values(154, 154); +insert t values(155, 155); +insert t values(156, 156); +insert t values(157, 157); +insert t values(158, 158); +insert t values(159, 159); +insert t values(160, 160); +insert t values(161, 161); +insert t values(162, 162); +insert t values(163, 163); +insert t values(164, 164); +insert t values(165, 165); +insert t values(166, 166); +insert t values(167, 167); +insert t values(168, 168); +insert t values(169, 169); +insert t values(170, 170); +insert t values(171, 171); +insert t values(172, 172); +insert t values(173, 173); +insert t values(174, 174); +insert t values(175, 175); +insert t values(176, 176); +insert t values(177, 177); +insert t values(178, 178); +insert t values(179, 179); +insert t values(180, 180); +insert t values(181, 181); +insert t values(182, 182); +insert t values(183, 183); +insert t values(184, 184); +insert t values(185, 185); +insert t values(186, 186); +insert t values(187, 187); +insert t values(188, 188); +insert t values(189, 189); +insert t values(190, 190); +insert t values(191, 191); +insert t values(192, 192); +insert t values(193, 193); +insert t values(194, 194); +insert t values(195, 195); +insert t values(196, 196); +insert t values(197, 197); +insert t values(198, 198); +insert t values(199, 199); +insert t values(200, 200); +select c2 from t where c1 in ('7', '10', '112', '111', '98', '106', '100', '9', '18', '17') order by c2; +select c2 from t where c1 in ('7a'); + +# TestTablePKisHandleScan +drop table if exists t; +create table t (a int PRIMARY KEY AUTO_INCREMENT); +insert t values (),(); +insert t values (-100),(0); +select * from t; +select * from t where a = 1; +select * from t where a != 1; +select * from t where a >= '1.1'; +select * from t where a < '1.1'; +select * from t where a > '-100.1' and a < 2; +select * from t where a is null; +select * from t where a is true; +select * from t where a is false; +select * from t where a in (1, 2); +select * from t where a between 1 and 2; + +# TestDefaultNull +drop table if exists t; +create table t (a int primary key auto_increment, b int default 1, c int); +insert t values (); +select * from t; +update t set b = NULL where a = 1; +select * from t; +update t set c = 1; +select * from t ; +delete from t where a = 1; +insert t (a) values (1); +select * from t; + +# TestJSON +drop table if exists test_json; +create table test_json (id int, a json); +insert into test_json (id, a) values (1, '{"a":[1,"2",{"aa":"bb"},4],"b":true}'); +insert into test_json (id, a) values (2, "null"); +insert into test_json (id, a) values (3, null); +insert into test_json (id, a) values (4, 'true'); +insert into test_json (id, a) values (5, '3'); +insert into test_json (id, a) values (5, '4.0'); +insert into test_json (id, a) values (6, '"string"'); +select tj.a from test_json tj order by tj.id; +select json_type(a) from test_json tj order by tj.id; +select a from test_json tj where a = 3; +select a from test_json tj where a = 4.0; +select a from test_json tj where a = true; +select a from test_json tj where a = "string"; +select cast(true as JSON); +select cast(false as JSON); +select a->>'$.a[2].aa' as x, a->'$.b' as y from test_json having x is not null order by id; +select a->'$.a[2].aa' as x, a->>'$.b' as y from test_json having x is not null order by id; +-- error 1101 +create table test_bad_json(a json default '{}'); +-- error 1101 +create table test_bad_json(a blob default 'hello'); +-- error 1101 +create table test_bad_json(a text default 'world'); +-- error 3152 +create table test_bad_json(id int, a json, key (a)); +select CAST('3' AS JSON), CAST('{}' AS JSON), CAST(null AS JSON); +select a, count(1) from test_json group by a order by a; +drop table if exists test_json; +create table test_json ( a decimal(60,2) as (JSON_EXTRACT(b,'$.c')), b json ); +insert into test_json (b) values + ('{"c": "1267.1"}'), + ('{"c": "1267.01"}'), + ('{"c": "1267.1234"}'), + ('{"c": "1267.3456"}'), + ('{"c": "1234567890123456789012345678901234567890123456789012345"}'), + ('{"c": "1234567890123456789012345678901234567890123456789012345.12345"}'); +select a from test_json; + +# TestGeneratedColumnWrite +drop table if exists test_gc_write, test_gc_write_1; +-- error 3109 +CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (a+8) virtual); +CREATE TABLE test_gc_write (a int primary key auto_increment, b int, c int as (b+8) virtual); +CREATE TABLE test_gc_write_1 (a int primary key, b int, c int); +-- error 3105 +insert into test_gc_write (a, b, c) values (1, 1, 1); +-- error 3105 +insert into test_gc_write values (1, 1, 1); +-- error 3105 +insert into test_gc_write select 1, 1, 1; +-- error 3105 +insert into test_gc_write (a, b) values (1, 1) on duplicate key update c = 1; +-- error 3105 +insert into test_gc_write set a = 1, b = 1, c = 1; +-- error 3105 +update test_gc_write set c = 1; +-- error 3105 +update test_gc_write, test_gc_write_1 set test_gc_write.c = 1; +insert into test_gc_write (a, b) values (1, 1); +insert into test_gc_write set a = 2, b = 2; +insert into test_gc_write (b) select c from test_gc_write; +update test_gc_write set b = 2 where a = 2; +update test_gc_write t1, test_gc_write_1 t2 set t1.b = 3, t2.b = 4; +-- error 1136 +insert into test_gc_write values (1, 1); +-- error 1136 +insert into test_gc_write select 1, 1; +-- error 1136 +insert into test_gc_write (c) select a, b from test_gc_write; +-- error 3105 +insert into test_gc_write (b, c) select a, b from test_gc_write; + +# TestGeneratedColumnRead +drop table if exists test_gc_read; +CREATE TABLE test_gc_read(a int primary key, b int, c int as (a+b), d int as (a*b) stored, e int as (c*2)); +SELECT generation_expression FROM information_schema.columns WHERE table_name = 'test_gc_read' AND column_name = 'd'; +INSERT INTO test_gc_read (a, b) VALUES (0,null),(1,2),(3,4); +SELECT * FROM test_gc_read ORDER BY a; +INSERT INTO test_gc_read SET a = 5, b = 10; +SELECT * FROM test_gc_read ORDER BY a; +REPLACE INTO test_gc_read (a, b) VALUES (5, 6); +SELECT * FROM test_gc_read ORDER BY a; +INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE b = 9; +SELECT * FROM test_gc_read ORDER BY a; +SELECT c, d FROM test_gc_read; +SELECT e FROM test_gc_read; +INSERT INTO test_gc_read (a, b) VALUES (5, 8) ON DUPLICATE KEY UPDATE a = 6, b = a; +SELECT * FROM test_gc_read ORDER BY a; +INSERT INTO test_gc_read (a, b) VALUES (6, 8) ON DUPLICATE KEY UPDATE b = 8, a = b; +SELECT * FROM test_gc_read ORDER BY a; +SELECT * FROM test_gc_read WHERE c = 7; +SELECT * FROM test_gc_read WHERE d = 64; +SELECT * FROM test_gc_read WHERE e = 6; +UPDATE test_gc_read SET a = a + 100 WHERE c = 7; +SELECT * FROM test_gc_read WHERE c = 107; +UPDATE test_gc_read m SET m.a = m.a + 100 WHERE c = 107; +SELECT * FROM test_gc_read WHERE c = 207; +UPDATE test_gc_read SET a = a - 200 WHERE d = 812; +SELECT * FROM test_gc_read WHERE d = 12; +INSERT INTO test_gc_read set a = 4, b = d + 1; +SELECT * FROM test_gc_read ORDER BY a; +DELETE FROM test_gc_read where a = 4; +CREATE TABLE test_gc_help(a int primary key, b int, c int, d int, e int); +INSERT INTO test_gc_help(a, b, c, d, e) SELECT * FROM test_gc_read; +SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.c = t2.c ORDER BY t1.a; +SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.d = t2.d ORDER BY t1.a; +SELECT t1.* FROM test_gc_read t1 JOIN test_gc_help t2 ON t1.e = t2.e ORDER BY t1.a; +--sorted_result +SELECT * FROM test_gc_read t WHERE t.a not in (SELECT t.a FROM test_gc_read t where t.c > 5); +--sorted_result +SELECT * FROM test_gc_read t WHERE t.c in (SELECT t.c FROM test_gc_read t where t.c > 5); +SELECT tt.b FROM test_gc_read tt WHERE tt.a = (SELECT max(t.a) FROM test_gc_read t WHERE t.c = tt.c) ORDER BY b; +SELECT c, sum(a) aa, max(d) dd, sum(e) ee FROM test_gc_read GROUP BY c ORDER BY aa; +SELECT a, sum(c), sum(d), sum(e) FROM test_gc_read GROUP BY a ORDER BY a; +UPDATE test_gc_read m, test_gc_read n SET m.b = m.b + 10, n.b = n.b + 10; +SELECT * FROM test_gc_read ORDER BY a; +drop table if exists t; +create table t(a int); +insert into t values(8); +update test_gc_read set a = a+1 where a in (select a from t); +select * from test_gc_read order by a; +CREATE TABLE test_gc_read_cast(a VARCHAR(255), b VARCHAR(255), c INT AS (JSON_EXTRACT(a, b)), d INT AS (JSON_EXTRACT(a, b)) STORED); +INSERT INTO test_gc_read_cast (a, b) VALUES ('{"a": "3"}', '$.a'); +SELECT c, d FROM test_gc_read_cast; +CREATE TABLE test_gc_read_cast_1(a VARCHAR(255), b VARCHAR(255), c ENUM("red", "yellow") AS (JSON_UNQUOTE(JSON_EXTRACT(a, b)))); +INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "yellow"}', '$.a'); +SELECT c FROM test_gc_read_cast_1; +CREATE TABLE test_gc_read_cast_2( a JSON, b JSON AS (a->>'$.a')); +INSERT INTO test_gc_read_cast_2(a) VALUES ('{"a": "{ \\\"key\\\": \\\"\\u6d4b\\\" }"}'); +SELECT b FROM test_gc_read_cast_2; +CREATE TABLE test_gc_read_cast_3( a JSON, b JSON AS (a->>'$.a'), c INT AS (b * 3.14) ); +INSERT INTO test_gc_read_cast_3(a) VALUES ('{"a": "5"}'); +SELECT c FROM test_gc_read_cast_3; +--error 1265 +INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "invalid"}', '$.a'); +DROP TABLE IF EXISTS test_gc_read_m; +CREATE TABLE test_gc_read_m (a int primary key, b int, c int as (a+1), d int as (c*2)); +INSERT INTO test_gc_read_m(a) values (1), (2); +ALTER TABLE test_gc_read_m DROP b; +SELECT * FROM test_gc_read_m; +CREATE TABLE test_gc_read_1(a int primary key, b int, c int as (a+b) not null, d int as (a*b) stored); +CREATE TABLE test_gc_read_2(a int primary key, b int, c int as (a+b), d int as (a*b) stored not null); +-- error 1048 +insert into test_gc_read_1(a, b) values (1, null); +-- error 1048 +insert into test_gc_read_2(a, b) values (1, null); + +# TestSelectPartition +set @@session.tidb_enable_list_partition = ON; +drop table if exists th, tr, tl; +create table th (a int, b int) partition by hash(a) partitions 3; +create table tr (a int, b int) + partition by range (a) ( + partition r0 values less than (4), + partition r1 values less than (7), + partition r3 values less than maxvalue); +create table tl (a int, b int, unique index idx(a)) partition by list (a) ( + 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 th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); +insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); +insert into tr values (-3,-3),(3,3),(4,4),(7,7),(8,8); +insert into tl values (3,3),(1,1),(4,4),(7,7),(8,8),(null,null); +select b from th partition (p0) order by a; +select b from tr partition (r0) order by a; +select b from tl partition (p0) order by a; +select b from th partition (p0,P0) order by a; +select b from tr partition (r0,R0,r0) order by a; +select b from tl partition (p0,P0,p0) order by a; +select b from th partition (P2,p0) order by a; +select b from tr partition (r1,R3) order by a; +select b from tl partition (p0,P3) order by a; +-- error 1735 +select b from th partition (p0,p4); +-- error 1735 +select b from tr partition (r1,r4); +-- error 1735 +select b from tl partition (p0,p4); +begin; +insert into th values (10,10),(11,11); +select a, b from th where b>10; +commit; +select a, b from th where b>10; +drop table if exists tscalar; +create table tscalar (c1 int) partition by range (c1 % 30) ( + partition p0 values less than (0), + partition p1 values less than (10), + partition p2 values less than (20), + partition pm values less than (maxvalue)); +insert into tscalar values(0), (10), (40), (50), (55); +insert into tscalar values(-0), (-10), (-40), (-50), (-55); +select * from tscalar where c1 in (55, 55); +select * from tscalar where c1 in (40, 40); +select * from tscalar where c1 in (40); +select * from tscalar where c1 in (-40); +select * from tscalar where c1 in (-40, -40); +select * from tscalar where c1 in (-1); +set @@session.tidb_enable_list_partition = default; + +# TestPrepareLoadData +-- error 1295 +prepare stmt from "load data local infile '/tmp/load_data_test.csv' into table test"; + +# TestPrepareImportInto +-- error 1295 +prepare stmt from "import into test from 'xx' format 'delimited'"; + +# TestHandleTransfer +drop table if exists t; +create table t(a int, index idx(a)); +insert into t values(1), (2), (4); +begin; +update t set a = 3 where a = 4; +select * from t ignore index(idx); +insert into t values(4); +select * from t use index(idx); +select * from t use index(idx) order by a desc; +update t set a = 5 where a = 3; +select * from t use index(idx); +commit; +drop table if exists t; +create table t(a int, b int, index idx(a)); +insert into t values(3, 3), (1, 1), (2, 2); +select * from t use index(idx) order by a; + +# TestMaxInt64Handle +drop table if exists t; +create table t(id bigint, PRIMARY KEY (id)); +insert into t values(9223372036854775807); +select * from t where id = 9223372036854775807; +select * from t where id = 9223372036854775807; +select * from t; +--error 1062 +insert into t values(9223372036854775807); +delete from t where id = 9223372036854775807; +select * from t; + +# TestUnsignedPk +drop table if exists t; +create table t(id bigint unsigned primary key); +insert into t values(9223372036854775808), (9223372036854775809), (1), (2); +select * from t order by id; +select * from t where id not in (2); +drop table if exists t; +create table t(a bigint unsigned primary key, b int, index idx(b)); +insert into t values(9223372036854775808, 1), (1, 1); +select * from t use index(idx) where b = 1 and a < 2; +select * from t use index(idx) where b = 1 order by b, a; + +# TestSignedCommonHandle +set @@tidb_enable_clustered_index = 1; +drop table if exists t; +create table t(k1 int, k2 int, primary key(k1, k2)); +insert into t(k1, k2) value(-100, 1), (-50, 1), (0, 0), (1, 1), (3, 3); +select k1 from t order by k1; +select k1 from t order by k1 desc; +select k1 from t where k1 < -51; +select k1 from t where k1 < -1; +select k1 from t where k1 <= 0; +select k1 from t where k1 < 2; +select k1 from t where k1 < -1 and k1 > -90; +set @@tidb_enable_clustered_index = default; + +# TestContainDotColumn +drop table if exists t1, t2, t3; +create table t1(t1.a char); +create table t2(a char, t2.b int); +-- error 1103 +create table t3(s.a char); + +# TestCheckTableClusterIndex +set @@tidb_enable_clustered_index = 1; +drop table if exists admin_test; +create table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1, c2), index (c1), unique key(c2)); +insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3); +admin check table admin_test; +set @@tidb_enable_clustered_index = default; + +# TestIncorrectLimitArg +drop table if exists t; +create table t(a bigint); +prepare stmt1 from 'select * from t limit ?'; +prepare stmt2 from 'select * from t limit ?, ?'; +set @a = -1; +set @b = 1; +-- error 1210 +execute stmt1 using @a; +-- error 1210 +execute stmt2 using @b, @a; +-- error 1210 +execute stmt2 using @a, @b; +-- error 1210 +execute stmt2 using @a, @a; + +# TestEmptyEnum +drop table if exists t; +create table t (e enum('Y', 'N')); +set sql_mode='STRICT_TRANS_TABLES'; +--error 1265 +insert into t values (0); +--error 1265 +insert into t values ('abc'); +set sql_mode=''; +insert into t values (0); +select * from t; +insert into t values ('abc'); +select * from t; +insert into t values (null); +select * from t; +drop table if exists t; +create table t (id int auto_increment primary key, c1 enum('a', '', 'c')); +insert into t(c1) values (0); +select id, c1+0, c1 from t; +alter table t change c1 c1 enum('a', '') not null; +select id, c1+0, c1 from t; +insert into t(c1) values (0); +select id, c1+0, c1 from t; +set sql_mode=default; + +# TestDIVZeroInPartitionExpr +drop table if exists t1; +create table t1(a int) partition by range (10 div a) (partition p0 values less than (10), partition p1 values less than maxvalue); +set @@sql_mode=''; +insert into t1 values (NULL), (0), (1); +set @@sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO'; +-- error 1365 +insert into t1 values (NULL), (0), (1); +set @@sql_mode=default; + +# TestInsertIntoGivenPartitionSet +drop table if exists t1; +create table t1( + a int(11) DEFAULT NULL, + b varchar(10) DEFAULT NULL, + UNIQUE KEY idx_a (a)) PARTITION BY RANGE (a) + (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, + PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, + PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, + PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, + PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +insert into t1 partition(p0) values(1, 'a'), (2, 'b'); +select * from t1 partition(p0) order by a; +insert into t1 partition(p0, p1) values(3, 'c'), (4, 'd'); +select * from t1 partition(p1); +-- error 1062 +insert into t1 values(1, 'a'); +-- error 1735 +insert into t1 partition(p0, p_non_exist) values(1, 'a'); +-- error 1748 +insert into t1 partition(p0, p1) values(40, 'a'); +replace into t1 partition(p0) values(1, 'replace'); +replace into t1 partition(p0, p1) values(3, 'replace'), (4, 'replace'); +replace into t1 values(1, 'a'); +select * from t1 partition (p0) order by a; +-- error 1735 +replace into t1 partition(p0, p_non_exist) values(1, 'a'); +-- error 1748 +replace into t1 partition(p0, p1) values(40, 'a'); +truncate table t1; +drop table if exists t; +create table t(a int, b char(10)); +-- error 1747 +insert into t partition(p0, p1) values(1, 'a'); +insert into t values(1, 'a'), (2, 'b'); +insert into t1 partition(p0) select * from t; +select * from t1 partition(p0) order by a; +truncate table t; +insert into t values(3, 'c'), (4, 'd'); +insert into t1 partition(p0, p1) select * from t; +select * from t1 partition(p1) order by a; +select * from t1 partition(p0) order by a; +-- error 1062 +insert into t1 select 1, 'a'; +-- error 1735 +insert into t1 partition(p0, p_non_exist) select 1, 'a'; +-- error 1748 +insert into t1 partition(p0, p1) select 40, 'a'; +replace into t1 partition(p0) select 1, 'replace'; +truncate table t; +insert into t values(3, 'replace'), (4, 'replace'); +replace into t1 partition(p0, p1) select * from t; +replace into t1 select 1, 'a'; +select * from t1 partition (p0) order by a; +-- error 1735 +replace into t1 partition(p0, p_non_exist) select 1, 'a'; +-- error 1748 +replace into t1 partition(p0, p1) select 40, 'a'; + +# TestUpdateGivenPartitionSet +drop table if exists t1, t2, t3; +create table t1( + a int(11), + b varchar(10) DEFAULT NULL, + primary key idx_a (a)) PARTITION BY RANGE (a) + (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, + PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, + PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, + PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, + PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +create table t2( + a int(11) DEFAULT NULL, + b varchar(10) DEFAULT NULL) PARTITION BY RANGE (a) + (PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB, + PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB, + PARTITION p2 VALUES LESS THAN (30) ENGINE = InnoDB, + PARTITION p3 VALUES LESS THAN (40) ENGINE = InnoDB, + PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +create table t3 (a int(11), b varchar(10) default null); +insert into t3 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); +-- error 1747 +update t3 partition(p0) set a = 40 where a = 2; +insert into t1 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); +-- error 1748 +update t1 partition(p0, p1) set a = 40; +-- error 1748 +update t1 partition(p0) set a = 40 where a = 2; +-- error 1735 +update t1 partition (p0, p_non_exist) set a = 40; +-- error 1748 +update t1 partition (p0), t3 set t1.a = 40 where t3.a = 2; +update t1 partition(p0) set a = 3 where a = 2; +update t1 partition(p0, p3) set a = 33 where a = 1; +insert into t2 values(1, 'a'), (2, 'b'), (11, 'c'), (21, 'd'); +-- error 1748 +update t2 partition(p0, p1) set a = 40; +-- error 1748 +update t2 partition(p0) set a = 40 where a = 2; +update t2 partition(p0) set a = 3 where a = 2; +update t2 partition(p0, p3) set a = 33 where a = 1; +drop table if exists t4; +create table t4(a int primary key, b int) partition by hash(a) partitions 2; +insert into t4(a, b) values(1, 1),(2, 2),(3, 3); +-- error 1748 +update t4 partition(p0) set a = 5 where a = 2; + +# TestIssue19667 +drop table if exists t; +CREATE TABLE t (a DATETIME); +INSERT INTO t VALUES('1988-04-17 01:59:59'); +SELECT DATE_ADD(a, INTERVAL 1 SECOND) FROM t; + +# TestZeroDateTimeCompatibility +--enable_warnings +select YEAR(0000-00-00), YEAR("0000-00-00"); +select MONTH(0000-00-00), MONTH("0000-00-00"); +select DAYOFMONTH(0000-00-00), DAYOFMONTH("0000-00-00"); +select QUARTER(0000-00-00), QUARTER("0000-00-00"); +select EXTRACT(DAY FROM 0000-00-00), EXTRACT(DAY FROM "0000-00-00"); +select EXTRACT(MONTH FROM 0000-00-00), EXTRACT(MONTH FROM "0000-00-00"); +select EXTRACT(YEAR FROM 0000-00-00), EXTRACT(YEAR FROM "0000-00-00"); +select EXTRACT(WEEK FROM 0000-00-00), EXTRACT(WEEK FROM "0000-00-00"); +select EXTRACT(QUARTER FROM 0000-00-00), EXTRACT(QUARTER FROM "0000-00-00"); +select DAYOFWEEK(0000-00-00), DAYOFWEEK("0000-00-00"); +select DAYOFYEAR(0000-00-00), DAYOFYEAR("0000-00-00"); +--disable_warnings +drop table if exists t; +create table t(v1 datetime, v2 datetime(3)); +insert ignore into t values(0,0); +--enable_warnings +select YEAR(v1), YEAR(v2) from t; +select MONTH(v1), MONTH(v2) from t; +select DAYOFMONTH(v1), DAYOFMONTH(v2) from t; +select QUARTER(v1), QUARTER(v2) from t; +select EXTRACT(DAY FROM v1), EXTRACT(DAY FROM v2) from t; +select EXTRACT(MONTH FROM v1), EXTRACT(MONTH FROM v2) from t; +select EXTRACT(YEAR FROM v1), EXTRACT(YEAR FROM v2) from t; +select EXTRACT(WEEK FROM v1), EXTRACT(WEEK FROM v2) from t; +select EXTRACT(QUARTER FROM v1), EXTRACT(QUARTER FROM v2) from t; +select DAYOFWEEK(v1), DAYOFWEEK(v2) from t; +select DAYOFYEAR(v1), DAYOFYEAR(v2) from t; +--disable_warnings + +# TestInvalidDateValueInCreateTable +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE'; +-- error 1067 +create table t (a datetime default '2999-00-00 00:00:00'); +create table t (a datetime); +-- error 1067 +alter table t modify column a datetime default '2999-00-00 00:00:00'; +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE'; +-- error 1067 +create table t (a datetime default '0000-00-00 00:00:00'); +create table t (a datetime); +-- error 1067 +alter table t modify column a datetime default '0000-00-00 00:00:00'; +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES'; +create table t (a datetime default '2999-00-00 00:00:00'); +drop table if exists t; +create table t (a datetime default '0000-00-00 00:00:00'); +drop table if exists t; +create table t (a datetime); +alter table t modify column a datetime default '2999-00-00 00:00:00'; +alter table t modify column a datetime default '0000-00-00 00:00:00'; +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES'; +-- error 1067 +create table t (a datetime default '2999-02-30 00:00:00'); +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE'; +-- error 1067 +create table t (a datetime default '2999-02-30 00:00:00'); +drop table if exists t; +set @@sql_mode='STRICT_TRANS_TABLES,ALLOW_INVALID_DATES'; +create table t (a datetime default '2999-02-30 00:00:00'); +drop table if exists t; +create table t (a datetime); +alter table t modify column a datetime default '2999-02-30 00:00:00'; +drop table if exists t; +set @@sql_mode=default; + +# TestEncodingSet +drop table if exists `enum-set`; +CREATE TABLE `enum-set` (`set` SET('x00','x01','x02','x03','x04','x05','x06','x07','x08','x09','x10','x11','x12','x13','x14','x15','x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31','x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47','x48','x49','x50','x51','x52','x53','x54','x55','x56','x57','x58','x59','x60','x61','x62','x63')NOT NULL PRIMARY KEY); +INSERT INTO `enum-set` VALUES ("x00,x59"); +select `set` from `enum-set` use index(PRIMARY); +admin check table `enum-set`; + +# TestYearTypeDeleteIndex +drop table if exists t; +create table t(a YEAR, PRIMARY KEY(a)); +insert into t set a = '2151'; +delete from t; +admin check table t; + +# TestRowID +drop table if exists t; +set @@tidb_enable_clustered_index = 'int_only'; +create table t(a varchar(10), b varchar(10), c varchar(1), index idx(a, b, c)); +insert into t values('a', 'b', 'c'); +insert into t values('a', 'b', 'c'); +select b, _tidb_rowid from t use index(idx) where a = 'a'; +begin; +select * from t for update; +select distinct b from t use index(idx) where a = 'a'; +commit; +drop table if exists t; +create table t(a varchar(5) primary key); +insert into t values('a'); +select *, _tidb_rowid from t use index(`primary`) where _tidb_rowid=1; +set @@tidb_enable_clustered_index = default; + +# TestSubqueryTableAlias +drop table if exists t; +set sql_mode = ''; +-- error 1248 +select a, b from (select 1 a) ``, (select 2 b) ``; +-- error 1066 +select a, b from (select 1 a) `x`, (select 2 b) `x`; +-- error 1248 +select a, b from (select 1 a), (select 2 b); +-- error 1248 +select a from (select 1 a) ``, (select 2 a) ``; +-- error 1066 +select a from (select 1 a) `x`, (select 2 a) `x`; +-- error 1066 +select x.a from (select 1 a) `x`, (select 2 a) `x`; +-- error 1248 +select a from (select 1 a), (select 2 a); +set sql_mode = 'oracle'; +select a, b from (select 1 a) ``, (select 2 b) ``; +select a, b from (select 1 a) `x`, (select 2 b) `x`; +select a, b from (select 1 a), (select 2 b); +-- error 1052 +select a from (select 1 a) ``, (select 2 a) ``; +-- error 1052 +select a from (select 1 a) `x`, (select 2 a) `x`; +-- error 1052 +select x.a from (select 1 a) `x`, (select 2 a) `x`; +-- error 1052 +select a from (select 1 a), (select 2 a); +set sql_mode = default; + +# TestSelectHashPartitionTable +drop table if exists th; +set @@session.tidb_enable_table_partition = '1'; +create table th (a int, b int) partition by hash(a) partitions 3; +insert into th values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); +insert into th values (-1,-1),(-2,-2),(-3,-3),(-4,-4),(-5,-5),(-6,-6),(-7,-7),(-8,-8); +select b from th order by a; +select * from th where a=-2; +select * from th where a=5; +drop table if exists th; +set @@session.tidb_enable_table_partition = default; + +# TestSelectView +drop table if exists view_t; +create table view_t (a int,b int); +insert into view_t values(1,2); +create definer='root'@'localhost' view view1 as select * from view_t; +create definer='root'@'localhost' view view2(c,d) as select * from view_t; +create definer='root'@'localhost' view view3(c,d) as select a,b from view_t; +create definer='root'@'localhost' view view4 as select * from (select * from (select * from view_t) tb1) tb; +select * from view1; +select * from view2; +select * from view3; +select * from view4; +drop table view_t; +create table view_t(c int,d int); +-- error 1356 +select * from view1; +-- error 1356 +select * from view2; +-- error 1356 +select * from view3; +drop table view_t; +create table view_t(a int,b int,c int); +insert into view_t values(1,2,3); +select * from view1; +select * from view2; +select * from view3; +select * from view4; +alter table view_t drop column a; +alter table view_t add column a int after b; +update view_t set a=1; +select * from view1; +select * from view2; +select * from view3; +select * from view4; +drop table view_t; +drop view view1,view2,view3,view4; +set @@tidb_enable_window_function = 1; +create table t(a int, b int); +insert into t values (1,1),(1,2),(2,1),(2,2); +create definer='root'@'localhost' view v as select a, first_value(a) over(rows between 1 preceding and 1 following), last_value(a) over(rows between 1 preceding and 1 following) from t; +select * from v; +drop view v; +set @@tidb_enable_window_function = default; + +# TestBinaryStrNumericOperator +drop table if exists t; +create table t(a varbinary(10)); +insert into t values ('123.12'); +--enable_warnings +select 1+a from t; +select a-1 from t; +select -10*a from t; +select a/-2 from t; +--disable_warnings