diff --git a/ddl/BUILD.bazel b/ddl/BUILD.bazel index 35e692fd0f350..43740e59f2a1f 100644 --- a/ddl/BUILD.bazel +++ b/ddl/BUILD.bazel @@ -192,7 +192,6 @@ go_test( "db_cache_test.go", "db_change_failpoints_test.go", "db_change_test.go", - "db_foreign_key_test.go", "db_integration_test.go", "db_rename_test.go", "db_table_test.go", diff --git a/ddl/constraint_test.go b/ddl/constraint_test.go index 49181c6b45ea4..4b13d968f6421 100644 --- a/ddl/constraint_test.go +++ b/ddl/constraint_test.go @@ -16,7 +16,6 @@ package ddl_test import ( "fmt" - "sort" "testing" "github.com/pingcap/failpoint" @@ -29,872 +28,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestCreateTableWithCheckConstraints(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 @@global.tidb_enable_check_constraint = 1") - - // Test column-type check constraint. - tk.MustExec("create table t(a int not null check(a>0))") - constraintTable := external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 1, len(constraintTable.Meta().Columns)) - require.Equal(t, 1, len(constraintTable.Meta().Constraints)) - constrs := constraintTable.Meta().Constraints - require.Equal(t, int64(1), constrs[0].ID) - require.True(t, constrs[0].InColumn) - require.True(t, constrs[0].Enforced) - require.Equal(t, "t", constrs[0].Table.L) - require.Equal(t, model.StatePublic, constrs[0].State) - require.Equal(t, 1, len(constrs[0].ConstraintCols)) - require.Equal(t, model.NewCIStr("a"), constrs[0].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[0].Name) - require.Equal(t, "`a` > 0", constrs[0].ExprString) - - tk.MustExec("drop table t") - tk.MustExec("create table t(a bigint key constraint my_constr check(a<10), b int constraint check(b > 1) not enforced)") - constraintTable = external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - constrs = constraintTable.Meta().Constraints - require.Equal(t, 2, len(constrs)) - require.Equal(t, int64(1), constrs[0].ID) - require.True(t, constrs[0].InColumn) - require.True(t, constrs[0].Enforced) - require.Equal(t, "t", constrs[0].Table.L) - require.Equal(t, model.StatePublic, constrs[0].State) - require.Equal(t, 1, len(constrs[0].ConstraintCols)) - require.Equal(t, model.NewCIStr("a"), constrs[0].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("my_constr"), constrs[0].Name) - require.Equal(t, "`a` < 10", constrs[0].ExprString) - - require.Equal(t, int64(2), constrs[1].ID) - require.True(t, constrs[1].InColumn) - require.False(t, constrs[1].Enforced) - require.Equal(t, 1, len(constrs[0].ConstraintCols)) - require.Equal(t, "t", constrs[1].Table.L) - require.Equal(t, model.StatePublic, constrs[1].State) - require.Equal(t, 1, len(constrs[1].ConstraintCols)) - require.Equal(t, model.NewCIStr("b"), constrs[1].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[1].Name) - require.Equal(t, "`b` > 1", constrs[1].ExprString) - - // Test table-type check constraint. - tk.MustExec("drop table t") - tk.MustExec("create table t(a int constraint check(a > 1) not enforced, constraint my_constr check(a < 10))") - constraintTable = external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 1, len(constraintTable.Meta().Columns)) - constrs = constraintTable.Meta().Constraints - require.Equal(t, 2, len(constrs)) - // table-type check constraint. - require.Equal(t, int64(1), constrs[0].ID) - require.False(t, constrs[0].InColumn) - require.True(t, constrs[0].Enforced) - require.Equal(t, "t", constrs[0].Table.L) - require.Equal(t, model.StatePublic, constrs[0].State) - require.Equal(t, 1, len(constrs[0].ConstraintCols)) - require.Equal(t, model.NewCIStr("a"), constrs[0].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("my_constr"), constrs[0].Name) - require.Equal(t, "`a` < 10", constrs[0].ExprString) - - // column-type check constraint. - require.Equal(t, int64(2), constrs[1].ID) - require.True(t, constrs[1].InColumn) - require.False(t, constrs[1].Enforced) - require.Equal(t, "t", constrs[1].Table.L) - require.Equal(t, model.StatePublic, constrs[1].State) - require.Equal(t, 1, len(constrs[1].ConstraintCols)) - require.Equal(t, model.NewCIStr("a"), constrs[1].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[1].Name) - require.Equal(t, "`a` > 1", constrs[1].ExprString) - - // Test column-type check constraint fail on dependency. - tk.MustExec("drop table t") - _, err := tk.Exec("create table t(a int not null check(b>0))") - require.Errorf(t, err, "[ddl:3813]Column check constraint 't_chk_1' references other column.") - - _, err = tk.Exec("create table t(a int not null check(b>a))") - require.Errorf(t, err, "[ddl:3813]Column check constraint 't_chk_1' references other column.") - - _, err = tk.Exec("create table t(a int not null check(a>0), b int, constraint check(c>b))") - require.Errorf(t, err, "[ddl:3820]Check constraint 't_chk_1' refers to non-existing column 'c'.") - - tk.MustExec("create table t(a int not null check(a>0), b int, constraint check(a>b))") - tk.MustExec("drop table t") - - tk.MustExec("create table t(a int not null check(a > '12345'))") - tk.MustExec("drop table t") - - tk.MustExec("create table t(a int not null primary key check(a > '12345'))") - tk.MustExec("drop table t") - - tk.MustExec("create table t(a varchar(10) not null primary key check(a > '12345'))") - tk.MustExec("drop table t") -} - -func TestAlterTableAddCheckConstraints(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 @@global.tidb_enable_check_constraint = 1") - - tk.MustExec("create table t(a int not null check(a>0))") - // Add constraint with name. - tk.MustExec("alter table t add constraint haha check(a<10)") - constraintTable := external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 1, len(constraintTable.Meta().Columns)) - require.Equal(t, 2, len(constraintTable.Meta().Constraints)) - constrs := constraintTable.Meta().Constraints - require.Equal(t, int64(2), constrs[1].ID) - require.False(t, constrs[1].InColumn) - require.True(t, constrs[1].Enforced) - require.Equal(t, "t", constrs[1].Table.L) - require.Equal(t, model.StatePublic, constrs[1].State) - require.Equal(t, 1, len(constrs[1].ConstraintCols)) - require.Equal(t, model.NewCIStr("a"), constrs[1].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("haha"), constrs[1].Name) - require.Equal(t, "`a` < 10", constrs[1].ExprString) - - // Add constraint without name. - tk.MustExec("alter table t add constraint check(a<11) not enforced") - constraintTable = external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 1, len(constraintTable.Meta().Columns)) - require.Equal(t, 3, len(constraintTable.Meta().Constraints)) - constrs = constraintTable.Meta().Constraints - require.Equal(t, int64(3), constrs[2].ID) - require.False(t, constrs[2].InColumn) - require.False(t, constrs[2].Enforced) - require.Equal(t, "t", constrs[2].Table.L) - require.Equal(t, model.StatePublic, constrs[2].State) - require.Equal(t, 1, len(constrs[2].ConstraintCols)) - require.Equal(t, model.NewCIStr("a"), constrs[2].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("t_chk_2"), constrs[2].Name) - require.Equal(t, "`a` < 11", constrs[2].ExprString) - - // Add constraint with the name has already existed. - _, err := tk.Exec("alter table t add constraint haha check(a)") - require.Errorf(t, err, "[schema:3822]Duplicate check constraint name 'haha'.") - - // Add constraint with the unknown column. - _, err = tk.Exec("alter table t add constraint check(b)") - require.Errorf(t, err, "[ddl:3820]Check constraint 't_chk_3' refers to non-existing column 'b'.") - - tk.MustExec("alter table t add constraint check(a*2 < a+1) not enforced") - // test add check constraint verify remain data - tk.MustExec("drop table t") - tk.MustExec("create table t(a int)") - tk.MustExec("insert into t values(1), (2), (3)") - tk.MustGetErrMsg("alter table t add constraint check(a < 2)", "[ddl:3819]Check constraint 't_chk_1' is violated.") - tk.MustGetErrMsg("alter table t add constraint check(a < 2) not enforced", "[ddl:3819]Check constraint 't_chk_2' is violated.") -} - -func TestAlterTableDropCheckConstraints(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 @@global.tidb_enable_check_constraint = 1") - - tk.MustExec("create table t(a int not null check(a>0), b int, constraint haha check(a < b), check(a 0", constrs[2].ExprString) - - // Drop a non-exist constraint - _, err := tk.Exec("alter table t drop constraint not_exist_constraint") - require.Errorf(t, err, "[ddl:3940]Constraint 'not_exist_constraint' does not exist") - - tk.MustExec("alter table t drop constraint haha") - constraintTable = external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - require.Equal(t, 2, len(constraintTable.Meta().Constraints)) - constrs = constraintTable.Meta().Constraints - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[0].Name) - require.Equal(t, model.NewCIStr("t_chk_2"), constrs[1].Name) - - tk.MustExec("alter table t drop constraint t_chk_2") - constraintTable = external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - require.Equal(t, 1, len(constraintTable.Meta().Constraints)) - constrs = constraintTable.Meta().Constraints - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[0].Name) - - tk.MustExec("drop table t") - tk.MustExec("create table t(a int check(a > 0))") - tk.MustGetErrMsg("insert into t values(0)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("alter table t drop constraint t_chk_1") - tk.MustExec("insert into t values(0)") -} - -func TestAlterTableAlterCheckConstraints(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 @@global.tidb_enable_check_constraint = 1") - - tk.MustExec("create table t(a int not null check(a>0) not enforced, b int, constraint haha check(a < b))") - constraintTable := external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - require.Equal(t, 2, len(constraintTable.Meta().Constraints)) - constrs := constraintTable.Meta().Constraints - - require.Equal(t, int64(1), constrs[0].ID) - require.False(t, constrs[0].InColumn) - require.True(t, constrs[0].Enforced) - require.Equal(t, "t", constrs[0].Table.L) - require.Equal(t, model.StatePublic, constrs[0].State) - require.Equal(t, 2, len(constrs[0].ConstraintCols)) - sort.Slice(constrs[0].ConstraintCols, func(i, j int) bool { - return constrs[0].ConstraintCols[i].L < constrs[0].ConstraintCols[j].L - }) - require.Equal(t, model.NewCIStr("a"), constrs[0].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("b"), constrs[0].ConstraintCols[1]) - require.Equal(t, model.NewCIStr("haha"), constrs[0].Name) - require.Equal(t, "`a` < `b`", constrs[0].ExprString) - - require.Equal(t, int64(2), constrs[1].ID) - require.True(t, constrs[1].InColumn) - require.False(t, constrs[1].Enforced) - require.Equal(t, "t", constrs[1].Table.L) - require.Equal(t, model.StatePublic, constrs[1].State) - require.Equal(t, 1, len(constrs[1].ConstraintCols)) - require.Equal(t, model.NewCIStr("a"), constrs[1].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[1].Name) - require.Equal(t, "`a` > 0", constrs[1].ExprString) - - // Alter constraint alter constraint with unknown name. - _, err := tk.Exec("alter table t alter constraint unknown not enforced") - require.Errorf(t, err, "[ddl:3940]Constraint 'unknown' does not exist") - - // Alter table alter constraint with user name. - tk.MustExec("alter table t alter constraint haha not enforced") - constraintTable = external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - require.Equal(t, 2, len(constraintTable.Meta().Constraints)) - constrs = constraintTable.Meta().Constraints - require.False(t, constrs[0].Enforced) - require.Equal(t, model.NewCIStr("haha"), constrs[0].Name) - require.False(t, constrs[1].Enforced) - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[1].Name) - - // Alter table alter constraint with generated name. - tk.MustExec("alter table t alter constraint t_chk_1 enforced") - constraintTable = external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - require.Equal(t, 2, len(constraintTable.Meta().Constraints)) - constrs = constraintTable.Meta().Constraints - require.False(t, constrs[0].Enforced) - require.Equal(t, model.NewCIStr("haha"), constrs[0].Name) - require.True(t, constrs[1].Enforced) - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[1].Name) - - // Alter table alter constraint will violate check. - // Here a=1, b=0 doesn't satisfy "a < b" constraint. - // Since "a 0), b int, c int, check(c > 0), check (b > c))") - tk.MustExec("alter table t drop column a") - constraintTable := external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - require.Equal(t, 2, len(constraintTable.Meta().Constraints)) - tk.MustGetErrMsg("alter table t drop column b", "[ddl:3959]Check constraint 't_chk_2' uses column 'b', hence column cannot be dropped or renamed.") - tk.MustGetErrMsg("alter table t rename column c to c1", "[ddl:3959]Check constraint 't_chk_1' uses column 'c', hence column cannot be dropped or renamed.") -} - -func TestCheckConstraintsNotEnforcedWorks(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int check(a > 0), b int check(b < 10) not enforced, c int)") - tk.MustExec("alter table t alter constraint t_chk_1 not enforced") - tk.MustExec("insert into t values(-1, 1, 0)") - tk.MustExec("alter table t alter constraint t_chk_2 enforced") - tk.MustGetErrMsg("insert into t values(-1, 11, 0)", "[table:3819]Check constraint 't_chk_2' is violated.") - tk.MustExec("alter table t add check(c = 0)") - tk.MustGetErrMsg("insert into t values(-1, 1, 1)", "[table:3819]Check constraint 't_chk_3' is violated.") - tk.MustExec("alter table t alter constraint t_chk_3 not enforced") - tk.MustExec("insert into t values(-1, 1, 0)") -} - -func TestUnsupportedCheckConstraintsExprWhenCreateTable(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 @@global.tidb_enable_check_constraint = 1") - // functions - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + NOW() > '2011-11-21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: now.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIMESTAMP() > '2011-11-21 01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIMESTAMP > '2011-11-21 01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 DATETIME CHECK (f1 + CURDATE() > '2011-11-21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: curdate.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 DATETIME CHECK (f1 + CURTIME() > '23:11:21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: curtime.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_DATE() > '2011-11-21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_date.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_DATE > '2011-11-21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_date.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIME() > '01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_time.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIME > '01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_time.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 DATETIME CHECK (f1 + LOCALTIME() > '23:11:21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtime.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 DATETIME CHECK (f1 + LOCALTIME > '23:11:21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtime.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + LOCALTIMESTAMP() > '2011-11-21 01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + LOCALTIMESTAMP > '2011-11-21 01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + UNIX_TIMESTAMP() > '2011-11-21 01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: unix_timestamp.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 DATETIME CHECK (f1 + UTC_DATE() > '2011-11-21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: utc_date.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + UTC_TIMESTAMP() > '2011-11-21 01:02:03'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: utc_timestamp.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 DATETIME CHECK (f1 + UTC_TIME() > '23:11:21'));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: utc_time.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 INT CHECK (f1 + CONNECTION_ID() < 929));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: connection_id.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(32) CHECK (CURRENT_USER() != a));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_user.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(32) CHECK (CURRENT_USER != a));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_user.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(32) CHECK (SESSION_USER() != a));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: session_user.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(32) CHECK (VERSION() != a));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: version.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(1024), b INT CHECK (b + FOUND_ROWS() > 2000));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: found_rows.") - tk.MustGetErrMsg("CREATE TABLE t1 (a INT CHECK ((a + LAST_INSERT_ID()) < 929));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: last_insert_id.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(32) CHECK (SYSTEM_USER() != a));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: system_user.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(32) CHECK (USER() != a));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: user.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 FLOAT CHECK (f1 + RAND() < 929.929));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: rand.") - tk.MustGetErrMsg("CREATE TABLE t1 (a INT CHECK (a + ROW_COUNT() > 1000));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: row_count.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (GET_LOCK(b,10) != 0));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: get_lock.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (IS_FREE_LOCK(b) != 0));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: is_free_lock.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (IS_USED_LOCK(b) != 0));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: is_used_lock.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (RELEASE_LOCK(b) != 0));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: release_lock.") - tk.MustGetErrMsg("CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024), CHECK (RELEASE_ALL_LOCKS() != 0));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: release_all_locks.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 VARCHAR(1024), f2 VARCHAR(1024) CHECK (LOAD_FILE(f2) != NULL));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: load_file.") - tk.MustGetErrMsg("CREATE TABLE t1 (id CHAR(40) CHECK(UUID() != id));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: uuid.") - tk.MustGetErrMsg("CREATE TABLE t1 (id INT CHECK(UUID_SHORT() != id));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: uuid_short.") - tk.MustGetErrMsg("CREATE TABLE t1 (id INT CHECK(SLEEP(id) != 0));", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: sleep.") - // udf var and system var - tk.MustExec("set @a = 1") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 int CHECK (f1 > @a))", "[ddl:3816]An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 int CHECK (f1 > @@session.tidb_mem_quota_query))", "[ddl:3816]An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable.") - tk.MustGetErrMsg("CREATE TABLE t1 (f1 int CHECK (f1 > @@global.tidb_mem_quota_query))", "[ddl:3816]An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable.") - // auto-increment column - tk.MustGetErrMsg("CREATE TABLE t1 (f1 int primary key auto_increment, f2 int, CHECK (f1 != f2));", "[ddl:3818]Check constraint 't1_chk_1' cannot refer to an auto-increment column.") - // default - tk.MustGetErrMsg("CREATE TABLE t1 (f1 INT CHECK (f1 = default(f1)))", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: default.") - // subquery - tk.MustGetErrMsg("CREATE TABLE t1 (id INT CHECK (id != (SELECT 1)));", "[ddl:3815]An expression of a check constraint 't1_chk_1' contains disallowed function.") - tk.MustGetErrMsg("CREATE TABLE t1 (a int check(a in (SELECT COALESCE(NULL, 1, 1))))", "[ddl:3815]An expression of a check constraint 't1_chk_1' contains disallowed function.") -} - -func TestUnsupportedCheckConstraintsExprWhenAlterTable(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t1(f1 TIMESTAMP, f2 DATETIME, f3 INT, f4 VARCHAR(32), f5 FLOAT, f6 CHAR(40), f7 INT PRIMARY KEY AUTO_INCREMENT)") - // functions - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + NOW() > '2011-11-21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: now.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIMESTAMP() > '2011-11-21 01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIMESTAMP > '2011-11-21 01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f2 + CURDATE() > '2011-11-21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: curdate.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f2 + CURTIME() > '23:11:21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: curtime.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + CURRENT_DATE() > '2011-11-21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_date.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + CURRENT_DATE > '2011-11-21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_date.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIME() > '01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_time.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIME > '01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_time.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f2 + LOCALTIME() > '23:11:21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtime.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f2 + LOCALTIME > '23:11:21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtime.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + LOCALTIMESTAMP() > '2011-11-21 01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + LOCALTIMESTAMP > '2011-11-21 01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + UNIX_TIMESTAMP() > '2011-11-21 01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: unix_timestamp.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f2 + UTC_DATE() > '2011-11-21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: utc_date.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 + UTC_TIMESTAMP() > '2011-11-21 01:02:03');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: utc_timestamp.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f2 + UTC_TIME() > '23:11:21');", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: utc_time.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f3 + CONNECTION_ID() < 929);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: connection_id.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (CURRENT_USER() != f4);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_user.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (CURRENT_USER != f4);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: current_user.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (SESSION_USER() != f4);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: session_user.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (VERSION() != f4);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: version.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f3 + FOUND_ROWS() > 2000);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: found_rows.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK ((f3 + LAST_INSERT_ID()) < 929);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: last_insert_id.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (SYSTEM_USER() != f4);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: system_user.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (USER() != f4);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: user.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f5 + RAND() < 929.929);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: rand.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f3 + ROW_COUNT() > 1000);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: row_count.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (GET_LOCK(f4,10) != 0);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: get_lock.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (IS_FREE_LOCK(f4) != 0);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: is_free_lock.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (IS_USED_LOCK(f4) != 0);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: is_used_lock.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (RELEASE_LOCK(f4) != 0);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: release_lock.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (RELEASE_ALL_LOCKS() != 0);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: release_all_locks.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (LOAD_FILE(f4) != NULL);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: load_file.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK(UUID() != f6);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: uuid.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK(UUID_SHORT() != f3);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: uuid_short.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK(SLEEP(f3) != 0);", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: sleep.") - // udf var and system var - tk.MustExec("set @a = 1") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f3 > @a)", "[ddl:3816]An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f3 > @@session.tidb_mem_quota_query)", "[ddl:3816]An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f3 > @@global.tidb_mem_quota_query)", "[ddl:3816]An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable.") - // auto-increment column - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f7 != f3);", "[ddl:3818]Check constraint 't1_chk_1' cannot refer to an auto-increment column.") - // default - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f1 = default(f1))", "[ddl:3814]An expression of a check constraint 't1_chk_1' contains disallowed function: default.") - // subquery - tk.MustGetErrMsg("ALTER TABLE t1 ADD CHECK (f3 != (SELECT 1));", "[ddl:3815]An expression of a check constraint 't1_chk_1' contains disallowed function.") - tk.MustGetErrMsg("ALTER TABLE t1 ADD check (f3 in (SELECT COALESCE(NULL, 1, 1)))", "[ddl:3815]An expression of a check constraint 't1_chk_1' contains disallowed function.") -} - -func TestNameInCreateTableLike(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int check(a > 10), b int constraint bbb check(b > 5), c int, check(c < 0))") - tk.MustExec("create table s like t") - - constraintTable := external.GetTableByName(t, tk, "test", "s") - require.Equal(t, 3, len(constraintTable.Meta().Columns)) - require.Equal(t, 3, len(constraintTable.Meta().Constraints)) - constrs := constraintTable.Meta().Constraints - require.Equal(t, model.NewCIStr("s_chk_1"), constrs[0].Name) - require.Equal(t, model.NewCIStr("s_chk_2"), constrs[1].Name) - require.Equal(t, model.NewCIStr("s_chk_3"), constrs[2].Name) - tk.MustGetErrMsg("insert into s(a) values(1)", "[table:3819]Check constraint 's_chk_2' is violated.") - tk.MustGetErrMsg("insert into s(b) values(2)", "[table:3819]Check constraint 's_chk_3' is violated.") - tk.MustGetErrMsg("insert into s(c) values(3)", "[table:3819]Check constraint 's_chk_1' is violated.") - - tk.MustExec("alter table s add check(a > 0)") - tk.MustExec("alter table s add constraint aaa check(a > 0)") - constraintTable = external.GetTableByName(t, tk, "test", "s") - require.Equal(t, 5, len(constraintTable.Meta().Constraints)) - constrs = constraintTable.Meta().Constraints - require.Equal(t, model.NewCIStr("s_chk_4"), constrs[3].Name) - require.Equal(t, model.NewCIStr("aaa"), constrs[4].Name) -} - -func TestInsertUpdateIgnoreWarningMessage(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int check(a > 10))") - tk.MustGetErrMsg("insert into t values(1),(11),(15)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("insert ignore into t values(1),(11),(15)") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 3819 Check constraint 't_chk_1' is violated.")) - tk.MustQuery("select a from t").Check(testkit.Rows("11]\n[15")) - - tk.MustExec("update ignore t set a = a-2") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 3819 Check constraint 't_chk_1' is violated.")) - tk.MustQuery("select a from t").Check(testkit.Rows("11]\n[13")) -} - -func TestCheckConstraintForeignKey(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, s") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int, b int, index(a), index(a, b))") - tk.MustGetErrMsg("create table s(a int, check (a > 0), foreign key (a) references t(a) on update cascade)", - "[ddl:3823]Column 'a' cannot be used in a check constraint 's_chk_1': needed in a foreign key constraint referential action.") - tk.MustGetErrMsg("create table s(a int, b int, check (a > 0), foreign key (a, b) references t(a, b) on update cascade)", - "[ddl:3823]Column 'a' cannot be used in a check constraint 's_chk_1': needed in a foreign key constraint referential action.") - - tk.MustExec("create table t1(a int, foreign key (a) references t(a) on update cascade)") - tk.MustGetErrMsg("alter table t1 add check ( a > 0 )", - "[ddl:3823]Column 'a' cannot be used in a check constraint 't1_chk_1': needed in a foreign key constraint referential action.") - tk.MustExec("create table t2(a int, b int, foreign key (a, b) references t(a, b) on update cascade)") - tk.MustGetErrMsg("alter table t2 add check ( a > 0 )", - "[ddl:3823]Column 'a' cannot be used in a check constraint 't2_chk_1': needed in a foreign key constraint referential action.") -} - -func TestCheckConstrainNonBoolExpr(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 @@global.tidb_enable_check_constraint = 1") - tk.MustGetErrMsg("create table t(a int, check(a))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(1))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check('1'))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int check(a))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(1+1))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(1/2))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(a + 1/2))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int check(a + 1/2))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(true + 1))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(abs(1)))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(length(a)))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(length(1)))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(floor(1.1)))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check(mod(3, 2)))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - tk.MustGetErrMsg("create table t(a int, check('true'))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_1'.") - - tk.MustExec("create table t(a int, check(true))") - tk.MustGetErrMsg("alter table t add check(a)", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(1)", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check('1')", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(1/2)", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(a + 1/2)", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(true + 1)", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(abs(1))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(length(a))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(length(1))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(length(1))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check(mod(3, 2))", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") - tk.MustGetErrMsg("alter table t add check('true')", "[ddl:3812]An expression of non-boolean type specified to a check constraint 't_chk_2'.") -} - -func TestAlterAddCheckConstrainColumnBadErr(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int)") - tk.MustGetErrMsg("alter table t add check(b > 0)", "[ddl:1054]Unknown column 'b' in 'check constraint t_chk_1 expression'") -} - -func TestCheckConstraintBoolExpr(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a json, b varchar(20))") - tk.MustExec("alter table t add check (JSON_VALID(a))") - tk.MustExec("alter table t add check (REGEXP_LIKE(b,'@'))") -} - -func TestCheckConstraintNameMaxLength(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 @@global.tidb_enable_check_constraint = 1") - var str64, str65 string - for i := 0; i < 64; i++ { - str64 += "a" - } - str65 = str64 + "a" - // create table - tk.MustExec(fmt.Sprintf("create table t(a int constraint %s check(a > 0))", str64)) - tk.MustExec("drop table t") - tk.MustExec(fmt.Sprintf("create table t(a int, constraint %s check(a > 0))", str64)) - tk.MustExec("drop table t") - tk.MustGetErrMsg(fmt.Sprintf("create table t(a int constraint %s check(a > 0))", str65), "[ddl:1059]Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long") - tk.MustGetErrMsg(fmt.Sprintf("create table t(a int, constraint %s check(a > 0))", str65), "[ddl:1059]Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long") - tk.MustGetErrMsg(fmt.Sprintf("create table %s(a int check(a > 0))", str64), "[ddl:1059]Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_chk_1' is too long") - tk.MustGetErrMsg(fmt.Sprintf("create table %s(a int, check(a > 0))", str64), "[ddl:1059]Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_chk_1' is too long") - // alter table - tk.MustExec("create table t(a int)") - tk.MustGetErrMsg(fmt.Sprintf("alter table t add constraint %s check(a > 0)", str65), "[ddl:1059]Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long") - tk.MustExec(fmt.Sprintf("alter table t add constraint %s check(a > 0)", str64)) - tk.MustExec("drop table t") - tk.MustExec(fmt.Sprintf("create table %s(a int)", str64)) - tk.MustGetErrMsg(fmt.Sprintf("alter table %s add check(a > 0)", str64), "[ddl:1059]Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_chk_1' is too long") -} - -func TestCheckConstraintNameCaseAndAccentSensitivity(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int)") - tk.MustExec("alter table t add constraint `cafe` check(a > 0)") - tk.MustGetErrMsg("alter table t add constraint `CAFE` check(a > 0)", "[schema:3822]Duplicate check constraint name 'cafe'.") - tk.MustExec("alter table t add constraint `café` check(a > 0)") -} - -func TestCheckConstraintEvaluated(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, s") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int check(a > 0))") - tk.MustExec("insert into t values(1)") - tk.MustExec("create table s(a int)") - tk.MustExec("insert into s values(-1)") - // insert - tk.MustGetErrMsg("insert into t values(-1)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("insert into t values(1)") - tk.MustGetErrMsg("insert into t(a) values(-1)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("insert into t(a) values(1)") - tk.MustGetErrMsg("insert into t set a = -1", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("insert into t set a = 1") - tk.MustGetErrMsg("insert into t(a) select -1", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("insert into t(a) select 1") - tk.MustGetErrMsg("insert into t(a) select a from s", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("insert into t(a) select a + 2 from s") - // update - tk.MustGetErrMsg("update t set a = -1", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("update t set a = 1") - tk.MustGetErrMsg("update t set a = a-1", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("update t set a = a+1") - tk.MustGetErrMsg("update t set a = -1 where a > 0", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("update t set a = 1 where a > 0") - tk.MustGetErrMsg("update t set a = (select a from s where a < 0) where a > 0", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("update t set a = (select a + 2 from s where a < 0) where a > 0") - tk.MustGetErrMsg("update t as a, s as b set a.a=b.a", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("update t as a, s as b set a.a=b.a + 2") - // replace - tk.MustGetErrMsg("replace into t(a) values(-1)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("replace into t(a) values(1)") - tk.MustGetErrMsg("replace into t(a) select -1", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("replace into t(a) select 1") - tk.MustGetErrMsg("replace into t set a = -1", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("replace into t set a = 1") -} - -func TestGenerateColumnCheckConstraint(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t( a int, b int as (a+1), CHECK (b > 0));") - tk.MustExec("insert into t(a) values(0)") - tk.MustGetErrMsg("insert into t(a) values(-2)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("alter table t alter constraint t_chk_1 not enforced") - tk.MustExec("insert into t(a) values(-2)") - - constraintTable := external.GetTableByName(t, tk, "test", "t") - require.Equal(t, 2, len(constraintTable.Meta().Columns)) - require.Equal(t, 1, len(constraintTable.Meta().Constraints)) - constrs := constraintTable.Meta().Constraints - require.Equal(t, int64(1), constrs[0].ID) - require.False(t, constrs[0].InColumn) - require.False(t, constrs[0].Enforced) - require.Equal(t, "t", constrs[0].Table.L) - require.Equal(t, model.StatePublic, constrs[0].State) - require.Equal(t, 1, len(constrs[0].ConstraintCols)) - require.Equal(t, model.NewCIStr("b"), constrs[0].ConstraintCols[0]) - require.Equal(t, model.NewCIStr("t_chk_1"), constrs[0].Name) - require.Equal(t, "`b` > 0", constrs[0].ExprString) - - tk.MustExec("alter table t drop constraint t_chk_1") - tk.MustExec("drop table t") - tk.MustExec("create table t(a int, b int as (a+1))") - tk.MustExec("alter table t add check(b > 0)") - tk.MustExec("insert into t(a) values(0)") - tk.MustGetErrMsg("insert into t(a) values(-2)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("alter table t alter constraint t_chk_1 not enforced") - tk.MustExec("insert into t(a) values(-2)") - tk.MustExec("alter table t drop constraint t_chk_1") - tk.MustGetErrMsg("alter table t add check(b > 0)", "[ddl:3819]Check constraint 't_chk_1' is violated.") -} - -func TestTemporaryTableCheckConstraint(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int, CHECK (a < -999));") - // local temporary table - tk.MustExec("drop temporary table if exists t;") - tk.MustExec("create temporary table t(a int, CHECK (a > 0));") - tk.MustExec("insert into t(a) values(1)") - tk.MustGetErrMsg("insert into t(a) values(-2)", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("drop temporary table t") - tk.MustExec("create temporary table t(a int, CHECK (a > 0) not enforced);") - tk.MustExec("insert into t values(-1)") - // global temporary table - tk.MustExec("create global temporary table tt(a int, check(a > 0)) on commit delete rows") - tk.MustExec("insert into tt(a) values(1)") - tk.MustGetErrMsg("insert into tt(a) values(-2)", "[table:3819]Check constraint 'tt_chk_1' is violated.") - tk.MustExec("alter table tt alter constraint tt_chk_1 not enforced") - tk.MustExec("insert into tt(a) values(-2)") - tk.MustExec("alter table tt drop constraint tt_chk_1") -} - -func TestCheckConstraintWithPrepareInsertCheckConstraint(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 @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int CHECK (a != 0));") - tk.MustExec("prepare stmt from 'insert into t values(?)'") - tk.MustExec("set @a = 1") - tk.MustExec("execute stmt using @a") - tk.MustExec("set @a = 0") - tk.MustGetErrMsg("execute stmt using @a", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("deallocate prepare stmt") -} - -func TestCheckConstraintOnDuplicateKeyUpdate(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, s") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int primary key, b int, check (b > 0))") - tk.MustExec("insert into t values(1, 1)") - tk.MustGetErrMsg("insert into t values(1, -10) on duplicate key update b = -1", "[table:3819]Check constraint 't_chk_1' is violated.") - tk.MustExec("insert ignore into t values(1, -10) on duplicate key update b = -1") - tk.MustQuery("select * from t").Check(testkit.Rows("1 1")) - tk.MustExec("create table s(a int primary key, check (a > 0))") - tk.MustExec("insert into s values(1)") - tk.MustGetErrMsg("insert into s values(1) on duplicate key update a = -1", "[table:3819]Check constraint 's_chk_1' is violated.") - tk.MustExec("insert ignore into s values(1) on duplicate key update a = -1") - tk.MustQuery("select * from s").Check(testkit.Rows("1")) -} - -func TestCheckConstraintOnInsert(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("DROP DATABASE IF EXISTS test_insert_check_constraint;") - tk.MustExec("CREATE DATABASE test_insert_check_constraint;") - tk.MustExec("USE test_insert_check_constraint;") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - tk.MustExec("CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0));") - tk.MustGetErrMsg("insert into t1 values (2, 2)", "[table:3819]Check constraint 't1_chk_1' is violated.") - tk.MustGetErrMsg("insert into t1 values (9, 2)", "[table:3819]Check constraint 't1_chk_2' is violated.") - tk.MustGetErrMsg("insert into t1 values (14, -4)", "[table:3819]Check constraint 'c2_positive' is violated.") - tk.MustGetErrMsg("insert into t1(c1) values (9)", "[table:3819]Check constraint 't1_chk_2' is violated.") - tk.MustGetErrMsg("insert into t1(c2) values (-3)", "[table:3819]Check constraint 'c2_positive' is violated.") - tk.MustExec("insert into t1 values (14, 4)") - tk.MustExec("insert into t1 values (null, 4)") - tk.MustExec("insert into t1 values (13, null)") - tk.MustExec("insert into t1 values (null, null)") - tk.MustExec("insert into t1(c1) values (null)") - tk.MustExec("insert into t1(c2) values (null)") - - // Test generated column with check constraint. - tk.MustExec("CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15));") - tk.MustGetErrMsg("insert into t2(c1, c2) values (11, 1)", "[table:3819]Check constraint 't2_chk_3' is violated.") - tk.MustExec("insert into t2(c1, c2) values (12, 7)") -} - -func TestCheckConstraintOnUpdate(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("DROP DATABASE IF EXISTS test_update_check_constraint;") - tk.MustExec("CREATE DATABASE test_update_check_constraint;") - tk.MustExec("USE test_update_check_constraint;") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - - tk.MustExec("CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0));") - tk.MustExec("insert into t1 values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16);") - tk.MustGetErrMsg("update t1 set c2 = -c2;", "[table:3819]Check constraint 'c2_positive' is violated.") - tk.MustGetErrMsg("update t1 set c2 = c1;", "[table:3819]Check constraint 't1_chk_1' is violated.") - tk.MustGetErrMsg("update t1 set c1 = c1 - 10;", "[table:3819]Check constraint 't1_chk_2' is violated.") - tk.MustGetErrMsg("update t1 set c2 = -10 where c2 = 12;", "[table:3819]Check constraint 'c2_positive' is violated.") - - // Test generated column with check constraint. - tk.MustExec("CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15));") - tk.MustExec("insert into t2(c1, c2) values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16);") - tk.MustGetErrMsg("update t2 set c2 = c2 - 10;", "[table:3819]Check constraint 't2_chk_3' is violated.") - tk.MustExec("update t2 set c2 = c2 - 5;") -} - -func TestCheckConstraintOnUpdateWithPartition(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("DROP DATABASE IF EXISTS test_update_check_constraint_hash;") - tk.MustExec("CREATE DATABASE test_update_check_constraint_hash;") - tk.MustExec("USE test_update_check_constraint_hash;") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - - tk.MustExec("CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0)) partition by hash(c2) partitions 5;") - tk.MustExec("insert into t1 values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16);") - tk.MustGetErrMsg("update t1 set c2 = -c2;", "[table:3819]Check constraint 'c2_positive' is violated.") - tk.MustGetErrMsg("update t1 set c2 = c1;", "[table:3819]Check constraint 't1_chk_1' is violated.") - tk.MustGetErrMsg("update t1 set c1 = c1 - 10;", "[table:3819]Check constraint 't1_chk_2' is violated.") - tk.MustGetErrMsg("update t1 set c2 = -10 where c2 = 12;", "[table:3819]Check constraint 'c2_positive' is violated.") - - // Test generated column with check constraint. - tk.MustExec("CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15)) partition by hash(c2) partitions 5;") - tk.MustExec("insert into t2(c1, c2) values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16);") - tk.MustGetErrMsg("update t2 set c2 = c2 - 10;", "[table:3819]Check constraint 't2_chk_3' is violated.") - tk.MustExec("update t2 set c2 = c2 - 5;") -} - -func TestShowCheckConstraint(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 @@global.tidb_enable_check_constraint = 1") - // Create table with check constraint - tk.MustExec("create table t(a int check (a>1), b int, constraint my_constr check(a<10))") - tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" + - " `a` int(11) DEFAULT NULL,\n" + - " `b` int(11) DEFAULT NULL,\n" + - "CONSTRAINT `my_constr` CHECK ((`a` < 10)),\n" + - "CONSTRAINT `t_chk_1` CHECK ((`a` > 1))\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - // Alter table add constraint. - tk.MustExec("alter table t add constraint my_constr2 check (a 1)),\n" + - "CONSTRAINT `my_constr2` CHECK ((`a` < `b`)) /*!80016 NOT ENFORCED */\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - // Alter table drop constraint. - tk.MustExec("alter table t drop constraint t_chk_1") - tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" + - " `a` int(11) DEFAULT NULL,\n" + - " `b` int(11) DEFAULT NULL,\n" + - "CONSTRAINT `my_constr` CHECK ((`a` < 10)),\n" + - "CONSTRAINT `my_constr2` CHECK ((`a` < `b`)) /*!80016 NOT ENFORCED */\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - tk.MustExec("drop table if exists t") -} - func TestAlterConstraintAddDrop(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) @@ -1154,47 +287,3 @@ func TestAlterEnforcedConstraintStateChange(t *testing.T) { tk.MustExec("alter table t alter constraint c1 enforced") tk.MustQuery("select * from t").Check(testkit.Rows("12")) } - -func TestIssue44689(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - for _, expr := range []string{"true", "false"} { - tk.MustExec("DROP TABLE IF EXISTS t0, t1, t2") - tk.MustExec(fmt.Sprintf("CREATE TABLE t0(c1 NUMERIC CHECK(%s))", expr)) - - tk.MustExec(fmt.Sprintf("CREATE TABLE t1(c1 NUMERIC, CHECK(%s))", expr)) - - tk.MustExec("CREATE TABLE t2(c1 NUMERIC)") - tk.MustExec(fmt.Sprintf("ALTER TABLE t2 ADD CONSTRAINT CHECK(%s)", expr)) - } -} - -func TestCheckConstraintSwitch(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int check(a > 0))") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 the switch of check constraint is off")) - tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - - tk.MustExec("drop table t") - tk.MustExec("set @@global.tidb_enable_check_constraint = 1") - tk.MustExec("create table t(a int check(a > 0))") - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL,\nCONSTRAINT `t_chk_1` CHECK ((`a` > 0))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - tk.MustExec("alter table t add constraint chk check(true)") - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustExec("alter table t alter constraint chk not enforced") - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustExec("alter table t drop constraint chk") - tk.MustQuery("show warnings").Check(testkit.Rows()) - - tk.MustExec("set @@global.tidb_enable_check_constraint = 0") - tk.MustExec("alter table t drop constraint t_chk_1") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 the switch of check constraint is off")) - tk.MustExec("alter table t alter constraint t_chk_1 not enforced") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 the switch of check constraint is off")) - tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL,\nCONSTRAINT `t_chk_1` CHECK ((`a` > 0))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) -} diff --git a/ddl/db_cache_test.go b/ddl/db_cache_test.go index be2f37e3eb159..a16523df4174a 100644 --- a/ddl/db_cache_test.go +++ b/ddl/db_cache_test.go @@ -37,95 +37,6 @@ func checkTableCacheStatus(t *testing.T, tk *testkit.TestKit, dbName, tableName require.Equal(t, status, tb.Meta().TableCacheStatusType) } -func TestAlterPartitionCache(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists cache_partition_table;") - tk.MustExec("create table cache_partition_table (a int, b int) partition by hash(a) partitions 3;") - tk.MustGetErrCode("alter table cache_partition_table cache", errno.ErrOptOnCacheTable) - defer tk.MustExec("drop table if exists cache_partition_table;") - tk.MustExec("drop table if exists cache_partition_range_table;") - tk.MustExec(`create table cache_partition_range_table (c1 smallint(6) not null, c2 char(5) default null) partition by range ( c1 ) ( - partition p0 values less than (10), - partition p1 values less than (20), - partition p2 values less than (30), - partition p3 values less than (MAXVALUE) - );`) - tk.MustGetErrCode("alter table cache_partition_range_table cache;", errno.ErrOptOnCacheTable) - defer tk.MustExec("drop table if exists cache_partition_range_table;") - tk.MustExec("drop table if exists partition_list_table;") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec(`create table cache_partition_list_table (id int) partition by list (id) ( - partition p0 values in (1,2), - partition p1 values in (3,4), - partition p3 values in (5,null) - );`) - tk.MustGetErrCode("alter table cache_partition_list_table cache", errno.ErrOptOnCacheTable) - tk.MustExec("drop table if exists cache_partition_list_table;") -} - -func TestAlterViewTableCache(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists cache_view_t") - tk.MustExec("create table cache_view_t (id int);") - tk.MustExec("create view v as select * from cache_view_t") - tk.MustGetErrCode("alter table v cache", errno.ErrWrongObject) -} - -func TestAlterTableNoCache(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists nocache_t1") - /* Test of cache table */ - tk.MustExec("create table nocache_t1 ( n int auto_increment primary key)") - tk.MustExec("alter table nocache_t1 cache") - checkTableCacheStatus(t, tk, "test", "nocache_t1", model.TableCacheStatusEnable) - tk.MustExec("alter table nocache_t1 nocache") - checkTableCacheStatus(t, tk, "test", "nocache_t1", model.TableCacheStatusDisable) - tk.MustExec("drop table if exists t1") - // Test if a table is not exists - tk.MustExec("drop table if exists nocache_t") - tk.MustGetErrCode("alter table nocache_t cache", errno.ErrNoSuchTable) - tk.MustExec("create table nocache_t (a int)") - tk.MustExec("alter table nocache_t nocache") - // Multiple no alter cache is okay - tk.MustExec("alter table nocache_t nocache") - tk.MustExec("alter table nocache_t nocache") -} - -func TestIndexOnCacheTable(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - /*Test cache table can't add/drop/rename index */ - tk.MustExec("drop table if exists cache_index") - tk.MustExec("create table cache_index (c1 int primary key, c2 int, c3 int, index ok2(c2))") - defer tk.MustExec("drop table if exists cache_index") - tk.MustExec("alter table cache_index cache") - tk.MustGetErrCode("create index cache_c2 on cache_index(c2)", errno.ErrOptOnCacheTable) - tk.MustGetErrCode("alter table cache_index add index k2(c2)", errno.ErrOptOnCacheTable) - tk.MustGetErrCode("alter table cache_index drop index ok2", errno.ErrOptOnCacheTable) - /*Test rename index*/ - tk.MustGetErrCode("alter table cache_index rename index ok2 to ok", errno.ErrOptOnCacheTable) - /*Test drop different indexes*/ - tk.MustExec("drop table if exists cache_index_1") - tk.MustExec("create table cache_index_1 (id int, c1 int, c2 int, primary key(id), key i1(c1), key i2(c2));") - tk.MustExec("alter table cache_index_1 cache") - tk.MustGetErrCode("alter table cache_index_1 drop index i1, drop index i2;", errno.ErrOptOnCacheTable) - - // cleanup - tk.MustExec("alter table cache_index_1 nocache") - tk.MustExec("alter table cache_index nocache") -} - func TestAlterTableCache(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) @@ -245,19 +156,6 @@ func TestCacheTableSizeLimit(t *testing.T) { tk.MustGetErrCode("insert into cache_t2 select * from tmp;", errno.ErrOptOnCacheTable) } -func TestIssue32692(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("create table cache_t2 (c1 int);") - tk.MustExec("alter table cache_t2 cache;") - tk.MustExec("alter table cache_t2 nocache;") - // Check no warning message here. - tk.MustExec("alter table cache_t2 cache;") - tk.MustQuery("show warnings").Check(testkit.Rows()) -} - func TestIssue34069(t *testing.T) { store := testkit.CreateMockStore(t) sem.Enable() diff --git a/ddl/db_change_test.go b/ddl/db_change_test.go index 855c366d0b394..f4cd50d93e486 100644 --- a/ddl/db_change_test.go +++ b/ddl/db_change_test.go @@ -26,7 +26,6 @@ import ( "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/ddl/util/callback" "github.com/pingcap/tidb/domain" - "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -414,32 +413,6 @@ type expectQuery struct { rows []string } -func TestAppendEnum(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database test_db_state default charset utf8 default collate utf8_bin") - tk.MustExec("use test_db_state") - tk.MustExec(`create table t ( - c1 varchar(64), - c2 enum('N','Y') not null default 'N', - c3 timestamp on update current_timestamp, - c4 int primary key, - unique key idx2 (c2, c3))`) - tk.MustExec("insert into t values('a', 'N', '2017-07-01', 8)") - // Make sure these SQLs use the plan of index scan. - tk.MustExec("drop stats t") - tk.MustGetErrMsg("insert into t values('a', 'A', '2018-09-19', 9)", "[types:1265]Data truncated for column 'c2' at row 1") - tk.MustExec("alter table t change c2 c2 enum('N') DEFAULT 'N'") - tk.MustExec("alter table t change c2 c2 int default 0") - tk.MustExec("alter table t change c2 c2 enum('N','Y','A') DEFAULT 'A'") - tk.MustExec("insert into t values('a', 'A', '2018-09-20', 10)") - tk.MustExec("insert into t (c1, c3, c4) values('a', '2018-09-21', 11)") - tk.MustQuery("select c4, c2 from t order by c4 asc").Check(testkit.Rows("8 N", "10 A", "11 A")) - // fixed - tk.MustExec("update t set c2='N' where c4 = 10") - tk.MustQuery("select c2 from t where c4 = 10").Check(testkit.Rows("N")) -} - // https://github.com/pingcap/tidb/pull/6249 fixes the following two test cases. func TestWriteOnlyWriteNULL(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) @@ -1899,15 +1872,6 @@ func TestDropExpressionIndex(t *testing.T) { tk.MustQuery("select * from t order by a, b").Check(testkit.Rows("0 9", "0 11", "1 7", "2 7", "5 7", "8 8", "10 10")) } -func TestExpressionIndexDDLError(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int, b int, index idx((a+b)))") - tk.MustGetErrCode("alter table t rename column b to b2", errno.ErrDependentByFunctionalIndex) - tk.MustGetErrCode("alter table t drop column b", errno.ErrDependentByFunctionalIndex) -} - func TestParallelRenameTable(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) diff --git a/ddl/db_foreign_key_test.go b/ddl/db_foreign_key_test.go deleted file mode 100644 index f45db3934d89a..0000000000000 --- a/ddl/db_foreign_key_test.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2022 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ddl_test - -import ( - "testing" - - "github.com/pingcap/tidb/errno" - "github.com/pingcap/tidb/parser/mysql" - "github.com/pingcap/tidb/testkit" -) - -func TestDuplicateForeignKey(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - // Foreign table. - tk.MustExec("create table t(id int key)") - // Create target table with duplicate fk. - tk.MustGetErrCode("create table t1(id int, id_fk int, CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`), CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`))", mysql.ErrFkDupName) - tk.MustGetErrCode("create table t1(id int, id_fk int, CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`), CONSTRAINT `fk_aaA` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`))", mysql.ErrFkDupName) - - tk.MustExec("create table t1(id int, id_fk int, CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`))") - // Alter target table with duplicate fk. - tk.MustGetErrCode("alter table t1 add CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`)", mysql.ErrFkDupName) - tk.MustGetErrCode("alter table t1 add CONSTRAINT `fk_aAa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`)", mysql.ErrFkDupName) - tk.MustExec("drop table if exists t, t1") -} - -func TestTemporaryTableForeignKey(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1 (a int, b int);") - tk.MustExec("drop table if exists t1_tmp;") - tk.MustExec("create global temporary table t1_tmp (a int, b int) on commit delete rows;") - tk.MustExec("create temporary table t2_tmp (a int, b int)") - // test add foreign key. - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t2 (a int, b int);") - failSQL := "alter table t1_tmp add foreign key (c) REFERENCES t2(a);" - tk.MustGetErrCode(failSQL, mysql.ErrCannotAddForeign) - failSQL = "alter table t2_tmp add foreign key (c) REFERENCES t2(a);" - tk.MustGetErrCode(failSQL, errno.ErrUnsupportedDDLOperation) - // Test drop column with foreign key. - failSQL = "create global temporary table t3 (c int,d int,foreign key (d) references t1 (b)) on commit delete rows;" - tk.MustGetErrCode(failSQL, mysql.ErrCannotAddForeign) - failSQL = "create temporary table t4(c int,d int,foreign key (d) references t1 (b));" - tk.MustGetErrCode(failSQL, mysql.ErrCannotAddForeign) - tk.MustExec("drop table if exists t1,t2,t3, t4,t1_tmp,t2_tmp;") -} diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index d12cdf3d66673..77f85a1f25dd9 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -49,101 +49,12 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/testkit/external" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/collate" "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/mock" "github.com/stretchr/testify/require" ) -func TestNoZeroDateMode(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - defer tk.MustExec("set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';") - - tk.MustExec("use test;") - tk.MustExec("set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION';") - tk.MustGetErrCode("create table test_zero_date(agent_start_time date NOT NULL DEFAULT '0000-00-00')", errno.ErrInvalidDefault) - tk.MustGetErrCode("create table test_zero_date(agent_start_time datetime NOT NULL DEFAULT '0000-00-00 00:00:00')", errno.ErrInvalidDefault) - tk.MustGetErrCode("create table test_zero_date(agent_start_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00')", errno.ErrInvalidDefault) - tk.MustGetErrCode("create table test_zero_date(a timestamp default '0000-00-00 00');", errno.ErrInvalidDefault) - tk.MustGetErrCode("create table test_zero_date(a timestamp default 0);", errno.ErrInvalidDefault) - defer tk.MustExec(`drop table if exists test_zero_date`) - tk.MustExec("set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';") - tk.MustExec("create table test_zero_date (a timestamp default 0)") - tk.MustExec(`insert into test_zero_date values (0)`) - tk.MustQuery(`select a, unix_timestamp(a) from test_zero_date`).Check(testkit.Rows("0000-00-00 00:00:00 0")) - tk.MustExec(`update test_zero_date set a = '2001-01-01 11:11:11' where a = 0`) - tk.MustExec(`replace into test_zero_date values (0)`) - tk.MustExec(`delete from test_zero_date where a = 0`) - tk.MustExec(`update test_zero_date set a = 0 where a = '2001-01-01 11:11:11'`) - tk.MustExec("set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';") - tk.MustGetErrCode(`insert into test_zero_date values (0)`, errno.ErrTruncatedWrongValue) - tk.MustGetErrCode(`replace into test_zero_date values (0)`, errno.ErrTruncatedWrongValue) - tk.MustGetErrCode(`update test_zero_date set a = 0 where a = 0`, errno.ErrTruncatedWrongValue) - tk.MustExec(`delete from test_zero_date where a = 0`) - tk.MustQuery(`select a, unix_timestamp(a) from test_zero_date`).Check(testkit.Rows()) - tk.MustExec(`drop table test_zero_date`) - tk.MustExec("set session sql_mode=''") - tk.MustExec("create table test_zero_date (a timestamp default 0)") - tk.MustExec(`drop table test_zero_date`) - tk.MustExec(`create table test_zero_date (a int)`) - tk.MustExec(`insert into test_zero_date values (0)`) - tk.MustExec(`alter table test_zero_date modify a date`) - tk.MustExec("set session sql_mode='NO_ZERO_DATE'") - tk.MustExec(`drop table test_zero_date`) - tk.MustExec("create table test_zero_date (a timestamp default 0)") - tk.MustExec(`drop table test_zero_date`) - tk.MustExec(`create table test_zero_date (a int)`) - tk.MustExec(`insert into test_zero_date values (0)`) - tk.MustExec(`alter table test_zero_date modify a date`) - tk.MustExec("set session sql_mode='STRICT_TRANS_TABLES'") - tk.MustExec(`drop table test_zero_date`) - tk.MustExec("create table test_zero_date (a timestamp default 0)") - tk.MustExec(`drop table test_zero_date`) - tk.MustExec(`create table test_zero_date (a int)`) - tk.MustExec(`insert into test_zero_date values (0)`) - tk.MustGetErrCode(`alter table test_zero_date modify a date`, errno.ErrTruncatedWrongValue) - tk.MustExec("set session sql_mode='NO_ZERO_DATE,STRICT_TRANS_TABLES'") - tk.MustExec(`drop table test_zero_date`) - tk.MustGetErrCode("create table test_zero_date (a timestamp default 0)", errno.ErrInvalidDefault) - tk.MustExec(`create table test_zero_date (a int)`) - tk.MustExec(`insert into test_zero_date values (0)`) - tk.MustGetErrCode(`alter table test_zero_date modify a date`, errno.ErrTruncatedWrongValue) -} - -func TestInvalidDefault(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("USE test;") - - tk.MustGetDBError("create table t(c1 decimal default 1.7976931348623157E308)", types.ErrInvalidDefault) - tk.MustGetDBError("create table t( c1 varchar(2) default 'TiDB');", types.ErrInvalidDefault) -} - -// TestKeyWithoutLength for issue #13452 -func TestKeyWithoutLengthCreateTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test") - tk.MustMatchErrMsg("create table t_without_length (a text primary key)", - ".*BLOB/TEXT column 'a' used in key specification without a key length") -} - -// TestInvalidNameWhenCreateTable for issue #3848 -func TestInvalidNameWhenCreateTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("USE test;") - - tk.MustGetErrCode("create table t(xxx.t.a bigint)", errno.ErrWrongDBName) - tk.MustGetErrCode("create table t(test.tttt.a bigint)", errno.ErrWrongTableName) - tk.MustGetErrCode("create table t(t.tttt.a bigint)", errno.ErrWrongDBName) -} - // TestCreateTableIfNotExistsLike for issue #6879 func TestCreateTableIfNotExistsLike(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -239,23 +150,6 @@ func TestIssue2293(t *testing.T) { tk.MustQuery("select * from t_issue_2293").Check(testkit.Rows("1")) } -func TestIssue6101(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t1 (quantity decimal(2) unsigned);") - _, err := tk.Exec("insert into t1 values (500), (-500), (~0), (-1);") - terr := errors.Cause(err).(*terror.Error) - require.Equal(t, errors.ErrCode(errno.ErrWarnDataOutOfRange), terr.Code()) - tk.MustExec("drop table t1") - - tk.MustExec("set sql_mode=''") - tk.MustExec("create table t1 (quantity decimal(2) unsigned);") - tk.MustExec("insert into t1 values (500), (-500), (~0), (-1);") - tk.MustQuery("select * from t1").Check(testkit.Rows("99", "0", "99", "0")) - tk.MustExec("drop table t1") -} - func TestIssue19229(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -317,22 +211,6 @@ func TestIndexLength(t *testing.T) { tk.MustExec("drop table idx_len;") } -func TestIssue3833(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table issue3833 (b char(0), c binary(0), d varchar(0))") - tk.MustGetErrCode("create index idx on issue3833 (b)", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("alter table issue3833 add index idx (b)", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(b))", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("create index idx on issue3833 (c)", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("alter table issue3833 add index idx (c)", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(c))", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("create index idx on issue3833 (d)", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("alter table issue3833 add index idx (d)", errno.ErrWrongKeyColumn) - tk.MustGetErrCode("create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(d))", errno.ErrWrongKeyColumn) -} - func TestIssue2858And2717(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -468,186 +346,6 @@ func TestIssue5092(t *testing.T) { tk.MustExec("drop table t_issue_5092") } -func TestErrnoErrorCode(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // create database - sql := "create database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - tk.MustGetErrCode(sql, errno.ErrTooLongIdent) - sql = "create database test" - tk.MustGetErrCode(sql, errno.ErrDBCreateExists) - sql = "create database test1 character set uft8;" - tk.MustGetErrCode(sql, errno.ErrUnknownCharacterSet) - sql = "create database test2 character set gkb;" - tk.MustGetErrCode(sql, errno.ErrUnknownCharacterSet) - sql = "create database test3 character set laitn1;" - tk.MustGetErrCode(sql, errno.ErrUnknownCharacterSet) - // drop database - sql = "drop database db_not_exist" - tk.MustGetErrCode(sql, errno.ErrDBDropExists) - // create table - tk.MustExec("create table test_error_code_succ (c1 int, c2 int, c3 int, primary key(c3))") - sql = "create table test_error_code_succ (c1 int, c2 int, c3 int)" - tk.MustGetErrCode(sql, errno.ErrTableExists) - sql = "create table test_error_code1 (c1 int, c2 int, c2 int)" - tk.MustGetErrCode(sql, errno.ErrDupFieldName) - sql = "create table test_error_code1 (c1 int, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int)" - tk.MustGetErrCode(sql, errno.ErrTooLongIdent) - sql = "create table test_error_code1 (c1 int, `_tidb_rowid` int)" - tk.MustGetErrCode(sql, errno.ErrWrongColumnName) - sql = "create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int)" - tk.MustGetErrCode(sql, errno.ErrTooLongIdent) - sql = "create table test_error_code1 (c1 int, c2 int, key aa (c1, c2), key aa (c1))" - tk.MustGetErrCode(sql, errno.ErrDupKeyName) - sql = "create table test_error_code1 (c1 int, c2 int, c3 int, key(c_not_exist))" - tk.MustGetErrCode(sql, errno.ErrKeyColumnDoesNotExits) - sql = "create table test_error_code1 (c1 int, c2 int, c3 int, primary key(c_not_exist))" - tk.MustGetErrCode(sql, errno.ErrKeyColumnDoesNotExits) - sql = "create table test_error_code1 (c1 int not null default '')" - tk.MustGetErrCode(sql, errno.ErrInvalidDefault) - sql = "CREATE TABLE `t` (`a` double DEFAULT 1.0 DEFAULT 2.0 DEFAULT now());" - tk.MustGetErrCode(sql, errno.ErrInvalidDefault) - sql = "CREATE TABLE `t` (`a` double DEFAULT now());" - tk.MustGetErrCode(sql, errno.ErrInvalidDefault) - sql = "create table t1(a int) character set uft8;" - tk.MustGetErrCode(sql, errno.ErrUnknownCharacterSet) - sql = "create table t1(a int) character set gkb;" - tk.MustGetErrCode(sql, errno.ErrUnknownCharacterSet) - sql = "create table t1(a int) character set laitn1;" - tk.MustGetErrCode(sql, errno.ErrUnknownCharacterSet) - sql = "create table test_error_code (a int not null ,b int not null,c int not null, d int not null, foreign key (b, c) references product(id));" - tk.MustGetErrCode(sql, errno.ErrWrongFkDef) - sql = "create table test_error_code_2;" - tk.MustGetErrCode(sql, errno.ErrTableMustHaveColumns) - sql = "create table test_error_code_2 (unique(c1));" - tk.MustGetErrCode(sql, errno.ErrTableMustHaveColumns) - sql = "create table test_error_code_2(c1 int, c2 int, c3 int, primary key(c1), primary key(c2));" - tk.MustGetErrCode(sql, errno.ErrMultiplePriKey) - sql = "create table test_error_code_3(pt blob ,primary key (pt));" - tk.MustGetErrCode(sql, errno.ErrBlobKeyWithoutLength) - sql = "create table test_error_code_3(a text, unique (a(769)));" - tk.MustGetErrCode(sql, errno.ErrTooLongKey) - sql = "create table test_error_code_3(a text charset ascii, unique (a(3073)));" - tk.MustGetErrCode(sql, errno.ErrTooLongKey) - sql = "create table test_error_code_3(`id` int, key `primary`(`id`));" - tk.MustGetErrCode(sql, errno.ErrWrongNameForIndex) - sql = "create table t2(c1.c2 blob default null);" - tk.MustGetErrCode(sql, errno.ErrWrongTableName) - sql = "create table t2 (id int default null primary key , age int);" - tk.MustGetErrCode(sql, errno.ErrInvalidDefault) - sql = "create table t2 (id int null primary key , age int);" - tk.MustGetErrCode(sql, errno.ErrPrimaryCantHaveNull) - sql = "create table t2 (id int default null, age int, primary key(id));" - tk.MustGetErrCode(sql, errno.ErrPrimaryCantHaveNull) - sql = "create table t2 (id int null, age int, primary key(id));" - tk.MustGetErrCode(sql, errno.ErrPrimaryCantHaveNull) - sql = "create table t2 (id int auto_increment, c int auto_increment);" - tk.MustGetErrCode(sql, errno.ErrWrongAutoKey) - sql = "create table t2 (a datetime(2) default current_timestamp(3));" - tk.MustGetErrCode(sql, errno.ErrInvalidDefault) - sql = "create table t2 (a datetime(2) default current_timestamp(2) on update current_timestamp);" - tk.MustGetErrCode(sql, errno.ErrInvalidOnUpdate) - sql = "create table t2 (a datetime default current_timestamp on update current_timestamp(2));" - tk.MustGetErrCode(sql, errno.ErrInvalidOnUpdate) - sql = "create table t2 (a datetime(2) default current_timestamp(2) on update current_timestamp(3));" - tk.MustGetErrCode(sql, errno.ErrInvalidOnUpdate) - sql = "create table t(a blob(10), index(a(0)));" - tk.MustGetErrCode(sql, errno.ErrKeyPart0) - sql = "create table t(a char(10), index(a(0)));" - tk.MustGetErrCode(sql, errno.ErrKeyPart0) - - sql = "create table t2 (id int primary key , age int);" - tk.MustExec(sql) - - // add column - sql = "alter table test_error_code_succ add column c1 int" - tk.MustGetErrCode(sql, errno.ErrDupFieldName) - sql = "alter table test_error_code_succ add column aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int" - tk.MustGetErrCode(sql, errno.ErrTooLongIdent) - sql = "alter table test_comment comment 'test comment'" - tk.MustGetErrCode(sql, errno.ErrNoSuchTable) - sql = "alter table test_error_code_succ add column `a ` int ;" - tk.MustGetErrCode(sql, errno.ErrWrongColumnName) - sql = "alter table test_error_code_succ add column `_tidb_rowid` int ;" - tk.MustGetErrCode(sql, errno.ErrWrongColumnName) - tk.MustExec("create table test_on_update (c1 int, c2 int);") - sql = "alter table test_on_update add column c3 int on update current_timestamp;" - tk.MustGetErrCode(sql, errno.ErrInvalidOnUpdate) - sql = "create table test_on_update_2(c int on update current_timestamp);" - tk.MustGetErrCode(sql, errno.ErrInvalidOnUpdate) - - // add columns - sql = "alter table test_error_code_succ add column c1 int, add column c1 int" - tk.MustGetErrCode(sql, errno.ErrDupFieldName) - sql = "alter table test_error_code_succ add column (aa int, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int)" - tk.MustGetErrCode(sql, errno.ErrTooLongIdent) - sql = "alter table test_error_code_succ add column `a ` int, add column `b ` int;" - tk.MustGetErrCode(sql, errno.ErrWrongColumnName) - tk.MustExec("create table test_add_columns_on_update (c1 int, c2 int);") - sql = "alter table test_add_columns_on_update add column cc int, add column c3 int on update current_timestamp;" - tk.MustGetErrCode(sql, errno.ErrInvalidOnUpdate) - - // drop column - sql = "alter table test_error_code_succ drop c_not_exist" - tk.MustGetErrCode(sql, errno.ErrCantDropFieldOrKey) - tk.MustExec("create table test_drop_column (c1 int );") - sql = "alter table test_drop_column drop column c1;" - tk.MustGetErrCode(sql, errno.ErrCantRemoveAllFields) - // drop columns - sql = "alter table test_error_code_succ drop c_not_exist, drop cc_not_exist" - tk.MustGetErrCode(sql, errno.ErrCantDropFieldOrKey) - tk.MustExec("create table test_drop_columns (c1 int);") - tk.MustExec("alter table test_drop_columns add column c2 int first, add column c3 int after c1") - sql = "alter table test_drop_columns drop column c1, drop column c2, drop column c3;" - tk.MustGetErrCode(sql, errno.ErrCantRemoveAllFields) - sql = "alter table test_drop_columns drop column c1, add column c2 int;" - tk.MustGetErrCode(sql, errno.ErrDupFieldName) - sql = "alter table test_drop_columns drop column c1, drop column c1;" - tk.MustGetErrCode(sql, errno.ErrUnsupportedDDLOperation) - // add index - sql = "alter table test_error_code_succ add index idx (c_not_exist)" - tk.MustGetErrCode(sql, errno.ErrKeyColumnDoesNotExits) - tk.MustExec("alter table test_error_code_succ add index idx (c1)") - sql = "alter table test_error_code_succ add index idx (c1)" - tk.MustGetErrCode(sql, errno.ErrDupKeyName) - // drop index - sql = "alter table test_error_code_succ drop index idx_not_exist" - tk.MustGetErrCode(sql, errno.ErrCantDropFieldOrKey) - sql = "alter table test_error_code_succ drop column c3" - tk.MustGetErrCode(sql, errno.ErrUnsupportedDDLOperation) - // modify column - sql = "alter table test_error_code_succ modify testx.test_error_code_succ.c1 bigint" - tk.MustGetErrCode(sql, errno.ErrWrongDBName) - sql = "alter table test_error_code_succ modify t.c1 bigint" - tk.MustGetErrCode(sql, errno.ErrWrongTableName) - sql = "alter table test_error_code_succ change c1 _tidb_rowid bigint" - tk.MustGetErrCode(sql, errno.ErrWrongColumnName) - sql = "alter table test_error_code_succ rename column c1 to _tidb_rowid" - tk.MustGetErrCode(sql, errno.ErrWrongColumnName) - // insert value - tk.MustExec("create table test_error_code_null(c1 char(100) not null);") - sql = "insert into test_error_code_null (c1) values(null);" - tk.MustGetErrCode(sql, errno.ErrBadNull) -} - -func TestTableDDLWithFloatType(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustGetErrCode("create table t (a decimal(1, 2))", errno.ErrMBiggerThanD) - tk.MustGetErrCode("create table t (a float(1, 2))", errno.ErrMBiggerThanD) - tk.MustGetErrCode("create table t (a double(1, 2))", errno.ErrMBiggerThanD) - tk.MustExec("create table t (a double(1, 1))") - tk.MustGetErrCode("alter table t add column b decimal(1, 2)", errno.ErrMBiggerThanD) - // add multi columns now not support, so no case. - tk.MustGetErrCode("alter table t modify column a float(1, 4)", errno.ErrMBiggerThanD) - tk.MustGetErrCode("alter table t change column a aa float(1, 4)", errno.ErrMBiggerThanD) - tk.MustExec("drop table t") -} - func TestTableDDLWithTimeType(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -1252,27 +950,6 @@ func TestCreateTableTooLarge(t *testing.T) { atomic.StoreUint32(&config.GetGlobalConfig().TableColumnCountLimit, originLimit) } -func TestCreateTableTooManyIndexes(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - sql := "create table t_too_many_indexes (" - for i := 0; i < 100; i++ { - if i != 0 { - sql += "," - } - sql += fmt.Sprintf("c%d int", i) - } - for i := 0; i < 100; i++ { - sql += "," - sql += fmt.Sprintf("key k%d(c%d)", i, i) - } - sql += ");" - - tk.MustGetErrCode(sql, errno.ErrTooManyKeys) -} - func TestChangeColumnPosition(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -1445,127 +1122,6 @@ func TestAddColumnDefaultNow(t *testing.T) { require.Equal(t, amsterdamC2MS, shanghaiC2MS, "The timestamp after 'hour' should be equivalent") } -func TestAddColumnTooMany(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - count := int(atomic.LoadUint32(&config.GetGlobalConfig().TableColumnCountLimit) - 1) - var cols []string - for i := 0; i < count; i++ { - cols = append(cols, fmt.Sprintf("a%d int", i)) - } - createSQL := fmt.Sprintf("create table t_column_too_many (%s)", strings.Join(cols, ",")) - tk.MustExec(createSQL) - tk.MustExec("alter table t_column_too_many add column a_512 int") - alterSQL := "alter table t_column_too_many add column a_513 int" - tk.MustGetErrCode(alterSQL, errno.ErrTooManyFields) -} - -func TestCreateTooManyIndexes(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - count := config.GetGlobalConfig().IndexLimit - 1 - sql := "create table t_index_too_many (" - for i := 0; i < 100; i++ { - if i != 0 { - sql += "," - } - sql += fmt.Sprintf("c%d int", i) - } - for i := 0; i < count; i++ { - sql += "," - sql += fmt.Sprintf("key k%d(c%d)", i, i) - } - sql += ");" - tk.MustExec(sql) - tk.MustExec("create index idx1 on t_index_too_many (c62)") - alterSQL := "create index idx2 on t_index_too_many (c63)" - tk.MustGetErrCode(alterSQL, errno.ErrTooManyKeys) -} - -func TestCreateSecondaryIndexInCluster(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // test create table with non-unique key - tk.MustExec(` -CREATE TABLE t ( - c01 varchar(255) NOT NULL, - c02 varchar(255) NOT NULL, - c03 varchar(255) NOT NULL, - c04 varchar(255) DEFAULT NULL, - c05 varchar(255) DEFAULT NULL, - c06 varchar(255) DEFAULT NULL, - PRIMARY KEY (c01,c02,c03) clustered, - KEY c04 (c04) -)`) - tk.MustExec("drop table t") - - // test create long clustered primary key. - tk.MustGetErrCode(` -CREATE TABLE t ( - c01 varchar(255) NOT NULL, - c02 varchar(255) NOT NULL, - c03 varchar(255) NOT NULL, - c04 varchar(255) NOT NULL, - c05 varchar(255) DEFAULT NULL, - c06 varchar(255) DEFAULT NULL, - PRIMARY KEY (c01,c02,c03,c04) clustered -)`, errno.ErrTooLongKey) - - // test create table with unique key - tk.MustExec(` -CREATE TABLE t ( - c01 varchar(255) NOT NULL, - c02 varchar(255) NOT NULL, - c03 varchar(255) NOT NULL, - c04 varchar(255) DEFAULT NULL, - c05 varchar(255) DEFAULT NULL, - c06 varchar(255) DEFAULT NULL, - PRIMARY KEY (c01,c02,c03) clustered, - unique key c04 (c04) -)`) - tk.MustExec("drop table t") - - // test create index - tk.MustExec(` -CREATE TABLE t ( - c01 varchar(255) NOT NULL, - c02 varchar(255) NOT NULL, - c03 varchar(255) NOT NULL, - c04 varchar(255) DEFAULT NULL, - c05 varchar(255) DEFAULT NULL, - c06 varchar(255) DEFAULT NULL, - PRIMARY KEY (c01,c02) clustered -)`) - tk.MustExec("create index idx1 on t(c03)") - tk.MustExec("create index idx2 on t(c03, c04)") - tk.MustExec("create unique index uk2 on t(c03, c04)") - tk.MustExec("drop table t") - - // test change/modify column - tk.MustExec(` -CREATE TABLE t ( - c01 varchar(255) NOT NULL, - c02 varchar(255) NOT NULL, - c03 varchar(255) NOT NULL, - c04 varchar(255) DEFAULT NULL, - c05 varchar(255) DEFAULT NULL, - c06 varchar(255) DEFAULT NULL, - Index idx1(c03), - PRIMARY KEY (c01,c02) clustered, - unique index uk1(c06) -)`) - tk.MustExec("alter table t change c03 c10 varchar(256) default null") - tk.MustGetErrCode("alter table t change c10 c100 varchar(1024) default null", errno.ErrTooLongKey) - tk.MustExec("alter table t modify c10 varchar(600) default null") - tk.MustExec("alter table t modify c06 varchar(600) default null") - tk.MustExec("alter table t modify c01 varchar(510)") - tk.MustExec("create table t2 like t") -} - func TestAlterColumn(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -1842,52 +1398,6 @@ func TestAlterAlgorithm(t *testing.T) { tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") } -func TestAlterTableAddUniqueOnPartionRangeColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - defer tk.MustExec("drop table if exists t") - - tk.MustExec(`create table t( - a int, - b varchar(100), - c int, - INDEX idx_c(c)) - PARTITION BY RANGE COLUMNS( a ) ( - PARTITION p0 VALUES LESS THAN (6), - PARTITION p1 VALUES LESS THAN (11), - PARTITION p2 VALUES LESS THAN (16), - PARTITION p3 VALUES LESS THAN (21) - )`) - tk.MustExec("insert into t values (4, 'xxx', 4)") - tk.MustExec("insert into t values (4, 'xxx', 9)") // Note the repeated 4 - tk.MustExec("insert into t values (17, 'xxx', 12)") - tk.MustGetErrCode("alter table t add unique index idx_a(a)", errno.ErrDupEntry) - - tk.MustExec("delete from t where a = 4") - tk.MustExec("alter table t add unique index idx_a(a)") - tk.MustExec("alter table t add unique index idx_ac(a, c)") - tk.MustGetErrCode("alter table t add unique index idx_b(b)", errno.ErrUniqueKeyNeedAllFieldsInPf) -} - -func TestFulltextIndexIgnore(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t_ft") - defer tk.MustExec("drop table if exists t_ft") - // Make sure that creating and altering to add a fulltext key gives the correct warning - assertWarningExec(tk, t, "create table t_ft (a text, fulltext key (a))", dbterror.ErrTableCantHandleFt) - assertWarningExec(tk, t, "alter table t_ft add fulltext key (a)", dbterror.ErrTableCantHandleFt) - - // Make sure table t_ft still has no indexes even after it was created and altered - r := tk.MustQuery("show index from t_ft") - require.Len(t, r.Rows(), 0) - r = tk.MustQuery("select * from information_schema.statistics where table_schema='test' and table_name='t_ft'") - require.Len(t, r.Rows(), 0) -} - func TestTreatOldVersionUTF8AsUTF8MB4(t *testing.T) { restoreFunc := config.RestoreFunc() defer restoreFunc() @@ -2039,17 +1549,6 @@ func TestTreatOldVersionUTF8AsUTF8MB4(t *testing.T) { ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) } -func TestDefaultValueIsString(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - defer tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int default b'1');") - tbl := external.GetTableByName(t, tk, "test", "t") - require.Equal(t, "1", tbl.Meta().Columns[0].DefaultValue) -} - func TestDefaultColumnWithRand(t *testing.T) { // Related issue: https://github.com/pingcap/tidb/issues/10377 store := testkit.CreateMockStoreWithSchemaLease(t, testLease) @@ -2107,32 +1606,6 @@ func TestDefaultColumnWithRand(t *testing.T) { tk.MustGetErrCode("CREATE TABLE t3 (c int, c1 int default a_function_not_supported_yet());", errno.ErrDefValGeneratedNamedFunctionIsNotAllowed) } -func TestDefaultColumnWithUUID(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, testLease) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - - tk.MustExec("create table t (c int(10), c1 varchar(256) default (uuid()))") - // add column with default uuid() for table t is forbidden in MySQL 8.0 - tk.MustGetErrCode("alter table t add column c2 varchar(256) default (uuid())", errno.ErrBinlogUnsafeSystemFunction) - tk.MustExec("insert into t(c) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10)") - // each value of UUID should differ - r := tk.MustQuery("select c1 from t").Rows() - set := make(map[string]bool, 10) - for _, row := range r { - str, _ := row[0].(string) - _, ok := set[str] - require.True(t, !ok, "Existing two same UUID values.") - set[str] = true - } - tk.MustQuery("show create table t").Check(testkit.Rows( - "t CREATE TABLE `t` (\n" + - " `c` int(10) DEFAULT NULL,\n" + - " `c1` varchar(256) DEFAULT uuid()\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) -} - func TestChangingDBCharset(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -2247,86 +1720,6 @@ func TestChangingDBCharset(t *testing.T) { tk.MustExec("alter database TEST_UPPERCASE_DB_CHARSET default character set utf8mb4;") } -func TestDropAutoIncrementIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database if not exists test") - tk.MustExec("use test") - - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (a int(11) not null auto_increment key, b int(11), c bigint, unique key (a, b, c))") - tk.MustExec("alter table t1 drop index a") - - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (a int auto_increment, unique key (a))") - dropIndexSQL := "alter table t1 drop index a" - tk.MustExec(dropIndexSQL) - - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (a int(11) not null auto_increment, b int(11), c bigint, unique key (a, b, c))") - dropIndexSQL = "alter table t1 drop index a" - tk.MustExec(dropIndexSQL) -} - -func TestInsertIntoGeneratedColumnWithDefaultExpr(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database if not exists test") - tk.MustExec("use test") - - // insert into virtual / stored columns - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (a int, b int as (-a) virtual, c int as (-a) stored)") - tk.MustExec("insert into t1 values (1, default, default)") - tk.MustQuery("select * from t1").Check(testkit.Rows("1 -1 -1")) - tk.MustExec("delete from t1") - - // insert multiple rows - tk.MustExec("insert into t1(a,b) values (1, default), (2, default)") - tk.MustQuery("select * from t1").Check(testkit.Rows("1 -1 -1", "2 -2 -2")) - tk.MustExec("delete from t1") - - // insert into generated columns only - tk.MustExec("insert into t1(b) values (default)") - tk.MustQuery("select * from t1").Check(testkit.Rows(" ")) - tk.MustExec("delete from t1") - tk.MustExec("insert into t1(c) values (default)") - tk.MustQuery("select * from t1").Check(testkit.Rows(" ")) - tk.MustExec("delete from t1") - - // generated columns with index - tk.MustExec("drop table if exists t2") - tk.MustExec("create table t2 like t1") - tk.MustExec("alter table t2 add index idx1(a)") - tk.MustExec("alter table t2 add index idx2(b)") - tk.MustExec("insert into t2 values (1, default, default)") - tk.MustQuery("select * from t2").Check(testkit.Rows("1 -1 -1")) - tk.MustExec("delete from t2") - tk.MustExec("alter table t2 drop index idx1") - tk.MustExec("alter table t2 drop index idx2") - tk.MustExec("insert into t2 values (1, default, default)") - tk.MustQuery("select * from t2").Check(testkit.Rows("1 -1 -1")) - - // generated columns in different position - tk.MustExec("drop table if exists t3") - tk.MustExec("create table t3 (gc1 int as (r+1), gc2 int as (r+1) stored, gc3 int as (gc2+1), gc4 int as (gc1+1) stored, r int)") - tk.MustExec("insert into t3 values (default, default, default, default, 1)") - tk.MustQuery("select * from t3").Check(testkit.Rows("2 2 3 3 1")) - - // generated columns in replace statement - tk.MustExec("create table t4 (a int key, b int, c int as (a+1), d int as (b+1) stored)") - tk.MustExec("insert into t4 values (1, 10, default, default)") - tk.MustQuery("select * from t4").Check(testkit.Rows("1 10 2 11")) - tk.MustExec("replace into t4 values (1, 20, default, default)") - tk.MustQuery("select * from t4").Check(testkit.Rows("1 20 2 21")) - - // generated columns with default function is not allowed - tk.MustExec("create table t5 (a int default 10, b int as (a+1))") - tk.MustGetErrCode("insert into t5 values (20, default(a))", errno.ErrBadGeneratedColumn) - - tk.MustExec("drop table t1, t2, t3, t4, t5") -} - func TestSqlFunctionsInGeneratedColumns(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -2504,104 +1897,6 @@ func TestAddExpressionIndex(t *testing.T) { }) } -func TestCreateExpressionIndexWithJSONFunction(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, b json);") - tk.MustExec("insert into t values (1, '{\"a\": 1}');") - - tk.MustExec("alter table t add index idx((cast(b->'$.a' as char(255))));") - tk.MustQuery("select * from t force index(idx);").Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery("select * from t ignore index(idx);").Check(testkit.Rows("1 {\"a\": 1}")) - - tk.MustExec("alter table t add index idx1((cast(b->>'$.a' as char(255))));") - tk.MustQuery("select * from t force index(idx1);").Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery("select * from t ignore index(idx1);").Check(testkit.Rows("1 {\"a\": 1}")) - - tk.MustExec("alter table t add index idx2((json_type(b)));") - tk.MustQuery("select * from t force index(idx2) where json_type(b) = 'OBJECT';").Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery("select * from t ignore index(idx2) where json_type(b) = 'OBJECT';").Check(testkit.Rows("1 {\"a\": 1}")) - - tk.MustGetErrCode("alter table t add index idx_wrong((b->'$.a'));", errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode("alter table t add index idx_wrong((b->>'$.a'));", errno.ErrFunctionalIndexOnBlob) - tk.MustGetErrCode("alter table t add index idx_wrong((json_pretty(b)));", errno.ErrFunctionalIndexOnBlob) - - tk.MustExec("drop table if exists t;") - tk.MustGetErrCode("create table t(a char(255), index idx((json_quote(a))));", errno.ErrTooLongKey) - tk.MustExec("create table t(a char(40));") - tk.MustExec("insert into t values ('[1, 2, 3]')") - tk.MustExec("alter table t add index idx3((json_quote(a)));") - tk.MustQuery("select * from t force index(idx3) where json_quote(a) = '\"[1, 2, 3]\"';").Check(testkit.Rows("[1, 2, 3]")) - tk.MustQuery("select * from t ignore index(idx3) where json_quote(a) = '\"[1, 2, 3]\"';").Check(testkit.Rows("[1, 2, 3]")) - - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int, b json);") - tk.MustGetErrCode(`alter table t add index idx_wrong((json_array(b)));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_object('key', b)));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_merge_preserve(b, '{"k": "v"}')));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_set(b, '$.a', 'v')));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_insert(b, '$.a', 'v')));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_replace(b, '$.a', 'v')));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_remove(b, '$.a')));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_array_append(b, '$.a', 1)));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_merge_patch(b, '{"k": "v"}')));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_search(b, 'one', 'a')));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - tk.MustGetErrCode(`alter table t add index idx_wrong((json_keys(b)));`, errno.ErrFunctionalIndexOnJSONOrGeometryFunction) - - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int, b json);") - tk.MustExec("insert into t values (1, '{\"a\": 1}');") - tk.MustExec(`alter table t add index idx0((json_type(json_search(b, 'one', 'a'))));`) - tk.MustExec(`alter table t add index idx1((json_type(json_array(b))));`) - tk.MustExec(`alter table t add index idx2((json_type(json_object('key', b))));`) - tk.MustExec(`alter table t add index idx3((json_type(json_merge_preserve(b, '{"k": "v"}'))));`) - tk.MustExec(`alter table t add index idx4((json_type(json_set(b, '$.a', 'v'))));`) - tk.MustExec(`alter table t add index idx5((json_type(json_insert(b, '$.a', 'v'))));`) - tk.MustExec(`alter table t add index idx6((json_type(json_replace(b, '$.a', 'v'))));`) - tk.MustExec(`alter table t add index idx7((json_type(json_remove(b, '$.a'))));`) - tk.MustExec(`alter table t add index idx8((json_type(json_array_append(b, '$.a', 1))));`) - tk.MustExec(`alter table t add index idx9((json_type(json_merge_patch(b, '{"k": "v"}'))));`) - tk.MustExec(`alter table t add index idx10((json_type(json_keys(b))));`) - tk.MustExec(`alter table t add index idx11((cast(json_quote(cast(a as char(10))) as char(64))));`) - tk.MustExec(`alter table t add index idx12((json_storage_size(b)));`) - tk.MustExec(`alter table t add index idx13((json_depth(b)));`) - tk.MustExec(`alter table t add index idx14((json_length(b)));`) - - tk.MustQuery(`select * from t force index(idx0) where json_type(json_search(b, 'one', 'a')) is NULL;`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx1) where json_type(json_array(b)) = 'ARRAY';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx2) where json_type(json_object('key', b)) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx3) where json_type(json_merge_preserve(b, '{"k": "v"}')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx4) where json_type(json_set(b, '$.a', 'v')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx5) where json_type(json_insert(b, '$.a', 'v')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx6) where json_type(json_replace(b, '$.a', 'v')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx7) where json_type(json_remove(b, '$.a')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx8) where json_type(json_array_append(b, '$.a', 1)) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx9) where json_type(json_merge_patch(b, '{"k": "v"}')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx10) where json_type(json_keys(b)) = 'ARRAY';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx11) where cast(json_quote(cast(a as char(10))) as char(64)) = '"1"';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx12) where json_storage_size(b) > 1;`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx13) where json_depth(b) > 0;`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t force index(idx14) where json_length(b) > 0;`).Check(testkit.Rows("1 {\"a\": 1}")) - - tk.MustQuery(`select * from t ignore index(idx0) where json_type(json_search(b, 'one', 'a')) is NULL;`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx1) where json_type(json_array(b)) = 'ARRAY';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx2) where json_type(json_object('key', b)) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx3) where json_type(json_merge_preserve(b, '{"k": "v"}')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx4) where json_type(json_set(b, '$.a', 'v')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx5) where json_type(json_insert(b, '$.a', 'v')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx6) where json_type(json_replace(b, '$.a', 'v')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx7) where json_type(json_remove(b, '$.a')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx8) where json_type(json_array_append(b, '$.a', 1)) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx9) where json_type(json_merge_patch(b, '{"k": "v"}')) = 'OBJECT';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx10) where json_type(json_keys(b)) = 'ARRAY';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx11) where cast(json_quote(cast(a as char(10))) as char(64)) = '"1"';`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx12) where json_storage_size(b) > 1;`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx13) where json_depth(b) > 0;`).Check(testkit.Rows("1 {\"a\": 1}")) - tk.MustQuery(`select * from t ignore index(idx14) where json_length(b) > 0;`).Check(testkit.Rows("1 {\"a\": 1}")) -} - func TestCreateExpressionIndexError(t *testing.T) { config.UpdateGlobal(func(conf *config.Config) { // Test for table lock. @@ -2656,176 +1951,6 @@ func TestCreateExpressionIndexError(t *testing.T) { tk.MustExec("update t t1 set t1.short_name='a' where t1.id='1';") } -func TestAddExpressionIndexOnPartition(t *testing.T) { - store, dom := testkit.CreateMockStoreAndDomain(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec(`create table t( - a int, - b varchar(100), - c int) - PARTITION BY RANGE ( a ) ( - PARTITION p0 VALUES LESS THAN (6), - PARTITION p1 VALUES LESS THAN (11), - PARTITION p2 VALUES LESS THAN (16), - PARTITION p3 VALUES LESS THAN (21) - );`) - tk.MustExec("insert into t values (1, 'test', 2), (12, 'test', 3), (15, 'test', 10), (20, 'test', 20);") - tk.MustExec("alter table t add index idx((a+c));") - - tblInfo, err := dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) - require.NoError(t, err) - columns := tblInfo.Meta().Columns - require.Equal(t, 4, len(columns)) - require.True(t, columns[3].Hidden) - - tk.MustQuery("select * from t order by a;").Check(testkit.Rows("1 test 2", "12 test 3", "15 test 10", "20 test 20")) -} - -// TestCreateTableWithAutoIdCache test the auto_id_cache table option. -// `auto_id_cache` take effects on handle too when `PKIshandle` is false, -// or even there is no auto_increment column at all. -func TestCreateTableWithAutoIdCache(t *testing.T) { - store, dom := testkit.CreateMockStoreAndDomain(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - - // Test primary key is handle. - tk.MustExec("create table t(a int auto_increment key clustered) auto_id_cache 100") - tblInfo, err := dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) - require.NoError(t, err) - require.Equal(t, int64(100), tblInfo.Meta().AutoIdCache) - tk.MustExec("insert into t values()") - tk.MustQuery("select * from t").Check(testkit.Rows("1")) - tk.MustExec("delete from t") - - // Invalid the allocator cache, insert will trigger a new cache - tk.MustExec("rename table t to t1;") - tk.MustExec("insert into t1 values()") - tk.MustQuery("select * from t1").Check(testkit.Rows("101")) - - // Test primary key is not handle. - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(a int) auto_id_cache 100") - _, err = dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) - require.NoError(t, err) - - tk.MustExec("insert into t values()") - tk.MustQuery("select _tidb_rowid from t").Check(testkit.Rows("1")) - tk.MustExec("delete from t") - - // Invalid the allocator cache, insert will trigger a new cache - tk.MustExec("rename table t to t1;") - tk.MustExec("insert into t1 values()") - tk.MustQuery("select _tidb_rowid from t1").Check(testkit.Rows("101")) - - // Test both auto_increment and rowid exist. - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(a int null, b int auto_increment unique) auto_id_cache 100") - _, err = dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) - require.NoError(t, err) - - tk.MustExec("insert into t(b) values(NULL)") - tk.MustQuery("select b, _tidb_rowid from t").Check(testkit.Rows("1 2")) - tk.MustExec("delete from t") - - // Invalid the allocator cache, insert will trigger a new cache. - tk.MustExec("rename table t to t1;") - tk.MustExec("insert into t1(b) values(NULL)") - tk.MustQuery("select b, _tidb_rowid from t1").Check(testkit.Rows("101 102")) - tk.MustExec("delete from t1") - - // Test alter auto_id_cache. - tk.MustExec("alter table t1 auto_id_cache 200") - tblInfo, err = dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t1")) - require.NoError(t, err) - require.Equal(t, int64(200), tblInfo.Meta().AutoIdCache) - - tk.MustExec("insert into t1(b) values(NULL)") - tk.MustQuery("select b, _tidb_rowid from t1").Check(testkit.Rows("201 202")) - tk.MustExec("delete from t1") - - // Invalid the allocator cache, insert will trigger a new cache. - tk.MustExec("rename table t1 to t;") - tk.MustExec("insert into t(b) values(NULL)") - tk.MustQuery("select b, _tidb_rowid from t").Check(testkit.Rows("401 402")) - tk.MustExec("delete from t") - - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(a int auto_increment key clustered) auto_id_cache 3") - tblInfo, err = dom.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) - require.NoError(t, err) - require.Equal(t, int64(3), tblInfo.Meta().AutoIdCache) - - // Test insert batch size(4 here) greater than the customized autoid step(3 here). - tk.MustExec("insert into t(a) values(NULL),(NULL),(NULL)") - // Cache 3 more values. We can't merge this two lines because the batch allocation overrides autoid step. - tk.MustExec("insert into t(a) values(NULL)") - tk.MustQuery("select a from t").Check(testkit.Rows("1", "2", "3", "4")) - tk.MustExec("delete from t") - - // Invalid the allocator cache, insert will trigger a new cache. - tk.MustExec("rename table t to t1;") - tk.MustExec("insert into t1(a) values(NULL)") - next := tk.MustQuery("select a from t1").Rows()[0][0].(string) - nextInt, err := strconv.Atoi(next) - require.NoError(t, err) - require.Greater(t, nextInt, 5) - - // Test auto_id_cache overflows int64. - tk.MustExec("drop table if exists t;") - tk.MustGetErrMsg("create table t(a int) auto_id_cache = 9223372036854775808", "table option auto_id_cache overflows int64") - - tk.MustExec("create table t(a int) auto_id_cache = 9223372036854775807") - tk.MustGetErrMsg("alter table t auto_id_cache = 9223372036854775808", "table option auto_id_cache overflows int64") -} - -func TestAlterIndexVisibility(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database if not exists alter_index_test") - tk.MustExec("USE alter_index_test;") - tk.MustExec("drop table if exists t, t1, t2, t3;") - - tk.MustExec("create table t(a int NOT NULL, b int, key(a), unique(b) invisible)") - query := queryIndexOnTable("alter_index_test", "t") - tk.MustQuery(query).Check(testkit.Rows("a YES", "b NO")) - - tk.MustExec("alter table t alter index a invisible") - tk.MustQuery(query).Check(testkit.Rows("a NO", "b NO")) - - tk.MustExec("alter table t alter index b visible") - tk.MustQuery(query).Check(testkit.Rows("a NO", "b YES")) - - tk.MustExec("alter table t alter index b invisible") - tk.MustQuery(query).Check(testkit.Rows("a NO", "b NO")) - - tk.MustGetErrMsg("alter table t alter index non_exists_idx visible", "[schema:1176]Key 'non_exists_idx' doesn't exist in table 't'") - - // Alter implicit primary key to invisible index should throw error - tk.MustExec("create table t1(a int NOT NULL, unique(a))") - tk.MustGetErrMsg("alter table t1 alter index a invisible", "[ddl:3522]A primary key index cannot be invisible") - - // Alter explicit primary key to invisible index should throw error - tk.MustExec("create table t2(a int, primary key(a))") - tk.MustGetErrMsg("alter table t2 alter index PRIMARY invisible", `[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 34 near "PRIMARY invisible" `) - - // Alter expression index - tk.MustExec("create table t3(a int NOT NULL, b int)") - tk.MustExec("alter table t3 add index idx((a+b));") - query = queryIndexOnTable("alter_index_test", "t3") - tk.MustQuery(query).Check(testkit.Rows("idx YES")) - - tk.MustExec("alter table t3 alter index idx invisible") - tk.MustQuery(query).Check(testkit.Rows("idx NO")) -} - func queryIndexOnTable(dbName, tableName string) string { return fmt.Sprintf("select distinct index_name, is_visible from information_schema.statistics where table_schema = '%s' and table_name = '%s' order by index_name", dbName, tableName) } @@ -2908,20 +2033,6 @@ func TestDropColumnsWithMultiIndex(t *testing.T) { tk.MustQuery(query).Check(testkit.Rows()) } -func TestDropLastVisibleColumnOrColumns(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t_drop_last_column(x int, key((1+1)))") - _, err := tk.Exec("alter table t_drop_last_column drop column x") - require.Error(t, err) - require.Equal(t, "[ddl:1113]A table must have at least 1 column", err.Error()) - // for visible columns - tk.MustExec("create table t_drop_last_columns(x int, y int, key((1+1)))") - tk.MustGetErrMsg("alter table t_drop_last_columns drop column x, drop column y", "[ddl:1113]A table must have at least 1 column") - tk.MustExec("drop table if exists t_drop_last_column, t_drop_last_columns") -} - func TestAutoIncrementTableOption(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -3218,23 +2329,6 @@ func TestIssue20741WithEnumField(t *testing.T) { tk.MustQuery("select * from issue20741 where cc = 1").Check(testkit.Rows("1 2 a", "2 2 a")) } -func TestIssue20741WithSetField(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists issue20741_2") - tk.MustExec("create table issue20741_2(id int primary key, c int)") - tk.MustExec("insert into issue20741_2(id, c) values(1, 2), (2, 2)") - tk.MustExec("alter table issue20741_2 add column cc set('a', 'b', 'c', 'd') not null") - tk.MustExec("update issue20741_2 set c=2 where id=1") - tk.MustQuery("select * from issue20741_2").Check(testkit.Rows("1 2 ", "2 2 ")) - tk.MustQuery("select * from issue20741_2 where cc = 0").Check(testkit.Rows("1 2 ", "2 2 ")) - tk.MustQuery("select * from issue20741_2 where cc = 1").Check(testkit.Rows()) - _, err := tk.Exec("insert into issue20741_2(id, c) values (3, 3)") - require.Error(t, err) - require.Equal(t, "[table:1364]Field 'cc' doesn't have a default value", err.Error()) -} - // TestDefaultValueIsLatin1 for issue #18977 func TestEnumAndSetDefaultValue(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -3339,14 +2433,6 @@ func TestIssue22028(t *testing.T) { tk.MustGetErrMsg("ALTER TABLE t MODIFY COLUMN a DOUBLE(0,0);", "[types:1439]Display width out of range for column 'a' (max = 255)") } -func TestIssue21835(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustGetErrMsg("create table t( col decimal(1,2) not null default 0);", "[types:1427]For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'col').") -} - func TestCreateTemporaryTable(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3517,66 +2603,6 @@ func TestAccessLocalTmpTableAfterDropDB(t *testing.T) { executeTests() } -func TestPlacementOnTemporaryTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists test.tplacement1, db2.t1, db2.tplacement3, db2.tplacement5") - tk.MustExec("drop database if exists db2") - tk.MustExec("drop placement policy if exists x") - tk.MustExec("create placement policy x primary_region='r1' regions='r1'") - defer tk.MustExec("drop placement policy x") - - // Cannot create temporary table with placement options - tk.MustGetErrCode("create temporary table tplacement2 (id int) placement policy='x'", errno.ErrOptOnTemporaryTable) - - // Cannot alter temporary table with placement options - tk.MustExec("create global temporary table tplacement1 (id int) on commit delete rows") - defer tk.MustExec("drop table tplacement1") - tk.MustGetErrCode("alter table tplacement1 placement policy='x'", errno.ErrOptOnTemporaryTable) - - tk.MustExec("create temporary table tplacement2 (id int)") - tk.MustGetErrCode("alter table tplacement2 placement policy='x'", errno.ErrUnsupportedDDLOperation) - - // Temporary table will not inherit placement from db - tk.MustExec("create database db2 placement policy x") - defer tk.MustExec("drop database db2") - - tk.MustExec("create global temporary table db2.tplacement3 (id int) on commit delete rows") - defer tk.MustExec("drop table db2.tplacement3") - tk.MustQuery("show create table db2.tplacement3").Check(testkit.Rows( - "tplacement3 CREATE GLOBAL TEMPORARY TABLE `tplacement3` (\n" + - " `id` int(11) DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ON COMMIT DELETE ROWS", - )) - - tk.MustExec("create temporary table db2.tplacement4 (id int)") - tk.MustQuery("show create table db2.tplacement4").Check(testkit.Rows( - "tplacement4 CREATE TEMPORARY TABLE `tplacement4` (\n" + - " `id` int(11) DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", - )) - - tk.MustExec("create table db2.t1 (a int) placement policy 'default'") - defer tk.MustExec("drop table db2.t1") - - tk.MustExec("create global temporary table db2.tplacement5 like db2.t1 on commit delete rows") - defer tk.MustExec("drop table db2.tplacement5") - tk.MustQuery("show create table db2.tplacement5").Check(testkit.Rows( - "tplacement5 CREATE GLOBAL TEMPORARY TABLE `tplacement5` (\n" + - " `a` int(11) DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ON COMMIT DELETE ROWS", - )) - - tk.MustExec("create temporary table db2.tplacement6 like db2.t1") - defer tk.MustExec("drop table db2.tplacement6") - tk.MustQuery("show create table db2.tplacement6").Check(testkit.Rows( - "tplacement6 CREATE TEMPORARY TABLE `tplacement6` (\n" + - " `a` int(11) DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", - )) -} - func TestAvoidCreateViewOnLocalTemporaryTable(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3768,163 +2794,6 @@ func TestDropTemporaryTable(t *testing.T) { tk.MustQuery("select * from a_local_temp_table_8").Check(testkit.Rows()) } -func TestDropWithGlobalTemporaryTableKeyWord(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - clearSQL := "drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2" - tk.MustExec(clearSQL) - defer tk.MustExec(clearSQL) - // two normal table test.tb, test.tb2 - tk.MustExec("create table tb(id int)") - tk.MustExec("create table tb2(id int)") - // two global temporary table test.temp, test.temp1 - tk.MustExec("create global temporary table temp(id int) on commit delete rows") - tk.MustExec("create global temporary table temp1(id int) on commit delete rows") - // two local temporary table test.ltemp1, test.ltemp2 - tk.MustExec("create temporary table ltemp1(id int)") - tk.MustExec("create temporary table ltemp2(id int)") - - // testing for drop table which is not global temporary - err := tk.ExecToErr("drop global temporary table tb") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table test.tb") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table ltemp1") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table test.ltemp1") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table ltemp1, temp") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table temp, ltemp1") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table xxx, ltemp1") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table xxx") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - - // testing for drop table if exists which is not global temporary - err = tk.ExecToErr("drop global temporary table if exists tb") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table if exists ltemp1") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - tk.MustExec("drop global temporary table if exists xxx") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'test.xxx'")) - err = tk.ExecToErr("drop global temporary table if exists xxx,tb") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - err = tk.ExecToErr("drop global temporary table if exists test.tb") - require.True(t, core.ErrDropTableOnTemporaryTable.Equal(err)) - - // testing for drop global temporary table successfully - tk.MustExec("drop global temporary table temp") - err = tk.ExecToErr("select * from temp") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - - tk.MustExec("drop global temporary table test.temp1") - err = tk.ExecToErr("select * from temp2") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - - tk.MustExec("create global temporary table temp (id int) on commit delete rows") - tk.MustExec("create global temporary table temp1 (id int) on commit delete rows") - - tk.MustExec("drop global temporary table temp, temp1") - err = tk.ExecToErr("select * from temp") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - err = tk.ExecToErr("select * from temp1") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - - tk.MustExec("create global temporary table temp (id int) on commit delete rows") - tk.MustExec("create global temporary table temp1 (id int) on commit delete rows") - - tk.MustExec("drop global temporary table if exists temp") - tk.MustQuery("show warnings").Check(testkit.Rows()) - err = tk.ExecToErr("select * from temp") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) -} - -func TestDropWithLocalTemporaryTableKeyWord(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - clearSQL := "drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2, testt.ltemp3" - tk.MustExec(clearSQL) - defer tk.MustExec(clearSQL) - // two normal table test.tb, test.tb2, a temporary table with name test.tb2 - tk.MustExec("create table tb(id int)") - tk.MustExec("create table tb2(id int)") - tk.MustExec("insert into tb2 values(1)") - tk.MustExec("create temporary table tb2(id int)") - // two global temporary table test.temp, test.temp1 - tk.MustExec("create global temporary table temp(id int) on commit delete rows") - tk.MustExec("create global temporary table temp1(id int) on commit delete rows") - // two local temporary table test.ltemp1, test.ltemp2 - tk.MustExec("create temporary table ltemp1(id int)") - tk.MustExec("create temporary table ltemp2(id int)") - // a local temporary table test.ltemp3 - tk.MustExec("create database if not exists testt") - tk.MustExec("create temporary table testt.ltemp3(id int)") - - // testing for drop table which is not local temporary - err := tk.ExecToErr("drop temporary table tb") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - err = tk.ExecToErr("drop temporary table test.tb") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - err = tk.ExecToErr("drop temporary table temp1") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - err = tk.ExecToErr("drop temporary table test.temp1") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - err = tk.ExecToErr("drop temporary table ltemp1, tb") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - err = tk.ExecToErr("drop temporary table temp, ltemp1") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - err = tk.ExecToErr("drop temporary table xxx, ltemp1") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - err = tk.ExecToErr("drop temporary table xxx") - require.True(t, infoschema.ErrTableDropExists.Equal(err)) - - // testing for drop table if exists which is not local temporary - tk.MustExec("drop temporary table if exists xxx") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'test.xxx'")) - tk.MustExec("drop temporary table if exists ltemp1, xxx") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'test.xxx'")) - tk.MustExec("drop temporary table if exists tb1, xxx") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'test.tb1,test.xxx'")) - tk.MustExec("drop temporary table if exists temp1") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'test.temp1'")) - tk.MustExec("drop temporary table if exists temp1, xxx") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'test.temp1,test.xxx'")) - tk.MustExec("drop temporary table if exists testt.ltemp4") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'testt.ltemp4'")) - tk.MustExec("drop temporary table if exists testt.ltemp3, tb1") - tk.MustQuery("show warnings").Check(testkit.Rows("Note 1051 Unknown table 'test.tb1'")) - - // testing for drop temporary table successfully - tk.MustExec("drop temporary table ltemp1") - err = tk.ExecToErr("select * from ltemp1") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - - tk.MustExec("drop temporary table test.ltemp2") - err = tk.ExecToErr("select * from ltemp2") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - - tk.MustExec("drop temporary table tb2") - tk.MustQuery("select * from tb2").Check(testkit.Rows("1")) - - tk.MustExec("create temporary table ltemp1 (id int)") - tk.MustExec("create temporary table ltemp2 (id int)") - - tk.MustExec("drop temporary table testt.ltemp3, ltemp1") - err = tk.ExecToErr("select * from testt.ltemp3") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - err = tk.ExecToErr("select * from ltemp1") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) - - tk.MustExec("drop temporary table if exists ltemp2") - tk.MustQuery("show warnings").Check(testkit.Rows()) - err = tk.ExecToErr("select * from ltemp2") - require.True(t, infoschema.ErrTableNotExists.Equal(err)) -} - func TestTruncateLocalTemporaryTable(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -4121,134 +2990,6 @@ func TestEnumDefaultValue(t *testing.T) { ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci")) } -func TestIssue29326(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (id int)") - tk.MustExec("insert into t1 values(1)") - defer tk.MustExec("drop table t1") - - tk.MustExec("drop table if exists t2") - tk.MustExec("create table t2 (id int)") - tk.MustExec("insert into t2 values(1)") - defer tk.MustExec("drop table t2") - - tk.MustExec("drop view if exists v1") - defer tk.MustExec("drop view if exists v1") - - tk.MustExec("create view v1 as select 1,1") - rs, err := tk.Exec("select * from v1") - require.NoError(t, err) - tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1")) - require.Equal(t, "1", rs.Fields()[0].Column.Name.O) - require.Equal(t, "Name_exp_1", rs.Fields()[1].Column.Name.O) - - tk.MustExec("drop view if exists v1") - tk.MustExec("create view v1 as select 1, 2, 1, 2, 1, 2, 1, 2") - rs, err = tk.Exec("select * from v1") - require.NoError(t, err) - tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 2 1 2 1 2 1 2")) - require.Equal(t, "1", rs.Fields()[0].Column.Name.O) - require.Equal(t, "2", rs.Fields()[1].Column.Name.O) - require.Equal(t, "Name_exp_1", rs.Fields()[2].Column.Name.O) - require.Equal(t, "Name_exp_2", rs.Fields()[3].Column.Name.O) - require.Equal(t, "Name_exp_1_1", rs.Fields()[4].Column.Name.O) - require.Equal(t, "Name_exp_1_2", rs.Fields()[5].Column.Name.O) - require.Equal(t, "Name_exp_2_1", rs.Fields()[6].Column.Name.O) - require.Equal(t, "Name_exp_2_2", rs.Fields()[7].Column.Name.O) - - tk.MustExec("drop view if exists v1") - tk.MustExec("create view v1 as select 't', 't', 1 as t") - rs, err = tk.Exec("select * from v1") - require.NoError(t, err) - tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("t t 1")) - require.Equal(t, "Name_exp_t", rs.Fields()[0].Column.Name.O) - require.Equal(t, "Name_exp_1_t", rs.Fields()[1].Column.Name.O) - require.Equal(t, "t", rs.Fields()[2].Column.Name.O) - - tk.MustExec("drop view if exists v1") - tk.MustExec("create definer=`root`@`127.0.0.1` view v1 as select 1, 1 union all select 1, 1") - tk.MustQuery("show create view v1").Check(testkit.Rows("v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` " + - "SQL SECURITY DEFINER VIEW `v1` (`1`, `Name_exp_1`) " + - "AS SELECT 1 AS `1`,1 AS `Name_exp_1` UNION ALL SELECT 1 AS `1`,1 AS `1` " + - "utf8mb4 utf8mb4_bin")) - rs, err = tk.Exec("select * from v1") - require.NoError(t, err) - tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1", "1 1")) - require.Equal(t, "1", rs.Fields()[0].Column.Name.O) - require.Equal(t, "Name_exp_1", rs.Fields()[1].Column.Name.O) - - tk.MustExec("drop view if exists v1") - tk.MustExec("create definer=`root`@`127.0.0.1` view v1 as select 'id', id from t1") - tk.MustQuery("show create view v1").Check(testkit.Rows("v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` " + - "SQL SECURITY DEFINER VIEW `v1` (`Name_exp_id`, `id`) " + - "AS SELECT _UTF8MB4'id' AS `Name_exp_id`,`id` AS `id` FROM `test`.`t1` " + - "utf8mb4 utf8mb4_bin")) - rs, err = tk.Exec("select * from v1") - require.NoError(t, err) - tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("id 1")) - require.Equal(t, "Name_exp_id", rs.Fields()[0].Column.Name.O) - require.Equal(t, "id", rs.Fields()[1].Column.Name.O) - - tk.MustExec("drop view if exists v1") - tk.MustExec("create definer=`root`@`127.0.0.1` view v1 as select 1, (select id from t1 where t1.id=t2.id) as '1' from t2") - tk.MustQuery("show create view v1").Check(testkit.Rows("v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` " + - "SQL SECURITY DEFINER VIEW `v1` (`Name_exp_1`, `1`) " + - "AS SELECT 1 AS `Name_exp_1`,(SELECT `id` AS `id` FROM `test`.`t1` WHERE `t1`.`id`=`t2`.`id`) AS `1` FROM `test`.`t2` " + - "utf8mb4 utf8mb4_bin")) - rs, err = tk.Exec("select * from v1") - require.NoError(t, err) - tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1")) - require.Equal(t, "Name_exp_1", rs.Fields()[0].Column.Name.O) - require.Equal(t, "1", rs.Fields()[1].Column.Name.O) - - tk.MustExec("drop view if exists v1") - tk.MustExec("create definer=`root`@`127.0.0.1` view v1 as select 1 as 'abs(t1.id)', abs(t1.id) from t1") - tk.MustQuery("show create view v1").Check(testkit.Rows("v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` " + - "SQL SECURITY DEFINER VIEW `v1` (`abs(t1.id)`, `Name_exp_abs(t1.id)`) " + - "AS SELECT 1 AS `abs(t1.id)`,ABS(`t1`.`id`) AS `Name_exp_abs(t1.id)` FROM `test`.`t1` " + - "utf8mb4 utf8mb4_bin")) - rs, err = tk.Exec("select * from v1") - require.NoError(t, err) - tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1")) - require.Equal(t, "abs(t1.id)", rs.Fields()[0].Column.Name.O) - require.Equal(t, "Name_exp_abs(t1.id)", rs.Fields()[1].Column.Name.O) - - tk.MustExec("drop view if exists v1") - err = tk.ExecToErr("create definer=`root`@`127.0.0.1` view v1 as select 1 as t,1 as t") - require.True(t, infoschema.ErrColumnExists.Equal(err)) - - tk.MustExec("drop view if exists v1") - err = tk.ExecToErr("create definer=`root`@`127.0.0.1` view v1 as select 1 as id, id from t1") - require.True(t, infoschema.ErrColumnExists.Equal(err)) - - tk.MustExec("drop view if exists v1") - err = tk.ExecToErr("create definer=`root`@`127.0.0.1` view v1 as select * from t1 left join t2 on t1.id=t2.id") - require.True(t, infoschema.ErrColumnExists.Equal(err)) - - tk.MustExec("drop view if exists v1") - err = tk.ExecToErr("create definer=`root`@`127.0.0.1` view v1 as select t1.id, t2.id from t1,t2 where t1.id=t2.id") - require.True(t, infoschema.ErrColumnExists.Equal(err)) -} - -func TestInvalidPartitionNameWhenCreateTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("create database invalidPartitionNames") - defer tk.MustExec("drop database invalidPartitionNames") - tk.MustExec("USE invalidPartitionNames") - - tk.MustGetDBError("create table t(a int) partition by range (a) (partition p0 values less than (0), partition `p1 ` values less than (3))", dbterror.ErrWrongPartitionName) - tk.MustGetDBError("create table t(a int) partition by range (a) (partition `` values less than (0), partition `p1` values less than (3))", dbterror.ErrWrongPartitionName) - - tk.MustExec("create table t(a int) partition by range (a) (partition `p0` values less than (0), partition `p1` values less than (3))") - tk.MustGetDBError("alter table t add partition (partition `p2 ` values less than (5))", dbterror.ErrWrongPartitionName) -} - func TestDDLLastInfo(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4273,141 +3014,6 @@ func TestDDLLastInfo(t *testing.T) { tk.MustQuery("select json_extract(@@tidb_last_ddl_info, '$.query'), json_extract(@@tidb_last_ddl_info, '$.seq_num')").Check(testkit.Rows(fmt.Sprintf("\"drop table t, t2\" %d", firstSequence+3))) } -func TestRegexpFunctionsGeneratedColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // test regexp_like - tk.MustExec("drop table if exists reg_like") - tk.MustExec("create table reg_like(a varchar(50), b varchar(50), c int generated always as (regexp_like(a, b)))") - tk.MustExec("insert into reg_like(a, b) values('123', '2')") - tk.MustExec("insert into reg_like(a, b) values('456', '1')") - tk.MustQuery("select * from reg_like").Check(testkit.Rows("123 2 1", "456 1 0")) - - // test regexp_substr - tk.MustExec("drop table if exists reg_sub;") - tk.MustExec("create table reg_sub(a varchar(50),b varchar(50),c varchar(50) generated always as (regexp_substr(a, b)))") - tk.MustExec("insert into reg_sub(a, b) values('abcd', 'bc.')") - tk.MustExec("insert into reg_sub(a, b) values('1234', '23.')") - tk.MustQuery("select * from reg_sub").Check(testkit.Rows("abcd bc. bcd", "1234 23. 234")) - - // test regexp_instr - tk.MustExec("drop table if exists reg_instr;") - tk.MustExec("create table reg_instr(a varchar(50),b varchar(50),c varchar(50) generated always as (regexp_instr(a, b)))") - tk.MustExec("insert into reg_instr(a, b) values('abcd', 'bc.')") - tk.MustExec("insert into reg_instr(a, b) values('1234', '23.')") - tk.MustQuery("select * from reg_instr").Check(testkit.Rows("abcd bc. 2", "1234 23. 2")) - - // test regexp_replace - tk.MustExec("drop table if exists reg_replace;") - tk.MustExec("create table reg_replace(a varchar(50),b varchar(50),c varchar(50),d varchar(50) generated always as (regexp_replace(a, b, c)));") - tk.MustExec("insert into reg_replace(a, b, c) values('abcd', 'bc.', 'xzx')") - tk.MustExec("insert into reg_replace(a, b, c) values('1234', '23.', 'xzx')") - tk.MustQuery("select * from reg_replace").Check(testkit.Rows("abcd bc. xzx axzx", "1234 23. xzx 1xzx")) - - tk.MustExec("drop table if exists reg_like") -} - -func TestReorgPartitionRangeFailure(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`create schema reorgfail`) - tk.MustExec("use reorgfail") - - tk.MustExec("CREATE TABLE t (id int, d varchar(255)) partition by range (id) (partition p0 values less than (1000000), partition p1 values less than (2000000), partition p2 values less than (3000000))") - tk.MustContainErrMsg(`ALTER TABLE t REORGANIZE PARTITION p0,p2 INTO (PARTITION p0 VALUES LESS THAN (1000000))`, "[ddl:8200]Unsupported REORGANIZE PARTITION of RANGE; not adjacent partitions") - tk.MustContainErrMsg(`ALTER TABLE t REORGANIZE PARTITION p0,p2 INTO (PARTITION p0 VALUES LESS THAN (4000000))`, "[ddl:8200]Unsupported REORGANIZE PARTITION of RANGE; not adjacent partitions") -} - -func TestReorgPartitionDocs(t *testing.T) { - // To test what is added as partition management in the docs - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`create schema reorgdocs`) - tk.MustExec("use reorgdocs") - tk.MustExec(`CREATE TABLE members ( - id int, - fname varchar(255), - lname varchar(255), - dob date, - data json -) -PARTITION BY RANGE (YEAR(dob)) ( - PARTITION pBefore1950 VALUES LESS THAN (1950), - PARTITION p1950 VALUES LESS THAN (1960), - PARTITION p1960 VALUES LESS THAN (1970), - PARTITION p1970 VALUES LESS THAN (1980), - PARTITION p1980 VALUES LESS THAN (1990), - PARTITION p1990 VALUES LESS THAN (2000))`) - tk.MustExec(`CREATE TABLE member_level ( - id int, - level int, - achievements json -) -PARTITION BY LIST (level) ( - PARTITION l1 VALUES IN (1), - PARTITION l2 VALUES IN (2), - PARTITION l3 VALUES IN (3), - PARTITION l4 VALUES IN (4), - PARTITION l5 VALUES IN (5));`) - tk.MustExec(`ALTER TABLE members DROP PARTITION p1990`) - tk.MustExec(`ALTER TABLE member_level DROP PARTITION l5`) - tk.MustExec(`ALTER TABLE members TRUNCATE PARTITION p1980`) - tk.MustExec(`ALTER TABLE member_level TRUNCATE PARTITION l4`) - tk.MustExec("ALTER TABLE members ADD PARTITION (PARTITION `p1990to2010` VALUES LESS THAN (2010))") - tk.MustExec(`ALTER TABLE member_level ADD PARTITION (PARTITION l5_6 VALUES IN (5,6))`) - tk.MustContainErrMsg(`ALTER TABLE members ADD PARTITION (PARTITION p1990 VALUES LESS THAN (2000))`, "[ddl:1493]VALUES LESS THAN value must be strictly increasing for each partition") - tk.MustExec(`ALTER TABLE members REORGANIZE PARTITION p1990to2010 INTO -(PARTITION p1990 VALUES LESS THAN (2000), - PARTITION p2000 VALUES LESS THAN (2010), - PARTITION p2010 VALUES LESS THAN (2020), - PARTITION p2020 VALUES LESS THAN (2030), - PARTITION pMax VALUES LESS THAN (MAXVALUE))`) - tk.MustExec(`ALTER TABLE member_level REORGANIZE PARTITION l5_6 INTO -(PARTITION l5 VALUES IN (5), - PARTITION l6 VALUES IN (6))`) - tk.MustExec(`ALTER TABLE members REORGANIZE PARTITION pBefore1950,p1950 INTO (PARTITION pBefore1960 VALUES LESS THAN (1960))`) - tk.MustExec(`ALTER TABLE member_level REORGANIZE PARTITION l1,l2 INTO (PARTITION l1_2 VALUES IN (1,2))`) - tk.MustExec(`ALTER TABLE members REORGANIZE PARTITION pBefore1960,p1960,p1970,p1980,p1990,p2000,p2010,p2020,pMax INTO -(PARTITION p1800 VALUES LESS THAN (1900), - PARTITION p1900 VALUES LESS THAN (2000), - PARTITION p2000 VALUES LESS THAN (2100))`) - tk.MustExec(`ALTER TABLE member_level REORGANIZE PARTITION l1_2,l3,l4,l5,l6 INTO -(PARTITION lOdd VALUES IN (1,3,5), - PARTITION lEven VALUES IN (2,4,6))`) - tk.MustContainErrMsg(`ALTER TABLE members REORGANIZE PARTITION p1800,p2000 INTO (PARTITION p2000 VALUES LESS THAN (2100))`, "[ddl:8200]Unsupported REORGANIZE PARTITION of RANGE; not adjacent partitions") - tk.MustExec(`INSERT INTO members VALUES (313, "John", "Doe", "2022-11-22", NULL)`) - tk.MustExec(`ALTER TABLE members REORGANIZE PARTITION p2000 INTO (PARTITION p2000 VALUES LESS THAN (2050))`) - tk.MustContainErrMsg(`ALTER TABLE members REORGANIZE PARTITION p2000 INTO (PARTITION p2000 VALUES LESS THAN (2020))`, "[table:1526]Table has no partition for value 2022") - tk.MustExec(`INSERT INTO member_level (id, level) values (313, 6)`) - tk.MustContainErrMsg(`ALTER TABLE member_level REORGANIZE PARTITION lEven INTO (PARTITION lEven VALUES IN (2,4))`, "[table:1526]Table has no partition for value 6") -} - -func TestDisableDDL(t *testing.T) { - // https://github.com/pingcap/tidb/issues/41277 - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustQuery("select @@global.tidb_enable_ddl").Check(testkit.Rows("1")) - tk.MustGetErrCode("set @@global.tidb_enable_ddl=false;", errno.ErrDDLSetting) - tk.MustGetErrCode("set @@global.tidb_enable_ddl=false;", errno.ErrDDLSetting) - tk.MustQuery("select @@global.tidb_enable_ddl").Check(testkit.Rows("1")) -} - -func TestReorganizePartitionWarning(t *testing.T) { - // https://github.com/pingcap/tidb/issues/42183 - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (id bigint, b varchar(20), index idxb(b)) partition by range(id) (partition p0 values less than (20), partition p1 values less than (100));") - tk.MustExec("alter table t reorganize partition p0 into (partition p01 values less than (10), partition p02 values less than (20));") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 The statistics of related partitions will be outdated after reorganizing partitions. Please use 'ANALYZE TABLE' statement if you want to update it now")) -} - func TestDefaultCollationForUTF8MB4(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) tk := testkit.NewTestKit(t, store) diff --git a/ddl/db_rename_test.go b/ddl/db_rename_test.go index 0bbe0eaea7e3e..8cf8fbe0c9815 100644 --- a/ddl/db_rename_test.go +++ b/ddl/db_rename_test.go @@ -27,30 +27,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestRenameIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (pk int primary key, c int default 1, c1 int default 1, unique key k1(c), key k2(c1))") - - // Test rename success - tk.MustExec("alter table t rename index k1 to k3") - tk.MustExec("admin check index t k3") - - // Test rename to the same name - tk.MustExec("alter table t rename index k3 to k3") - tk.MustExec("admin check index t k3") - - // Test rename on non-exists keys - tk.MustGetErrCode("alter table t rename index x to x", errno.ErrKeyDoesNotExist) - - // Test rename on already-exists keys - tk.MustGetErrCode("alter table t rename index k3 to k2", errno.ErrDupKeyName) - - tk.MustExec("alter table t rename index k2 to K2") - tk.MustGetErrCode("alter table t rename key k3 to K2", errno.ErrDupKeyName) -} - // See issue: https://github.com/pingcap/tidb/issues/29752 // Ref https://dev.mysql.com/doc/refman/8.0/en/rename-table.html func TestRenameTableWithLocked(t *testing.T) { diff --git a/ddl/db_table_test.go b/ddl/db_table_test.go index 5e8fdc73fcd7f..fd918ed370771 100644 --- a/ddl/db_table_test.go +++ b/ddl/db_table_test.go @@ -48,37 +48,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestTableForeignKey(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t1 (a int, b int, index(a), index(b));") - // test create table with foreign key. - failSQL := "create table t2 (c int, foreign key (a) references t1(a));" - tk.MustGetErrCode(failSQL, errno.ErrKeyColumnDoesNotExits) - // test add foreign key. - tk.MustExec("create table t3 (a int, b int);") - failSQL = "alter table t1 add foreign key (c) REFERENCES t3(a);" - tk.MustGetErrCode(failSQL, errno.ErrKeyColumnDoesNotExits) - // test origin key not match error - failSQL = "alter table t1 add foreign key (a) REFERENCES t3(a, b);" - tk.MustGetErrCode(failSQL, errno.ErrWrongFkDef) - // Test drop column with foreign key. - tk.MustExec("create table t4 (c int,d int,foreign key (d) references t1 (b));") - failSQL = "alter table t4 drop column d" - tk.MustGetErrCode(failSQL, errno.ErrFkColumnCannotDrop) - // Test change column with foreign key. - failSQL = "alter table t4 change column d e bigint;" - tk.MustGetErrCode(failSQL, errno.ErrFKIncompatibleColumns) - // Test modify column with foreign key. - failSQL = "alter table t4 modify column d bigint;" - tk.MustGetErrCode(failSQL, errno.ErrFKIncompatibleColumns) - tk.MustQuery("select count(*) from information_schema.KEY_COLUMN_USAGE;") - tk.MustExec("alter table t4 drop foreign key fk_1") - tk.MustExec("alter table t4 modify column d bigint;") - tk.MustExec("drop table if exists t1,t2,t3,t4;") -} - func TestAddNotNullColumn(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -110,29 +79,6 @@ out: tk.MustExec("drop table tnn") } -func TestCharacterSetInColumns(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database varchar_test;") - defer tk.MustExec("drop database varchar_test;") - tk.MustExec("use varchar_test") - tk.MustExec("create table t (c1 int, s1 varchar(10), s2 text)") - tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name != 'utf8mb4'").Check(testkit.Rows("0")) - tk.MustQuery("select count(*) from information_schema.columns where table_schema = 'varchar_test' and character_set_name = 'utf8mb4'").Check(testkit.Rows("2")) - - tk.MustExec("create table t1(id int) charset=UTF8;") - tk.MustExec("create table t2(id int) charset=BINARY;") - tk.MustExec("create table t3(id int) charset=LATIN1;") - tk.MustExec("create table t4(id int) charset=ASCII;") - tk.MustExec("create table t5(id int) charset=UTF8MB4;") - - tk.MustExec("create table t11(id int) charset=utf8;") - tk.MustExec("create table t12(id int) charset=binary;") - tk.MustExec("create table t13(id int) charset=latin1;") - tk.MustExec("create table t14(id int) charset=ascii;") - tk.MustExec("create table t15(id int) charset=utf8mb4;") -} - func TestAddNotNullColumnWhileInsertOnDupUpdate(t *testing.T) { store := testkit.CreateMockStore(t) tk1 := testkit.NewTestKit(t, store) @@ -363,26 +309,6 @@ func TestCreateTableWithIntegerColWithDefault(t *testing.T) { require.True(t, strings.Contains(ret.(string), "`a` double DEFAULT '12.43'")) } -func TestAlterTableWithValidation(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - defer tk.MustExec("drop table if exists t1") - - tk.MustExec("create table t1 (c1 int, c2 int as (c1 + 1));") - - // Test for alter table with validation. - tk.MustExec("alter table t1 with validation") - require.Equal(t, uint16(1), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|8200|ALTER TABLE WITH VALIDATION is currently unsupported")) - - // Test for alter table without validation. - tk.MustExec("alter table t1 without validation") - require.Equal(t, uint16(1), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|8200|ALTER TABLE WITHOUT VALIDATION is currently unsupported")) -} - func TestCreateTableWithInfo(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) @@ -496,28 +422,6 @@ func TestBatchCreateTable(t *testing.T) { require.NoError(t, err) } -// port from mysql -// https://github.com/mysql/mysql-server/blob/124c7ab1d6f914637521fd4463a993aa73403513/mysql-test/t/lock.test -func TestLock(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - /* Testing of table locking */ - tk.MustExec("DROP TABLE IF EXISTS t1") - tk.MustExec("CREATE TABLE t1 ( `id` int(11) NOT NULL default '0', `id2` int(11) NOT NULL default '0', `id3` int(11) NOT NULL default '0', `dummy1` char(30) default NULL, PRIMARY KEY (`id`,`id2`), KEY `index_id3` (`id3`))") - tk.MustExec("insert into t1 (id,id2) values (1,1),(1,2),(1,3)") - tk.MustExec("LOCK TABLE t1 WRITE") - tk.MustExec("select dummy1,count(distinct id) from t1 group by dummy1") - tk.MustExec("update t1 set id=-1 where id=1") - tk.MustExec("LOCK TABLE t1 READ") - _, err := tk.Exec("update t1 set id=1 where id=1") - require.True(t, terror.ErrorEqual(err, infoschema.ErrTableNotLockedForWrite)) - tk.MustExec("unlock tables") - tk.MustExec("update t1 set id=1 where id=-1") - tk.MustExec("drop table t1") -} - // port from mysql // https://github.com/mysql/mysql-server/blob/4f1d7cf5fcb11a3f84cff27e37100d7295e7d5ca/mysql-test/t/tablelock.test func TestTableLock(t *testing.T) { @@ -854,31 +758,6 @@ func TestTablesLockDelayClean(t *testing.T) { }) } -func TestDDLWithInvalidTableInfo(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - defer tk.MustExec("drop table if exists t") - // Test create with invalid expression. - _, err := tk.Exec(`CREATE TABLE t ( - c0 int(11) , - c1 int(11), - c2 decimal(16,4) GENERATED ALWAYS AS ((case when (c0 = 0) then 0when (c0 > 0) then (c1 / c0) end)) - );`) - require.Error(t, err) - require.Equal(t, "[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 4 column 88 near \"then (c1 / c0) end))\n\t);\" ", err.Error()) - - tk.MustExec("create table t (a bigint, b int, c int generated always as (b+1)) partition by hash(a) partitions 4;") - // Test drop partition column. - tk.MustGetErrMsg("alter table t drop column a;", "[ddl:3855]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") - // Test modify column with invalid expression. - tk.MustGetErrMsg("alter table t modify column c int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end));", "[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 97 near \"then (b / a) end));\" ") - // Test add column with invalid expression. - tk.MustGetErrMsg("alter table t add column d int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end));", "[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 94 near \"then (b / a) end));\" ") -} - func TestAddColumn2(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) diff --git a/ddl/db_test.go b/ddl/db_test.go index 0608f1c647f4c..bb4fd2e475651 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -41,14 +41,11 @@ import ( "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/terror" parsertypes "github.com/pingcap/tidb/parser/types" - "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/sessiontxn" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/testkit/external" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util" - "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/sqlexec" "github.com/stretchr/testify/require" @@ -67,64 +64,6 @@ const defaultBatchSize = 1024 const dbTestLease = 600 * time.Millisecond -// Close issue #24580 -// See https://github.com/pingcap/tidb/issues/24580 -func TestIssue24580(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(250) default null);") - tk.MustExec("insert into t values();") - tk.MustGetErrMsg("alter table t modify a char not null;", "[ddl:1265]Data truncated for column 'a' at row 1") - tk.MustExec("drop table if exists t") -} - -// Close issue #27862 https://github.com/pingcap/tidb/issues/27862 -// Ref: https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html#data-types-storage-reqs-strings -// text(100) in utf8mb4 charset needs max 400 byte length, thus tinytext is not enough. -func TestCreateTextAdjustLen(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a text(100));") - tk.MustQuery("show create table t").Check(testkit.RowsWithSep("|", ""+ - "t CREATE TABLE `t` (\n"+ - " `a` text DEFAULT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - tk.MustExec("alter table t add b text(100);") - tk.MustExec("alter table t add c text;") - tk.MustExec("alter table t add d text(50);") - tk.MustExec("alter table t change column a a text(50);") - tk.MustQuery("show create table t").Check(testkit.RowsWithSep("|", ""+ - "t CREATE TABLE `t` (\n"+ - " `a` tinytext DEFAULT NULL,\n"+ - " `b` text DEFAULT NULL,\n"+ - " `c` text DEFAULT NULL,\n"+ - " `d` tinytext DEFAULT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - - // Ref: https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html - // TINYBLOB, TINYTEXT L + 1 bytes, where L < 2^8 - // BLOB, TEXT L + 2 bytes, where L < 2^16 - // MEDIUMBLOB, MEDIUMTEXT L + 3 bytes, where L < 2^24 - // LONGBLOB, LONGTEXT L + 4 bytes, where L < 2^32 - tk.MustExec("alter table t change column d d text(100);") - tk.MustExec("alter table t change column c c text(30000);") - tk.MustExec("alter table t change column b b text(10000000);") - tk.MustQuery("show create table t").Check(testkit.RowsWithSep("|", ""+ - "t CREATE TABLE `t` (\n"+ - " `a` tinytext DEFAULT NULL,\n"+ - " `b` longtext DEFAULT NULL,\n"+ - " `c` mediumtext DEFAULT NULL,\n"+ - " `d` text DEFAULT NULL\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) - tk.MustExec("drop table if exists t") -} - func TestGetTimeZone(t *testing.T) { store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) @@ -167,77 +106,6 @@ func TestGetTimeZone(t *testing.T) { } } -// for issue #30328 -func TestTooBigFieldLengthAutoConvert(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - err := tk.ExecToErr("create table i30328_1(a varbinary(70000), b varchar(70000000))") - require.True(t, types.ErrTooBigFieldLength.Equal(err)) - - // save previous sql_mode and change - r := tk.MustQuery("select @@sql_mode") - defer func(sqlMode string) { - tk.MustExec("set @@sql_mode= '" + sqlMode + "'") - tk.MustExec("drop table if exists i30328_1") - tk.MustExec("drop table if exists i30328_2") - }(r.Rows()[0][0].(string)) - tk.MustExec("set @@sql_mode='NO_ENGINE_SUBSTITUTION'") - - tk.MustExec("create table i30328_1(a varbinary(70000), b varchar(70000000))") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1246 Converting column 'a' from VARBINARY to BLOB", "Warning 1246 Converting column 'b' from VARCHAR to TEXT")) - tk.MustExec("create table i30328_2(a varchar(200))") - tk.MustExec("alter table i30328_2 modify a varchar(70000000);") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1246 Converting column 'a' from VARCHAR to TEXT")) -} - -// For Close issue #24288 -// see https://github.com/pingcap/tidb/issues/24288 -func TestDdlMaxLimitOfIdentifier(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - - // create/drop database test - longDbName := strings.Repeat("库", mysql.MaxDatabaseNameLength-1) - tk.MustExec(fmt.Sprintf("create database %s", longDbName)) - defer func() { - tk.MustExec(fmt.Sprintf("drop database %s", longDbName)) - }() - tk.MustExec(fmt.Sprintf("use %s", longDbName)) - - // create/drop table,index test - longTblName := strings.Repeat("表", mysql.MaxTableNameLength-1) - longColName := strings.Repeat("三", mysql.MaxColumnNameLength-1) - longIdxName := strings.Repeat("索", mysql.MaxIndexIdentifierLen-1) - tk.MustExec(fmt.Sprintf("create table %s(f1 int primary key,f2 int, %s varchar(50))", longTblName, longColName)) - tk.MustExec(fmt.Sprintf("create index %s on %s(%s)", longIdxName, longTblName, longColName)) - defer func() { - tk.MustExec(fmt.Sprintf("drop index %s on %s", longIdxName, longTblName)) - tk.MustExec(fmt.Sprintf("drop table %s", longTblName)) - }() - - // alter table - tk.MustExec(fmt.Sprintf("alter table %s change f2 %s int", longTblName, strings.Repeat("二", mysql.MaxColumnNameLength-1))) -} - -// Close issue #23321. -// See https://github.com/pingcap/tidb/issues/23321 -func TestJsonUnmarshalErrWhenPanicInCancellingPath(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists test_add_index_after_add_col") - tk.MustExec("create table test_add_index_after_add_col(a int, b int not null default '0');") - tk.MustExec("insert into test_add_index_after_add_col values(1, 2),(2,2);") - tk.MustExec("alter table test_add_index_after_add_col add column c int not null default '0';") - tk.MustGetErrMsg("alter table test_add_index_after_add_col add unique index cc(c);", "[kv:1062]Duplicate entry '0' for key 'test_add_index_after_add_col.cc'") -} - func TestIssue22819(t *testing.T) { store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) @@ -287,53 +155,6 @@ func TestIssue22307(t *testing.T) { require.EqualError(t, checkErr2, "[planner:1054]Unknown column 'b' in 'order clause'") } -func TestIssue9100(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table employ (a int, b int) partition by range (b) (partition p0 values less than (1));") - tk.MustGetErrMsg("alter table employ add unique index p_a (a);", "[ddl:1503]A UNIQUE INDEX must include all columns in the table's partitioning function") - tk.MustGetErrMsg("alter table employ add primary key p_a (a);", "[ddl:1503]A PRIMARY must include all columns in the table's partitioning function") - - tk.MustExec("create table issue9100t1 (col1 int not null, col2 date not null, col3 int not null, unique key (col1, col2)) partition by range( col1 ) (partition p1 values less than (11))") - tk.MustExec("alter table issue9100t1 add unique index p_col1 (col1)") - tk.MustExec("alter table issue9100t1 add primary key p_col1 (col1)") - - tk.MustExec("create table issue9100t2 (col1 int not null, col2 date not null, col3 int not null, unique key (col1, col3)) partition by range( col1 + col3 ) (partition p1 values less than (11))") - tk.MustGetErrMsg("alter table issue9100t2 add unique index p_col1 (col1)", "[ddl:1503]A UNIQUE INDEX must include all columns in the table's partitioning function") - tk.MustGetErrMsg("alter table issue9100t2 add primary key p_col1 (col1)", "[ddl:1503]A PRIMARY must include all columns in the table's partitioning function") -} - -func TestIssue22207(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec("set @@session.tidb_enable_exchange_partition = 1;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t1(id char(10)) partition by list columns(id) (partition p0 values in ('a'), partition p1 values in ('b'));") - tk.MustExec("insert into t1 VALUES('a')") - tk.MustExec("create table t2(id char(10));") - tk.MustExec("ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;") - tk.MustQuery("select * from t2").Check(testkit.Rows("a")) - require.Len(t, tk.MustQuery("select * from t1").Rows(), 0) - - tk.MustExec("drop table if exists t1;") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t1 (id int) partition by list (id) (partition p0 values in (1,2,3), partition p1 values in (4,5,6));") - tk.MustExec("insert into t1 VALUES(1);") - tk.MustExec("insert into t1 VALUES(2);") - tk.MustExec("insert into t1 VALUES(3);") - tk.MustExec("create table t2(id int);") - tk.MustExec("ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;") - tk.MustQuery("select * from t2").Check(testkit.Rows("1", "2", "3")) - require.Len(t, tk.MustQuery("select * from t1").Rows(), 0) - tk.MustExec("set @@session.tidb_enable_exchange_partition = 0;") -} - func TestIssue23473(t *testing.T) { store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) @@ -347,148 +168,6 @@ func TestIssue23473(t *testing.T) { require.True(t, mysql.HasNoDefaultValueFlag(tbl.Cols()[0].GetFlag())) } -func TestAlterOrderBy(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table ob (pk int primary key, c int default 1, c1 int default 1, KEY cl(c1))") - - // Test order by with primary key - tk.MustExec("alter table ob order by c") - require.Equal(t, uint16(1), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1105|ORDER BY ignored as there is a user-defined clustered index in the table 'ob'")) - - // Test order by with no primary key - tk.MustExec("drop table if exists ob") - tk.MustExec("create table ob (c int default 1, c1 int default 1, KEY cl(c1))") - tk.MustExec("alter table ob order by c") - require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - tk.MustExec("drop table if exists ob") -} - -func TestFKOnGeneratedColumns(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // test add foreign key to generated column - - // foreign key constraint cannot be defined on a virtual generated column. - tk.MustExec("create table t1 (a int primary key);") - tk.MustGetErrCode("create table t2 (a int, b int as (a+1) virtual, foreign key (b) references t1(a));", errno.ErrForeignKeyCannotUseVirtualColumn) - tk.MustExec("create table t2 (a int, b int generated always as (a+1) virtual);") - tk.MustGetErrCode("alter table t2 add foreign key (b) references t1(a);", errno.ErrForeignKeyCannotUseVirtualColumn) - tk.MustExec("drop table t1, t2;") - - // foreign key constraint can be defined on a stored generated column. - tk.MustExec("create table t2 (a int primary key);") - tk.MustExec("create table t1 (a int, b int as (a+1) stored, foreign key (b) references t2(a));") - tk.MustExec("create table t3 (a int, b int generated always as (a+1) stored);") - tk.MustExec("alter table t3 add foreign key (b) references t2(a);") - tk.MustExec("drop table t1, t2, t3;") - - // foreign key constraint can reference a stored generated column. - tk.MustExec("create table t1 (a int, b int generated always as (a+1) stored primary key);") - tk.MustExec("create table t2 (a int, foreign key (a) references t1(b));") - tk.MustExec("create table t3 (a int);") - tk.MustExec("alter table t3 add foreign key (a) references t1(b);") - tk.MustExec("drop table t1, t2, t3;") - - // rejected FK options on stored generated columns - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set null);", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update cascade);", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set default);", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on delete set null);", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on delete set default);", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustExec("create table t2 (a int primary key);") - tk.MustExec("create table t1 (a int, b int generated always as (a+1) stored);") - tk.MustGetErrCode("alter table t1 add foreign key (b) references t2(a) on update set null;", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("alter table t1 add foreign key (b) references t2(a) on update cascade;", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("alter table t1 add foreign key (b) references t2(a) on update set default;", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("alter table t1 add foreign key (b) references t2(a) on delete set null;", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustGetErrCode("alter table t1 add foreign key (b) references t2(a) on delete set default;", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustExec("drop table t1, t2;") - // column name with uppercase characters - tk.MustGetErrCode("create table t1 (A int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set null);", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustExec("create table t2 (a int primary key);") - tk.MustExec("create table t1 (A int, b int generated always as (a+1) stored);") - tk.MustGetErrCode("alter table t1 add foreign key (b) references t2(a) on update set null;", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustExec("drop table t1, t2;") - - tk.MustExec("create table t1 (a int, b int generated always as (a+1) stored);") - tk.MustGetErrCode("alter table t1 add foreign key (b) references t2(a) on update set null;", errno.ErrWrongFKOptionForGeneratedColumn) - tk.MustExec("drop table t1;") - - // allowed FK options on stored generated columns - tk.MustExec("create table t1 (a int primary key, b char(5));") - tk.MustExec("create table t2 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on update restrict);") - tk.MustExec("create table t3 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on update no action);") - tk.MustExec("create table t4 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on delete restrict);") - tk.MustExec("create table t5 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on delete cascade);") - tk.MustExec("create table t6 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on delete no action);") - tk.MustExec("drop table t2,t3,t4,t5,t6;") - tk.MustExec("create table t2 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t2 add foreign key (b) references t1(a) on update restrict;") - tk.MustExec("create table t3 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t3 add foreign key (b) references t1(a) on update no action;") - tk.MustExec("create table t4 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t4 add foreign key (b) references t1(a) on delete restrict;") - tk.MustExec("create table t5 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t5 add foreign key (b) references t1(a) on delete cascade;") - tk.MustExec("create table t6 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t6 add foreign key (b) references t1(a) on delete no action;") - tk.MustExec("drop table t1,t2,t3,t4,t5,t6;") - - // rejected FK options on the base columns of a stored generated columns - tk.MustExec("create table t2 (a int primary key);") - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on update set null);", errno.ErrCannotAddForeign) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on update cascade);", errno.ErrCannotAddForeign) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on update set default);", errno.ErrCannotAddForeign) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on delete set null);", errno.ErrCannotAddForeign) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on delete cascade);", errno.ErrCannotAddForeign) - tk.MustGetErrCode("create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on delete set default);", errno.ErrCannotAddForeign) - tk.MustExec("create table t1 (a int, b int generated always as (a+1) stored);") - tk.MustGetErrCode("alter table t1 add foreign key (a) references t2(a) on update set null;", errno.ErrCannotAddForeign) - tk.MustGetErrCode("alter table t1 add foreign key (a) references t2(a) on update cascade;", errno.ErrCannotAddForeign) - tk.MustGetErrCode("alter table t1 add foreign key (a) references t2(a) on update set default;", errno.ErrCannotAddForeign) - tk.MustGetErrCode("alter table t1 add foreign key (a) references t2(a) on delete set null;", errno.ErrCannotAddForeign) - tk.MustGetErrCode("alter table t1 add foreign key (a) references t2(a) on delete cascade;", errno.ErrCannotAddForeign) - tk.MustGetErrCode("alter table t1 add foreign key (a) references t2(a) on delete set default;", errno.ErrCannotAddForeign) - tk.MustExec("drop table t1, t2;") - - // allowed FK options on the base columns of a stored generated columns - tk.MustExec("create table t1 (a int primary key, b char(5));") - tk.MustExec("create table t2 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on update restrict);") - tk.MustExec("create table t3 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on update no action);") - tk.MustExec("create table t4 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on delete restrict);") - tk.MustExec("create table t5 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on delete no action);") - tk.MustExec("drop table t2,t3,t4,t5") - tk.MustExec("create table t2 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t2 add foreign key (a) references t1(a) on update restrict;") - tk.MustExec("create table t3 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t3 add foreign key (a) references t1(a) on update no action;") - tk.MustExec("create table t4 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t4 add foreign key (a) references t1(a) on delete restrict;") - tk.MustExec("create table t5 (a int, b int generated always as (a % 10) stored);") - tk.MustExec("alter table t5 add foreign key (a) references t1(a) on delete no action;") - tk.MustExec("drop table t1,t2,t3,t4,t5;") -} - -func TestSelectInViewFromAnotherDB(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create database test_db2") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int)") - tk.MustExec("use test_db2") - tk.MustExec("create sql security invoker view v as select * from test.t") - tk.MustExec("use test") - tk.MustExec("select test_db2.v.a from test_db2.v") -} - func TestAutoConvertBlobTypeByLength(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) @@ -596,95 +275,6 @@ func TestDropTableOnTiKVDiskFull(t *testing.T) { tk.MustExec("drop table test_disk_full_drop_table;") } -func TestComment(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists ct, ct1") - - validComment := strings.Repeat("a", 1024) - invalidComment := strings.Repeat("b", 1025) - validTableComment := strings.Repeat("a", 2048) - invalidTableComment := strings.Repeat("b", 2049) - - // test table comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer) COMMENT = '" + validTableComment + "'") - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer)") - tk.MustExec("ALTER TABLE t COMMENT = '" + validTableComment + "'") - - // test column comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer NOT NULL COMMENT '" + validComment + "')") - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer)") - tk.MustExec("ALTER TABLE t ADD COLUMN c1 integer COMMENT '" + validComment + "'") - - // test index comment - tk.MustExec("create table ct (c int, d int, e int, key (c) comment '" + validComment + "')") - tk.MustExec("create index i on ct (d) comment '" + validComment + "'") - tk.MustExec("alter table ct add key (e) comment '" + validComment + "'") - - // test table partition comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (0) COMMENT '" + validComment + "')") - tk.MustExec("ALTER TABLE t ADD PARTITION (PARTITION p1 VALUES LESS THAN (1000000) COMMENT '" + validComment + "')") - - // test table comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustGetErrCode("CREATE TABLE t (c integer) COMMENT = '"+invalidTableComment+"'", errno.ErrTooLongTableComment) - tk.MustExec("CREATE TABLE t (c integer)") - tk.MustGetErrCode("ALTER TABLE t COMMENT = '"+invalidTableComment+"'", errno.ErrTooLongTableComment) - - // test column comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustGetErrCode("CREATE TABLE t (c integer NOT NULL COMMENT '"+invalidComment+"')", errno.ErrTooLongFieldComment) - tk.MustExec("CREATE TABLE t (c integer)") - tk.MustGetErrCode("ALTER TABLE t ADD COLUMN c1 integer COMMENT '"+invalidComment+"'", errno.ErrTooLongFieldComment) - - // test index comment - tk.MustGetErrCode("create table ct1 (c int, key (c) comment '"+invalidComment+"')", errno.ErrTooLongIndexComment) - tk.MustGetErrCode("create index i1 on ct (d) comment '"+invalidComment+"'", errno.ErrTooLongIndexComment) - tk.MustGetErrCode("alter table ct add key (e) comment '"+invalidComment+"'", errno.ErrTooLongIndexComment) - - // test table partition comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustGetErrCode("CREATE TABLE t (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (0) COMMENT '"+invalidComment+"')", errno.ErrTooLongTablePartitionComment) - tk.MustExec("CREATE TABLE t (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (0) COMMENT '" + validComment + "')") - tk.MustGetErrCode("ALTER TABLE t ADD PARTITION (PARTITION p1 VALUES LESS THAN (1000000) COMMENT '"+invalidComment+"')", errno.ErrTooLongTablePartitionComment) - - tk.MustExec("set @@sql_mode=''") - - // test table comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer) COMMENT = '" + invalidTableComment + "'") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1628|Comment for table 't' is too long (max = 2048)")) - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer)") - tk.MustExec("ALTER TABLE t COMMENT = '" + invalidTableComment + "'") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1628|Comment for table 't' is too long (max = 2048)")) - - // test column comment - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer NOT NULL COMMENT '" + invalidComment + "')") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1629|Comment for field 'c' is too long (max = 1024)")) - tk.MustExec("DROP TABLE IF EXISTS t") - tk.MustExec("CREATE TABLE t (c integer)") - tk.MustExec("ALTER TABLE t ADD COLUMN c1 integer COMMENT '" + invalidComment + "'") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1629|Comment for field 'c1' is too long (max = 1024)")) - - // test index comment - tk.MustExec("create table ct1 (c int, d int, e int, key (c) comment '" + invalidComment + "')") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1688|Comment for index 'c' is too long (max = 1024)")) - tk.MustExec("create index i1 on ct1 (d) comment '" + invalidComment + "b" + "'") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1688|Comment for index 'i1' is too long (max = 1024)")) - tk.MustExec("alter table ct1 add key (e) comment '" + invalidComment + "'") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1688|Comment for index 'e' is too long (max = 1024)")) - - tk.MustExec("drop table if exists ct, ct1") -} - func TestRebaseAutoID(t *testing.T) { require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`)) defer func() { require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange")) }() @@ -819,90 +409,6 @@ func TestAlterShardRowIDBits(t *testing.T) { tk.MustGetErrMsg("insert into t1 set a=1;", "[autoid:1467]Failed to read auto-increment value from storage engine") } -func TestShardRowIDBitsOnTemporaryTable(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // for global temporary table - tk.MustExec("drop table if exists shard_row_id_temporary") - tk.MustGetErrMsg( - "create global temporary table shard_row_id_temporary (a int) shard_row_id_bits = 5 on commit delete rows;", - core.ErrOptOnTemporaryTable.GenWithStackByArgs("shard_row_id_bits").Error()) - tk.MustExec("create global temporary table shard_row_id_temporary (a int) on commit delete rows;") - tk.MustGetErrMsg( - "alter table shard_row_id_temporary shard_row_id_bits = 4;", - dbterror.ErrOptOnTemporaryTable.GenWithStackByArgs("shard_row_id_bits").Error()) - // for local temporary table - tk.MustExec("drop table if exists local_shard_row_id_temporary") - tk.MustGetErrMsg( - "create temporary table local_shard_row_id_temporary (a int) shard_row_id_bits = 5;", - core.ErrOptOnTemporaryTable.GenWithStackByArgs("shard_row_id_bits").Error()) - tk.MustExec("create temporary table local_shard_row_id_temporary (a int);") - tk.MustGetErrMsg( - "alter table local_shard_row_id_temporary shard_row_id_bits = 4;", - dbterror.ErrUnsupportedLocalTempTableDDL.GenWithStackByArgs("ALTER TABLE").Error()) -} - -func TestAutoIncrementIDOnTemporaryTable(t *testing.T) { - store := testkit.CreateMockStoreWithSchemaLease(t, dbTestLease) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // global temporary table with auto_increment=0 - tk.MustExec("drop table if exists global_temp_auto_id") - tk.MustExec("create global temporary table global_temp_auto_id(id int primary key auto_increment) on commit delete rows") - tk.MustExec("begin") - tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 1 _TIDB_ROWID")) - tk.MustExec("insert into global_temp_auto_id value(null)") - tk.MustQuery("select @@last_insert_id").Check(testkit.Rows("1")) - tk.MustQuery("select id from global_temp_auto_id").Check(testkit.Rows("1")) - tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 2 _TIDB_ROWID")) - tk.MustExec("commit") - tk.MustExec("drop table global_temp_auto_id") - - // global temporary table with auto_increment=100 - tk.MustExec("create global temporary table global_temp_auto_id(id int primary key auto_increment) auto_increment=100 on commit delete rows") - // the result should be the same in each transaction - for i := 0; i < 2; i++ { - tk.MustQuery("show create table global_temp_auto_id").Check(testkit.Rows("global_temp_auto_id CREATE GLOBAL TEMPORARY TABLE `global_temp_auto_id` (\n" + - " `id` int(11) NOT NULL AUTO_INCREMENT,\n" + - " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100 ON COMMIT DELETE ROWS")) - tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 100 _TIDB_ROWID")) - tk.MustExec("begin") - tk.MustExec("insert into global_temp_auto_id value(null)") - tk.MustQuery("select @@last_insert_id").Check(testkit.Rows("100")) - tk.MustQuery("select id from global_temp_auto_id").Check(testkit.Rows("100")) - tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 101 _TIDB_ROWID")) - tk.MustExec("commit") - } - tk.MustExec("drop table global_temp_auto_id") - - // local temporary table with auto_increment=0 - tk.MustExec("create temporary table local_temp_auto_id(id int primary key auto_increment)") - // It doesn't matter to report an error since `show next_row_id` is an extended syntax. - err := tk.QueryToErr("show table local_temp_auto_id next_row_id") - require.EqualError(t, err, "[schema:1146]Table 'test.local_temp_auto_id' doesn't exist") - tk.MustExec("insert into local_temp_auto_id value(null)") - tk.MustQuery("select @@last_insert_id").Check(testkit.Rows("1")) - tk.MustQuery("select id from local_temp_auto_id").Check(testkit.Rows("1")) - tk.MustExec("drop table local_temp_auto_id") - - // local temporary table with auto_increment=100 - tk.MustExec("create temporary table local_temp_auto_id(id int primary key auto_increment) auto_increment=100") - tk.MustQuery("show create table local_temp_auto_id").Check(testkit.Rows("local_temp_auto_id CREATE TEMPORARY TABLE `local_temp_auto_id` (\n" + - " `id` int(11) NOT NULL AUTO_INCREMENT,\n" + - " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100")) - tk.MustExec("insert into local_temp_auto_id value(null)") - tk.MustQuery("select @@last_insert_id").Check(testkit.Rows("100")) - tk.MustQuery("select id from local_temp_auto_id").Check(testkit.Rows("100")) - tk.MustQuery("show create table local_temp_auto_id").Check(testkit.Rows("local_temp_auto_id CREATE TEMPORARY TABLE `local_temp_auto_id` (\n" + - " `id` int(11) NOT NULL AUTO_INCREMENT,\n" + - " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=101")) -} - func TestDDLJobErrorCount(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomainWithSchemaLease(t, dbTestLease) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/r/ddl/constraint.result b/tests/integrationtest/r/ddl/constraint.result new file mode 100644 index 0000000000000..803643e47e192 --- /dev/null +++ b/tests/integrationtest/r/ddl/constraint.result @@ -0,0 +1,792 @@ +set @@global.tidb_enable_check_constraint = 1; +drop table if exists t; +create table t(a int check(a > 0), b int, c int, check(c > 0), check (b > c)); +alter table t drop column a; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT NULL, +CONSTRAINT `t_chk_1` CHECK ((`c` > 0)), +CONSTRAINT `t_chk_2` CHECK ((`b` > `c`)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t drop column b; +Error 3959 (HY000): Check constraint 't_chk_2' uses column 'b', hence column cannot be dropped or renamed. +alter table t rename column c to c1; +Error 3959 (HY000): Check constraint 't_chk_1' uses column 'c', hence column cannot be dropped or renamed. +drop table if exists t; +create table t(a int check(a > 0), b int check(b < 10) not enforced, c int); +alter table t alter constraint t_chk_1 not enforced; +insert into t values(-1, 1, 0); +alter table t alter constraint t_chk_2 enforced; +insert into t values(-1, 11, 0); +Error 3819 (HY000): Check constraint 't_chk_2' is violated. +alter table t add check(c = 0); +insert into t values(-1, 1, 1); +Error 3819 (HY000): Check constraint 't_chk_3' is violated. +alter table t alter constraint t_chk_3 not enforced; +insert into t values(-1, 1, 0); +drop table if exists t; +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + NOW() > '2011-11-21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: now. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIMESTAMP() > '2011-11-21 01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIMESTAMP > '2011-11-21 01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp. +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + CURDATE() > '2011-11-21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: curdate. +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + CURTIME() > '23:11:21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: curtime. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_DATE() > '2011-11-21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_date. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_DATE > '2011-11-21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_date. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIME() > '01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_time. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIME > '01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_time. +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + LOCALTIME() > '23:11:21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtime. +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + LOCALTIME > '23:11:21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtime. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + LOCALTIMESTAMP() > '2011-11-21 01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + LOCALTIMESTAMP > '2011-11-21 01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + UNIX_TIMESTAMP() > '2011-11-21 01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: unix_timestamp. +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + UTC_DATE() > '2011-11-21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: utc_date. +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + UTC_TIMESTAMP() > '2011-11-21 01:02:03')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: utc_timestamp. +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + UTC_TIME() > '23:11:21')); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: utc_time. +CREATE TABLE t1 (f1 INT CHECK (f1 + CONNECTION_ID() < 929)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: connection_id. +CREATE TABLE t1 (a VARCHAR(32) CHECK (CURRENT_USER() != a)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_user. +CREATE TABLE t1 (a VARCHAR(32) CHECK (CURRENT_USER != a)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_user. +CREATE TABLE t1 (a VARCHAR(32) CHECK (SESSION_USER() != a)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: session_user. +CREATE TABLE t1 (a VARCHAR(32) CHECK (VERSION() != a)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: version. +CREATE TABLE t1 (a VARCHAR(1024), b INT CHECK (b + FOUND_ROWS() > 2000)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: found_rows. +CREATE TABLE t1 (a INT CHECK ((a + LAST_INSERT_ID()) < 929)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: last_insert_id. +CREATE TABLE t1 (a VARCHAR(32) CHECK (SYSTEM_USER() != a)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: system_user. +CREATE TABLE t1 (a VARCHAR(32) CHECK (USER() != a)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: user. +CREATE TABLE t1 (f1 FLOAT CHECK (f1 + RAND() < 929.929)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: rand. +CREATE TABLE t1 (a INT CHECK (a + ROW_COUNT() > 1000)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: row_count. +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (GET_LOCK(b,10) != 0)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: get_lock. +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (IS_FREE_LOCK(b) != 0)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: is_free_lock. +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (IS_USED_LOCK(b) != 0)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: is_used_lock. +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (RELEASE_LOCK(b) != 0)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: release_lock. +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024), CHECK (RELEASE_ALL_LOCKS() != 0)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: release_all_locks. +CREATE TABLE t1 (f1 VARCHAR(1024), f2 VARCHAR(1024) CHECK (LOAD_FILE(f2) != NULL)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: load_file. +CREATE TABLE t1 (id CHAR(40) CHECK(UUID() != id)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: uuid. +CREATE TABLE t1 (id INT CHECK(UUID_SHORT() != id)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: uuid_short. +CREATE TABLE t1 (id INT CHECK(SLEEP(id) != 0)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: sleep. +set @a = 1; +CREATE TABLE t1 (f1 int CHECK (f1 > @a)); +Error 3816 (HY000): An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable. +CREATE TABLE t1 (f1 int CHECK (f1 > @@session.tidb_mem_quota_query)); +Error 3816 (HY000): An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable. +CREATE TABLE t1 (f1 int CHECK (f1 > @@global.tidb_mem_quota_query)); +Error 3816 (HY000): An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable. +CREATE TABLE t1 (f1 int primary key auto_increment, f2 int, CHECK (f1 != f2)); +Error 3818 (HY000): Check constraint 't1_chk_1' cannot refer to an auto-increment column. +CREATE TABLE t1 (f1 INT CHECK (f1 = default(f1))); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: default. +CREATE TABLE t1 (id INT CHECK (id != (SELECT 1))); +Error 3815 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function. +CREATE TABLE t1 (a int check(a in (SELECT COALESCE(NULL, 1, 1)))); +Error 3815 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function. +drop table if exists t; +create table t1(f1 TIMESTAMP, f2 DATETIME, f3 INT, f4 VARCHAR(32), f5 FLOAT, f6 CHAR(40), f7 INT PRIMARY KEY AUTO_INCREMENT); +ALTER TABLE t1 ADD CHECK (f1 + NOW() > '2011-11-21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: now. +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIMESTAMP() > '2011-11-21 01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp. +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIMESTAMP > '2011-11-21 01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_timestamp. +ALTER TABLE t1 ADD CHECK (f2 + CURDATE() > '2011-11-21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: curdate. +ALTER TABLE t1 ADD CHECK (f2 + CURTIME() > '23:11:21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: curtime. +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_DATE() > '2011-11-21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_date. +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_DATE > '2011-11-21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_date. +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIME() > '01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_time. +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIME > '01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_time. +ALTER TABLE t1 ADD CHECK (f2 + LOCALTIME() > '23:11:21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtime. +ALTER TABLE t1 ADD CHECK (f2 + LOCALTIME > '23:11:21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtime. +ALTER TABLE t1 ADD CHECK (f1 + LOCALTIMESTAMP() > '2011-11-21 01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp. +ALTER TABLE t1 ADD CHECK (f1 + LOCALTIMESTAMP > '2011-11-21 01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: localtimestamp. +ALTER TABLE t1 ADD CHECK (f1 + UNIX_TIMESTAMP() > '2011-11-21 01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: unix_timestamp. +ALTER TABLE t1 ADD CHECK (f2 + UTC_DATE() > '2011-11-21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: utc_date. +ALTER TABLE t1 ADD CHECK (f1 + UTC_TIMESTAMP() > '2011-11-21 01:02:03'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: utc_timestamp. +ALTER TABLE t1 ADD CHECK (f2 + UTC_TIME() > '23:11:21'); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: utc_time. +ALTER TABLE t1 ADD CHECK (f3 + CONNECTION_ID() < 929); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: connection_id. +ALTER TABLE t1 ADD CHECK (CURRENT_USER() != f4); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_user. +ALTER TABLE t1 ADD CHECK (CURRENT_USER != f4); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: current_user. +ALTER TABLE t1 ADD CHECK (SESSION_USER() != f4); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: session_user. +ALTER TABLE t1 ADD CHECK (VERSION() != f4); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: version. +ALTER TABLE t1 ADD CHECK (f3 + FOUND_ROWS() > 2000); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: found_rows. +ALTER TABLE t1 ADD CHECK ((f3 + LAST_INSERT_ID()) < 929); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: last_insert_id. +ALTER TABLE t1 ADD CHECK (SYSTEM_USER() != f4); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: system_user. +ALTER TABLE t1 ADD CHECK (USER() != f4); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: user. +ALTER TABLE t1 ADD CHECK (f5 + RAND() < 929.929); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: rand. +ALTER TABLE t1 ADD CHECK (f3 + ROW_COUNT() > 1000); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: row_count. +ALTER TABLE t1 ADD CHECK (GET_LOCK(f4,10) != 0); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: get_lock. +ALTER TABLE t1 ADD CHECK (IS_FREE_LOCK(f4) != 0); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: is_free_lock. +ALTER TABLE t1 ADD CHECK (IS_USED_LOCK(f4) != 0); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: is_used_lock. +ALTER TABLE t1 ADD CHECK (RELEASE_LOCK(f4) != 0); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: release_lock. +ALTER TABLE t1 ADD CHECK (RELEASE_ALL_LOCKS() != 0); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: release_all_locks. +ALTER TABLE t1 ADD CHECK (LOAD_FILE(f4) != NULL); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: load_file. +ALTER TABLE t1 ADD CHECK(UUID() != f6); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: uuid. +ALTER TABLE t1 ADD CHECK(UUID_SHORT() != f3); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: uuid_short. +ALTER TABLE t1 ADD CHECK(SLEEP(f3) != 0); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: sleep. +set @a = 1; +ALTER TABLE t1 ADD CHECK (f3 > @a); +Error 3816 (HY000): An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable. +ALTER TABLE t1 ADD CHECK (f3 > @@session.tidb_mem_quota_query); +Error 3816 (HY000): An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable. +ALTER TABLE t1 ADD CHECK (f3 > @@global.tidb_mem_quota_query); +Error 3816 (HY000): An expression of a check constraint 't1_chk_1' cannot refer to a user or system variable. +ALTER TABLE t1 ADD CHECK (f7 != f3); +Error 3818 (HY000): Check constraint 't1_chk_1' cannot refer to an auto-increment column. +ALTER TABLE t1 ADD CHECK (f1 = default(f1)); +Error 3814 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function: default. +ALTER TABLE t1 ADD CHECK (f3 != (SELECT 1)); +Error 3815 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function. +ALTER TABLE t1 ADD check (f3 in (SELECT COALESCE(NULL, 1, 1))); +Error 3815 (HY000): An expression of a check constraint 't1_chk_1' contains disallowed function. +drop table if exists t, s; +create table t(a int check(a > 10), b int constraint bbb check(b > 5), c int, check(c < 0)); +create table s like t; +show create table s; +Table Create Table +s CREATE TABLE `s` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT NULL, +CONSTRAINT `s_chk_1` CHECK ((`c` < 0)), +CONSTRAINT `s_chk_2` CHECK ((`a` > 10)), +CONSTRAINT `s_chk_3` CHECK ((`b` > 5)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +insert into s(a) values(1); +Error 3819 (HY000): Check constraint 's_chk_2' is violated. +insert into s(b) values(2); +Error 3819 (HY000): Check constraint 's_chk_3' is violated. +insert into s(c) values(3); +Error 3819 (HY000): Check constraint 's_chk_1' is violated. +alter table s add check(a > 0); +alter table s add constraint aaa check(a > 0); +show create table s; +Table Create Table +s CREATE TABLE `s` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT NULL, +CONSTRAINT `s_chk_1` CHECK ((`c` < 0)), +CONSTRAINT `s_chk_2` CHECK ((`a` > 10)), +CONSTRAINT `s_chk_3` CHECK ((`b` > 5)), +CONSTRAINT `s_chk_4` CHECK ((`a` > 0)), +CONSTRAINT `aaa` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t; +create table t(a int check(a > 10)); +insert into t values(1),(11),(15); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +insert ignore into t values(1),(11),(15); +show warnings; +Level Code Message +Warning 3819 Check constraint 't_chk_1' is violated. +select a from t; +a +11 +15 +update ignore t set a = a-2; +show warnings; +Level Code Message +Warning 3819 Check constraint 't_chk_1' is violated. +select a from t; +a +11 +13 +drop table if exists t, s, t1, t2; +create table t(a int, b int, index(a), index(a, b)); +create table s(a int, check (a > 0), foreign key (a) references t(a) on update cascade); +Error 3823 (HY000): Column 'a' cannot be used in a check constraint 's_chk_1': needed in a foreign key constraint referential action. +create table s(a int, b int, check (a > 0), foreign key (a, b) references t(a, b) on update cascade); +Error 3823 (HY000): Column 'a' cannot be used in a check constraint 's_chk_1': needed in a foreign key constraint referential action. +create table t1(a int, foreign key (a) references t(a) on update cascade); +alter table t1 add check ( a > 0 ); +Error 3823 (HY000): Column 'a' cannot be used in a check constraint 't1_chk_1': needed in a foreign key constraint referential action. +create table t2(a int, b int, foreign key (a, b) references t(a, b) on update cascade); +alter table t2 add check ( a > 0 ); +Error 3823 (HY000): Column 'a' cannot be used in a check constraint 't2_chk_1': needed in a foreign key constraint referential action. +drop table t, t1, t2; +drop table if exists t; +create table t(a int, check(a)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(1)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check('1')); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int check(a)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(1+1)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(1/2)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(a + 1/2)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int check(a + 1/2)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(true + 1)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(abs(1))); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(length(a))); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(length(1))); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(floor(1.1))); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(mod(3, 2))); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check('true')); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_1'. +create table t(a int, check(true)); +alter table t add check(a); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(1); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check('1'); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(1/2); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(a + 1/2); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(true + 1); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(abs(1)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(length(a)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(length(1)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(length(1)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check(mod(3, 2)); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +alter table t add check('true'); +Error 3812 (HY000): An expression of non-boolean type specified to a check constraint 't_chk_2'. +drop table if exists t; +create table t(a int); +alter table t add check(b > 0); +Error 1054 (42S22): Unknown column 'b' in 'check constraint t_chk_1 expression' +drop table if exists t; +create table t(a json, b varchar(20)); +alter table t add check (JSON_VALID(a)); +alter table t add check (REGEXP_LIKE(b,'@')); +drop table if exists t; +create table t(a int constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +drop table t; +create table t(a int, constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +drop table t; +create table t(a int constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +create table t(a int, constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int check(a > 0)); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_chk_1' is too long +create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int, check(a > 0)); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_chk_1' is too long +create table t(a int); +alter table t add constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +alter table t add constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0); +drop table t; +create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int); +alter table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa add check(a > 0); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_chk_1' is too long +drop table if exists t; +create table t(a int); +alter table t add constraint `cafe` check(a > 0); +alter table t add constraint `CAFE` check(a > 0); +Error 3822 (HY000): Duplicate check constraint name 'cafe'. +alter table t add constraint `café` check(a > 0); +drop table if exists t, s; +create table t(a int check(a > 0)); +insert into t values(1); +create table s(a int); +insert into s values(-1); +insert into t values(-1); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +insert into t values(1); +insert into t(a) values(-1); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +insert into t(a) values(1); +insert into t set a = -1; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +insert into t set a = 1; +insert into t(a) select -1; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +insert into t(a) select 1; +insert into t(a) select a from s; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +insert into t(a) select a + 2 from s; +update t set a = -1; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +update t set a = 1; +update t set a = a-1; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +update t set a = a+1; +update t set a = -1 where a > 0; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +update t set a = 1 where a > 0; +update t set a = (select a from s where a < 0) where a > 0; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +update t set a = (select a + 2 from s where a < 0) where a > 0; +update t as a, s as b set a.a=b.a; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +update t as a, s as b set a.a=b.a + 2; +replace into t(a) values(-1); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +replace into t(a) values(1); +replace into t(a) select -1; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +replace into t(a) select 1; +replace into t set a = -1; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +replace into t set a = 1; +drop table if exists t; +create table t( a int, b int as (a+1), CHECK (b > 0)); +insert into t(a) values(0); +insert into t(a) values(-2); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, + `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL, +CONSTRAINT `t_chk_1` CHECK ((`b` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t alter constraint t_chk_1 not enforced; +insert into t(a) values(-2); +alter table t drop constraint t_chk_1; +drop table t; +create table t(a int, b int as (a+1)); +alter table t add check(b > 0); +insert into t(a) values(0); +insert into t(a) values(-2); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +alter table t alter constraint t_chk_1 not enforced; +insert into t(a) values(-2); +alter table t drop constraint t_chk_1; +alter table t add check(b > 0); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +drop table if exists t; +create table t(a int, CHECK (a < -999)); +drop temporary table if exists t; +create temporary table t(a int, CHECK (a > 0)); +insert into t(a) values(1); +insert into t(a) values(-2); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +drop temporary table t; +create temporary table t(a int, CHECK (a > 0) not enforced); +insert into t values(-1); +create global temporary table tt(a int, check(a > 0)) on commit delete rows; +insert into tt(a) values(1); +insert into tt(a) values(-2); +Error 3819 (HY000): Check constraint 'tt_chk_1' is violated. +alter table tt alter constraint tt_chk_1 not enforced; +insert into tt(a) values(-2); +alter table tt drop constraint tt_chk_1; +drop temporary table t; +drop global temporary table tt; +drop table if exists t; +create table t(a int CHECK (a != 0)); +prepare stmt from 'insert into t values(?)'; +set @a = 1; +execute stmt using @a; + +set @a = 0; +execute stmt using @a; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +deallocate prepare stmt; +drop table if exists t, s; +create table t(a int primary key, b int, check (b > 0)); +insert into t values(1, 1); +insert into t values(1, -10) on duplicate key update b = -1; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +insert ignore into t values(1, -10) on duplicate key update b = -1; +select * from t; +a b +1 1 +create table s(a int primary key, check (a > 0)); +insert into s values(1); +insert into s values(1) on duplicate key update a = -1; +Error 3819 (HY000): Check constraint 's_chk_1' is violated. +insert ignore into s values(1) on duplicate key update a = -1; +select * from s; +a +1 +drop table if exists t1, t2; +CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0)); +insert into t1 values (2, 2); +Error 3819 (HY000): Check constraint 't1_chk_1' is violated. +insert into t1 values (9, 2); +Error 3819 (HY000): Check constraint 't1_chk_2' is violated. +insert into t1 values (14, -4); +Error 3819 (HY000): Check constraint 'c2_positive' is violated. +insert into t1(c1) values (9); +Error 3819 (HY000): Check constraint 't1_chk_2' is violated. +insert into t1(c2) values (-3); +Error 3819 (HY000): Check constraint 'c2_positive' is violated. +insert into t1 values (14, 4); +insert into t1 values (null, 4); +insert into t1 values (13, null); +insert into t1 values (null, null); +insert into t1(c1) values (null); +insert into t1(c2) values (null); +CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15)); +insert into t2(c1, c2) values (11, 1); +Error 3819 (HY000): Check constraint 't2_chk_3' is violated. +insert into t2(c1, c2) values (12, 7); +drop table if exists t1, t2; +CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0)); +insert into t1 values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +update t1 set c2 = -c2; +Error 3819 (HY000): Check constraint 'c2_positive' is violated. +update t1 set c2 = c1; +Error 3819 (HY000): Check constraint 't1_chk_1' is violated. +update t1 set c1 = c1 - 10; +Error 3819 (HY000): Check constraint 't1_chk_2' is violated. +update t1 set c2 = -10 where c2 = 12; +Error 3819 (HY000): Check constraint 'c2_positive' is violated. +CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15)); +insert into t2(c1, c2) values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +update t2 set c2 = c2 - 10; +Error 3819 (HY000): Check constraint 't2_chk_3' is violated. +update t2 set c2 = c2 - 5; +drop table if exists t1, t2; +CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0)) partition by hash(c2) partitions 5; +insert into t1 values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +update t1 set c2 = -c2; +Error 3819 (HY000): Check constraint 'c2_positive' is violated. +update t1 set c2 = c1; +Error 3819 (HY000): Check constraint 't1_chk_1' is violated. +update t1 set c1 = c1 - 10; +Error 3819 (HY000): Check constraint 't1_chk_2' is violated. +update t1 set c2 = -10 where c2 = 12; +Error 3819 (HY000): Check constraint 'c2_positive' is violated. +CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15)) partition by hash(c2) partitions 5; +insert into t2(c1, c2) values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +update t2 set c2 = c2 - 10; +Error 3819 (HY000): Check constraint 't2_chk_3' is violated. +update t2 set c2 = c2 - 5; +drop table if exists t; +create table t(a int check (a>1), b int, constraint my_constr check(a<10)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `my_constr` CHECK ((`a` < 10)), +CONSTRAINT `t_chk_1` CHECK ((`a` > 1)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t add constraint my_constr2 check (a 1)), +CONSTRAINT `my_constr2` CHECK ((`a` < `b`)) /*!80016 NOT ENFORCED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t drop constraint t_chk_1; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `my_constr` CHECK ((`a` < 10)), +CONSTRAINT `my_constr2` CHECK ((`a` < `b`)) /*!80016 NOT ENFORCED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t; +DROP TABLE IF EXISTS t0, t1, t2; +CREATE TABLE t0(c1 NUMERIC CHECK(true)); +CREATE TABLE t1(c1 NUMERIC, CHECK(true)); +CREATE TABLE t2(c1 NUMERIC); +ALTER TABLE t2 ADD CONSTRAINT CHECK(true); +DROP TABLE IF EXISTS t0, t1, t2; +CREATE TABLE t0(c1 NUMERIC CHECK(false)); +CREATE TABLE t1(c1 NUMERIC, CHECK(false)); +CREATE TABLE t2(c1 NUMERIC); +ALTER TABLE t2 ADD CONSTRAINT CHECK(false); +create table t(a int check(a > 0)); +show warnings; +Level Code Message +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +set @@global.tidb_enable_check_constraint = 1; +create table t(a int check(a > 0)); +show warnings; +Level Code Message +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t add constraint chk check(true); +show warnings; +Level Code Message +alter table t alter constraint chk not enforced; +show warnings; +Level Code Message +alter table t drop constraint chk; +show warnings; +Level Code Message +set @@global.tidb_enable_check_constraint = 0; +alter table t drop constraint t_chk_1; +show warnings; +Level Code Message +Warning 1105 the switch of check constraint is off +alter table t alter constraint t_chk_1 not enforced; +show warnings; +Level Code Message +Warning 1105 the switch of check constraint is off +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +set @@global.tidb_enable_check_constraint = 1; +drop table if exists t; +create table t(a int not null check(a>0)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +create table t(a bigint key constraint my_constr check(a<10), b int constraint check(b > 1) not enforced); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` bigint(20) NOT NULL, + `b` int(11) DEFAULT NULL, + PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */, +CONSTRAINT `my_constr` CHECK ((`a` < 10)), +CONSTRAINT `t_chk_1` CHECK ((`b` > 1)) /*!80016 NOT ENFORCED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +create table t(a int constraint check(a > 1) not enforced, constraint my_constr check(a < 10)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, +CONSTRAINT `my_constr` CHECK ((`a` < 10)), +CONSTRAINT `t_chk_1` CHECK ((`a` > 1)) /*!80016 NOT ENFORCED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +create table t(a int not null check(b>0)); +Error 3813 (HY000): Column check constraint 't_chk_1' references other column. +create table t(a int not null check(b>a)); +Error 3813 (HY000): Column check constraint 't_chk_1' references other column. +create table t(a int not null check(a>0), b int, constraint check(c>b)); +Error 3820 (HY000): Check constraint 't_chk_1' refers to non-existing column 'c'. +create table t(a int not null check(a>0), b int, constraint check(a>b)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > `b`)), +CONSTRAINT `t_chk_2` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +create table t(a int not null check(a > '12345')); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > _utf8mb4'12345')) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +create table t(a int not null primary key check(a > '12345')); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, + PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */, +CONSTRAINT `t_chk_1` CHECK ((`a` > _utf8mb4'12345')) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +create table t(a varchar(10) not null primary key check(a > '12345')); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` varchar(10) NOT NULL, + PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */, +CONSTRAINT `t_chk_1` CHECK ((`a` > _utf8mb4'12345')) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +drop table if exists t; +create table t(a int not null check(a>0)); +alter table t add constraint haha check(a<10); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)), +CONSTRAINT `haha` CHECK ((`a` < 10)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t add constraint check(a<11) not enforced; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)), +CONSTRAINT `haha` CHECK ((`a` < 10)), +CONSTRAINT `t_chk_2` CHECK ((`a` < 11)) /*!80016 NOT ENFORCED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t add constraint haha check(a); +Error 3822 (HY000): Duplicate check constraint name 'haha'. +alter table t add constraint check(b); +Error 1054 (42S22): Unknown column 'b' in 'check constraint t_chk_3 expression' +alter table t add constraint check(a*2 < a+1) not enforced; +drop table t; +create table t(a int); +insert into t values(1), (2), (3); +alter table t add constraint check(a < 2); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +alter table t add constraint check(a < 2) not enforced; +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +drop table if exists t; +set @@global.tidb_enable_check_constraint = 1; +create table t(a int not null check(a>0), b int, constraint haha check(a < b), check(a 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t drop constraint not_exist_constraint; +Error 3940 (HY000): Constraint 'not_exist_constraint' does not exist. +alter table t drop constraint haha; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` < `b` + 1)), +CONSTRAINT `t_chk_2` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t drop constraint t_chk_2; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `t_chk_1` CHECK ((`a` < `b` + 1)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table t; +create table t(a int check(a > 0)); +insert into t values(0); +Error 3819 (HY000): Check constraint 't_chk_1' is violated. +alter table t drop constraint t_chk_1; +insert into t values(0); +drop table if exists t; +set @@global.tidb_enable_check_constraint = 1; +create table t(a int not null check(a>0) not enforced, b int, constraint haha check(a < b)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `haha` CHECK ((`a` < `b`)), +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)) /*!80016 NOT ENFORCED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t alter constraint unknown not enforced; +Error 3940 (HY000): Constraint 'unknown' does not exist. +alter table t alter constraint haha not enforced; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `haha` CHECK ((`a` < `b`)) /*!80016 NOT ENFORCED */, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)) /*!80016 NOT ENFORCED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t alter constraint t_chk_1 enforced; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL, +CONSTRAINT `haha` CHECK ((`a` < `b`)) /*!80016 NOT ENFORCED */, +CONSTRAINT `t_chk_1` CHECK ((`a` > 0)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +set @@global.tidb_enable_check_constraint = 0; diff --git a/tests/integrationtest/r/ddl/db.result b/tests/integrationtest/r/ddl/db.result new file mode 100644 index 0000000000000..7ce83eb0c138b --- /dev/null +++ b/tests/integrationtest/r/ddl/db.result @@ -0,0 +1,434 @@ +drop table if exists t; +create table t(a char(250) default null); +insert into t values(); +alter table t modify a char not null; +Error 1265 (01000): Data truncated for column 'a' at row 1 +drop table if exists t; +drop table if exists t; +create table t(a text(100)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` text DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t add b text(100); +alter table t add c text; +alter table t add d text(50); +alter table t change column a a text(50); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` tinytext DEFAULT NULL, + `b` text DEFAULT NULL, + `c` text DEFAULT NULL, + `d` tinytext DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +alter table t change column d d text(100); +alter table t change column c c text(30000); +alter table t change column b b text(10000000); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` tinytext DEFAULT NULL, + `b` longtext DEFAULT NULL, + `c` mediumtext DEFAULT NULL, + `d` text DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t; +drop table if exists i30328_1, i30328_2; +create table i30328_1(a varbinary(70000), b varchar(70000000)); +Error 1074 (42000): Column length too big for column 'a' (max = 65535); use BLOB or TEXT instead +select @@sql_mode; +@@sql_mode +ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION +set @@sql_mode='NO_ENGINE_SUBSTITUTION'; +create table i30328_1(a varbinary(70000), b varchar(70000000)); +show warnings; +Level Code Message +Warning 1246 Converting column 'a' from VARBINARY to BLOB +Warning 1246 Converting column 'b' from VARCHAR to TEXT +create table i30328_2(a varchar(200)); +alter table i30328_2 modify a varchar(70000000); +show warnings; +Level Code Message +Warning 1246 Converting column 'a' from VARCHAR to TEXT +set @@sql_mode= default; +drop table if exists i30328_1; +drop table if exists i30328_2; +drop database if exists 库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库; +create database 库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库; +use 库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库; +create table 表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表(f1 int primary key,f2 int, 三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三 varchar(50)); +create index 索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索 on 表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表(三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三三); +alter table 表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表 change f2 二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二 int; +drop index 索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索索 on 表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表; +drop table 表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表表; +drop database 库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库库; +use ddl__db; +drop table if exists test_add_index_after_add_col; +create table test_add_index_after_add_col(a int, b int not null default '0'); +insert into test_add_index_after_add_col values(1, 2),(2,2); +alter table test_add_index_after_add_col add column c int not null default '0'; +alter table test_add_index_after_add_col add unique index cc(c); +Error 1062 (23000): Duplicate entry '0' for key 'test_add_index_after_add_col.cc' +drop table if exists employ, issue9100t1, issue9100t2; +create table employ (a int, b int) partition by range (b) (partition p0 values less than (1)); +alter table employ add unique index p_a (a); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +alter table employ add primary key p_a (a); +Error 1503 (HY000): A PRIMARY must include all columns in the table's partitioning function +create table issue9100t1 (col1 int not null, col2 date not null, col3 int not null, unique key (col1, col2)) partition by range( col1 ) (partition p1 values less than (11)); +alter table issue9100t1 add unique index p_col1 (col1); +alter table issue9100t1 add primary key p_col1 (col1); +create table issue9100t2 (col1 int not null, col2 date not null, col3 int not null, unique key (col1, col3)) partition by range( col1 + col3 ) (partition p1 values less than (11)); +alter table issue9100t2 add unique index p_col1 (col1); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +alter table issue9100t2 add primary key p_col1 (col1); +Error 1503 (HY000): A PRIMARY must include all columns in the table's partitioning function +set @@session.tidb_enable_list_partition = ON; +set @@session.tidb_enable_exchange_partition = 1; +drop table if exists t1; +drop table if exists t2; +create table t1(id char(10)) partition by list columns(id) (partition p0 values in ('a'), partition p1 values in ('b')); +insert into t1 VALUES('a'); +create table t2(id char(10)); +ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; +select * from t2; +id +a +select * from t1; +id +drop table if exists t1; +drop table if exists t2; +create table t1 (id int) partition by list (id) (partition p0 values in (1,2,3), partition p1 values in (4,5,6)); +insert into t1 VALUES(1); +insert into t1 VALUES(2); +insert into t1 VALUES(3); +create table t2(id int); +ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; +select * from t2; +id +1 +2 +3 +select * from t1; +id +set @@session.tidb_enable_exchange_partition = default; +set @@session.tidb_enable_list_partition = default; +drop table if exists ob; +create table ob (pk int primary key, c int default 1, c1 int default 1, KEY cl(c1)); +alter table ob order by c; +show warnings; +Level Code Message +Warning 1105 ORDER BY ignored as there is a user-defined clustered index in the table 'ob' +drop table if exists ob; +create table ob (c int default 1, c1 int default 1, KEY cl(c1)); +alter table ob order by c; +show warnings; +Level Code Message +drop table if exists ob; +drop table if exists t1, t2, t3, t4, t5, t6; +create table t1 (a int primary key); +create table t2 (a int, b int as (a+1) virtual, foreign key (b) references t1(a)); +Error 3733 (HY000): Foreign key 'fk_1' uses virtual column 'b' which is not supported. +create table t2 (a int, b int generated always as (a+1) virtual); +alter table t2 add foreign key (b) references t1(a); +Error 3733 (HY000): Foreign key 'fk_1' uses virtual column 'b' which is not supported. +drop table t1, t2; +create table t2 (a int primary key); +create table t1 (a int, b int as (a+1) stored, foreign key (b) references t2(a)); +create table t3 (a int, b int generated always as (a+1) stored); +alter table t3 add foreign key (b) references t2(a); +drop table t1, t2, t3; +create table t1 (a int, b int generated always as (a+1) stored primary key); +create table t2 (a int, foreign key (a) references t1(b)); +create table t3 (a int); +alter table t3 add foreign key (a) references t1(b); +drop table t1, t2, t3; +create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set null); +Error 3104 (HY000): Cannot define foreign key with ON UPDATE SET NULL clause on a generated column. +create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update cascade); +Error 3104 (HY000): Cannot define foreign key with ON UPDATE CASCADE clause on a generated column. +create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set default); +Error 3104 (HY000): Cannot define foreign key with ON UPDATE SET DEFAULT clause on a generated column. +create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on delete set null); +Error 3104 (HY000): Cannot define foreign key with ON DELETE SET NULL clause on a generated column. +create table t1 (a int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on delete set default); +Error 3104 (HY000): Cannot define foreign key with ON DELETE SET DEFAULT clause on a generated column. +create table t2 (a int primary key); +create table t1 (a int, b int generated always as (a+1) stored); +alter table t1 add foreign key (b) references t2(a) on update set null; +Error 3104 (HY000): Cannot define foreign key with ON UPDATE SET NULL clause on a generated column. +alter table t1 add foreign key (b) references t2(a) on update cascade; +Error 3104 (HY000): Cannot define foreign key with ON UPDATE CASCADE clause on a generated column. +alter table t1 add foreign key (b) references t2(a) on update set default; +Error 3104 (HY000): Cannot define foreign key with ON UPDATE SET DEFAULT clause on a generated column. +alter table t1 add foreign key (b) references t2(a) on delete set null; +Error 3104 (HY000): Cannot define foreign key with ON DELETE SET NULL clause on a generated column. +alter table t1 add foreign key (b) references t2(a) on delete set default; +Error 3104 (HY000): Cannot define foreign key with ON DELETE SET DEFAULT clause on a generated column. +drop table t1, t2; +create table t1 (A int, b int generated always as (a+1) stored, foreign key (b) references t2(a) on update set null); +Error 3104 (HY000): Cannot define foreign key with ON UPDATE SET NULL clause on a generated column. +create table t2 (a int primary key); +create table t1 (A int, b int generated always as (a+1) stored); +alter table t1 add foreign key (b) references t2(a) on update set null; +Error 3104 (HY000): Cannot define foreign key with ON UPDATE SET NULL clause on a generated column. +drop table t1, t2; +create table t1 (a int, b int generated always as (a+1) stored); +alter table t1 add foreign key (b) references t2(a) on update set null; +Error 3104 (HY000): Cannot define foreign key with ON UPDATE SET NULL clause on a generated column. +drop table t1; +create table t1 (a int primary key, b char(5)); +create table t2 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on update restrict); +create table t3 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on update no action); +create table t4 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on delete restrict); +create table t5 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on delete cascade); +create table t6 (a int, b int generated always as (a % 10) stored, foreign key (b) references t1(a) on delete no action); +drop table t2,t3,t4,t5,t6; +create table t2 (a int, b int generated always as (a % 10) stored); +alter table t2 add foreign key (b) references t1(a) on update restrict; +create table t3 (a int, b int generated always as (a % 10) stored); +alter table t3 add foreign key (b) references t1(a) on update no action; +create table t4 (a int, b int generated always as (a % 10) stored); +alter table t4 add foreign key (b) references t1(a) on delete restrict; +create table t5 (a int, b int generated always as (a % 10) stored); +alter table t5 add foreign key (b) references t1(a) on delete cascade; +create table t6 (a int, b int generated always as (a % 10) stored); +alter table t6 add foreign key (b) references t1(a) on delete no action; +drop table t1,t2,t3,t4,t5,t6; +create table t2 (a int primary key); +create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on update set null); +Error 1215 (HY000): Cannot add foreign key constraint +create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on update cascade); +Error 1215 (HY000): Cannot add foreign key constraint +create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on update set default); +Error 1215 (HY000): Cannot add foreign key constraint +create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on delete set null); +Error 1215 (HY000): Cannot add foreign key constraint +create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on delete cascade); +Error 1215 (HY000): Cannot add foreign key constraint +create table t1 (a int, b int generated always as (a+1) stored, foreign key (a) references t2(a) on delete set default); +Error 1215 (HY000): Cannot add foreign key constraint +create table t1 (a int, b int generated always as (a+1) stored); +alter table t1 add foreign key (a) references t2(a) on update set null; +Error 1215 (HY000): Cannot add foreign key constraint +alter table t1 add foreign key (a) references t2(a) on update cascade; +Error 1215 (HY000): Cannot add foreign key constraint +alter table t1 add foreign key (a) references t2(a) on update set default; +Error 1215 (HY000): Cannot add foreign key constraint +alter table t1 add foreign key (a) references t2(a) on delete set null; +Error 1215 (HY000): Cannot add foreign key constraint +alter table t1 add foreign key (a) references t2(a) on delete cascade; +Error 1215 (HY000): Cannot add foreign key constraint +alter table t1 add foreign key (a) references t2(a) on delete set default; +Error 1215 (HY000): Cannot add foreign key constraint +drop table t1, t2; +create table t1 (a int primary key, b char(5)); +create table t2 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on update restrict); +create table t3 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on update no action); +create table t4 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on delete restrict); +create table t5 (a int, b int generated always as (a % 10) stored, foreign key (a) references t1(a) on delete no action); +drop table t2,t3,t4,t5; +create table t2 (a int, b int generated always as (a % 10) stored); +alter table t2 add foreign key (a) references t1(a) on update restrict; +create table t3 (a int, b int generated always as (a % 10) stored); +alter table t3 add foreign key (a) references t1(a) on update no action; +create table t4 (a int, b int generated always as (a % 10) stored); +alter table t4 add foreign key (a) references t1(a) on delete restrict; +create table t5 (a int, b int generated always as (a % 10) stored); +alter table t5 add foreign key (a) references t1(a) on delete no action; +drop table t1,t2,t3,t4,t5; +drop database if exists test_db2; +create database test_db2; +drop table if exists t; +create table t(a int); +use test_db2; +create sql security invoker view v as select * from ddl__db.t; +select test_db2.v.a from test_db2.v; +a +drop database test_db2; +use ddl__db; +drop table if exists ct, ct1; +DROP TABLE IF EXISTS t; +CREATE TABLE t (c integer) COMMENT = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'; +show warnings; +Level Code Message +Warning 1688 Comment for index 'e' is too long (max = 1024) +set sql_mode=default; +drop table if exists ct, ct1; +drop table if exists shard_row_id_temporary; +create global temporary table shard_row_id_temporary (a int) shard_row_id_bits = 5 on commit delete rows; +Error 8006 (HY000): `shard_row_id_bits` is unsupported on temporary tables. +create global temporary table shard_row_id_temporary (a int) on commit delete rows; +alter table shard_row_id_temporary shard_row_id_bits = 4; +Error 8006 (HY000): `shard_row_id_bits` is unsupported on temporary tables. +drop table if exists local_shard_row_id_temporary; +create temporary table local_shard_row_id_temporary (a int) shard_row_id_bits = 5; +Error 8006 (HY000): `shard_row_id_bits` is unsupported on temporary tables. +create temporary table local_shard_row_id_temporary (a int); +alter table local_shard_row_id_temporary shard_row_id_bits = 4; +Error 8200 (HY000): TiDB doesn't support ALTER TABLE for local temporary table +drop table if exists global_temp_auto_id; +create global temporary table global_temp_auto_id(id int primary key auto_increment) on commit delete rows; +begin; +show table global_temp_auto_id next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +ddl__db global_temp_auto_id id 1 _TIDB_ROWID +insert into global_temp_auto_id value(null); +select @@last_insert_id; +@@last_insert_id +1 +select id from global_temp_auto_id; +id +1 +show table global_temp_auto_id next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +ddl__db global_temp_auto_id id 2 _TIDB_ROWID +commit; +drop table global_temp_auto_id; +create global temporary table global_temp_auto_id(id int primary key auto_increment) auto_increment=100 on commit delete rows; +show create table global_temp_auto_id; +Table Create Table +global_temp_auto_id CREATE GLOBAL TEMPORARY TABLE `global_temp_auto_id` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100 ON COMMIT DELETE ROWS +show table global_temp_auto_id next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +ddl__db global_temp_auto_id id 100 _TIDB_ROWID +begin; +insert into global_temp_auto_id value(null); +select @@last_insert_id; +@@last_insert_id +100 +select id from global_temp_auto_id; +id +100 +show table global_temp_auto_id next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +ddl__db global_temp_auto_id id 101 _TIDB_ROWID +commit; +show create table global_temp_auto_id; +Table Create Table +global_temp_auto_id CREATE GLOBAL TEMPORARY TABLE `global_temp_auto_id` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100 ON COMMIT DELETE ROWS +show table global_temp_auto_id next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +ddl__db global_temp_auto_id id 100 _TIDB_ROWID +begin; +insert into global_temp_auto_id value(null); +select @@last_insert_id; +@@last_insert_id +100 +select id from global_temp_auto_id; +id +100 +show table global_temp_auto_id next_row_id; +DB_NAME TABLE_NAME COLUMN_NAME NEXT_GLOBAL_ROW_ID ID_TYPE +ddl__db global_temp_auto_id id 101 _TIDB_ROWID +commit; +drop table global_temp_auto_id; +create temporary table local_temp_auto_id(id int primary key auto_increment); +show table local_temp_auto_id next_row_id; +Error 1146 (42S02): Table 'ddl__db.local_temp_auto_id' doesn't exist +insert into local_temp_auto_id value(null); +select @@last_insert_id; +@@last_insert_id +1 +select id from local_temp_auto_id; +id +1 +drop table local_temp_auto_id; +create temporary table local_temp_auto_id(id int primary key auto_increment) auto_increment=100; +show create table local_temp_auto_id; +Table Create Table +local_temp_auto_id CREATE TEMPORARY TABLE `local_temp_auto_id` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100 +insert into local_temp_auto_id value(null); +select @@last_insert_id; +@@last_insert_id +100 +select id from local_temp_auto_id; +id +100 +show create table local_temp_auto_id; +Table Create Table +local_temp_auto_id CREATE TEMPORARY TABLE `local_temp_auto_id` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=101 diff --git a/tests/integrationtest/r/ddl/db_cache.result b/tests/integrationtest/r/ddl/db_cache.result new file mode 100644 index 0000000000000..b4250370f852f --- /dev/null +++ b/tests/integrationtest/r/ddl/db_cache.result @@ -0,0 +1,82 @@ +drop table if exists cache_partition_table; +create table cache_partition_table (a int, b int) partition by hash(a) partitions 3; +alter table cache_partition_table cache; +Error 8242 (HY000): 'partition mode' is unsupported on cache tables. +drop table if exists cache_partition_range_table; +create table cache_partition_range_table (c1 smallint(6) not null, c2 char(5) default null) partition by range ( c1 ) ( +partition p0 values less than (10), +partition p1 values less than (20), +partition p2 values less than (30), +partition p3 values less than (MAXVALUE) +); +alter table cache_partition_range_table cache; +Error 8242 (HY000): 'partition mode' is unsupported on cache tables. +drop table if exists partition_list_table; +set @@session.tidb_enable_list_partition = ON; +create table cache_partition_list_table (id int) partition by list (id) ( +partition p0 values in (1,2), +partition p1 values in (3,4), +partition p3 values in (5,null) +); +alter table cache_partition_list_table cache; +Error 8242 (HY000): 'partition mode' is unsupported on cache tables. +drop table if exists cache_partition_list_table; +drop table if exists cache_partition_range_table; +drop table if exists cache_partition_table; +set @@session.tidb_enable_list_partition = default; +drop table if exists cache_view_t; +create table cache_view_t (id int); +create view v as select * from cache_view_t; +alter table v cache; +Error 1347 (HY000): 'ddl__db_cache.v' is not BASE TABLE +drop view v; +drop table if exists nocache_t1; +create table nocache_t1 ( n int auto_increment primary key); +alter table nocache_t1 cache; +show create table nocache_t1; +Table Create Table +nocache_t1 CREATE TABLE `nocache_t1` ( + `n` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`n`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /* CACHED ON */ +alter table nocache_t1 nocache; +show create table nocache_t1; +Table Create Table +nocache_t1 CREATE TABLE `nocache_t1` ( + `n` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`n`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t1; +drop table if exists nocache_t; +alter table nocache_t cache; +Error 1146 (42S02): Table 'ddl__db_cache.nocache_t' doesn't exist +create table nocache_t (a int); +alter table nocache_t nocache; +alter table nocache_t nocache; +alter table nocache_t nocache; +drop table if exists cache_index; +create table cache_index (c1 int primary key, c2 int, c3 int, index ok2(c2)); +alter table cache_index cache; +create index cache_c2 on cache_index(c2); +Error 8242 (HY000): 'Create Index' is unsupported on cache tables. +alter table cache_index add index k2(c2); +Error 8242 (HY000): 'Alter Table' is unsupported on cache tables. +alter table cache_index drop index ok2; +Error 8242 (HY000): 'Alter Table' is unsupported on cache tables. +alter table cache_index rename index ok2 to ok; +Error 8242 (HY000): 'Alter Table' is unsupported on cache tables. +drop table if exists cache_index_1; +create table cache_index_1 (id int, c1 int, c2 int, primary key(id), key i1(c1), key i2(c2)); +alter table cache_index_1 cache; +alter table cache_index_1 drop index i1, drop index i2; +Error 8242 (HY000): 'Alter Table' is unsupported on cache tables. +alter table cache_index_1 nocache; +alter table cache_index nocache; +drop table if exists cache_index; +drop table if exists cache_t2; +create table cache_t2 (c1 int); +alter table cache_t2 cache; +alter table cache_t2 nocache; +alter table cache_t2 cache; +show warnings; +Level Code Message diff --git a/tests/integrationtest/r/ddl/db_change.result b/tests/integrationtest/r/ddl/db_change.result new file mode 100644 index 0000000000000..7c170cb56bfc3 --- /dev/null +++ b/tests/integrationtest/r/ddl/db_change.result @@ -0,0 +1,35 @@ +drop database if exists ddl__db_change2; +create database ddl__db_change2 default charset utf8 default collate utf8_bin; +use ddl__db_change2; +create table t ( +c1 varchar(64), +c2 enum('N','Y') not null default 'N', +c3 timestamp on update current_timestamp, +c4 int primary key, +unique key idx2 (c2, c3)); +insert into t values('a', 'N', '2017-07-01', 8); +drop stats t; +insert into t values('a', 'A', '2018-09-19', 9); +Error 1265 (01000): Data truncated for column 'c2' at row 1 +alter table t change c2 c2 enum('N') DEFAULT 'N'; +alter table t change c2 c2 int default 0; +alter table t change c2 c2 enum('N','Y','A') DEFAULT 'A'; +insert into t values('a', 'A', '2018-09-20', 10); +insert into t (c1, c3, c4) values('a', '2018-09-21', 11); +select c4, c2 from t order by c4 asc; +c4 c2 +8 N +10 A +11 A +update t set c2='N' where c4 = 10; +select c2 from t where c4 = 10; +c2 +N +drop database ddl__db_change2; +use ddl__db_change; +drop table if exists t; +create table t(a int, b int, index idx((a+b))); +alter table t rename column b to b2; +Error 3837 (HY000): Column 'b' has an expression index dependency and cannot be dropped or renamed +alter table t drop column b; +Error 3837 (HY000): Column 'b' has an expression index dependency and cannot be dropped or renamed diff --git a/tests/integrationtest/r/ddl/db_foreign_key.result b/tests/integrationtest/r/ddl/db_foreign_key.result new file mode 100644 index 0000000000000..64d81969eb05d --- /dev/null +++ b/tests/integrationtest/r/ddl/db_foreign_key.result @@ -0,0 +1,28 @@ +drop table if exists t, t1; +create table t(id int key); +create table t1(id int, id_fk int, CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`), CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`)); +Error 1826 (HY000): Duplicate foreign key constraint name 'fk_aaa' +create table t1(id int, id_fk int, CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`), CONSTRAINT `fk_aaA` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`)); +Error 1826 (HY000): Duplicate foreign key constraint name 'fk_aaA' +create table t1(id int, id_fk int, CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`)); +alter table t1 add CONSTRAINT `fk_aaa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`); +Error 1826 (HY000): Duplicate foreign key constraint name 'fk_aaa' +alter table t1 add CONSTRAINT `fk_aAa` FOREIGN KEY (`id_fk`) REFERENCES `t` (`id`); +Error 1826 (HY000): Duplicate foreign key constraint name 'fk_aAa' +drop table if exists t, t1; +drop table if exists t1; +create table t1 (a int, b int); +drop table if exists t1_tmp; +create global temporary table t1_tmp (a int, b int) on commit delete rows; +create temporary table t2_tmp (a int, b int); +drop table if exists t2; +create table t2 (a int, b int); +alter table t1_tmp add foreign key (c) REFERENCES t2(a); +Error 1215 (HY000): Cannot add foreign key constraint +alter table t2_tmp add foreign key (c) REFERENCES t2(a); +Error 8200 (HY000): TiDB doesn't support ALTER TABLE for local temporary table +create global temporary table t3 (c int,d int,foreign key (d) references t1 (b)) on commit delete rows; +Error 1215 (HY000): Cannot add foreign key constraint +create temporary table t4(c int,d int,foreign key (d) references t1 (b)); +Error 1215 (HY000): Cannot add foreign key constraint +drop table if exists t1,t2,t3,t4,t1_tmp,t2_tmp; diff --git a/tests/integrationtest/r/ddl/db_integration.result b/tests/integrationtest/r/ddl/db_integration.result new file mode 100644 index 0000000000000..515bb8774d5a6 --- /dev/null +++ b/tests/integrationtest/r/ddl/db_integration.result @@ -0,0 +1,1218 @@ +drop table if exists test_zero_date; +set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'; +create table test_zero_date(agent_start_time date NOT NULL DEFAULT '0000-00-00'); +Error 1067 (42000): Invalid default value for 'agent_start_time' +create table test_zero_date(agent_start_time datetime NOT NULL DEFAULT '0000-00-00 00:00:00'); +Error 1067 (42000): Invalid default value for 'agent_start_time' +create table test_zero_date(agent_start_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'); +Error 1067 (42000): Invalid default value for 'agent_start_time' +create table test_zero_date(a timestamp default '0000-00-00 00'); +Error 1067 (42000): Invalid default value for 'a' +create table test_zero_date(a timestamp default 0); +Error 1067 (42000): Invalid default value for 'a' +set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +create table test_zero_date (a timestamp default 0); +insert into test_zero_date values (0); +select a, unix_timestamp(a) from test_zero_date; +a unix_timestamp(a) +0000-00-00 00:00:00 0 +update test_zero_date set a = '2001-01-01 11:11:11' where a = 0; +replace into test_zero_date values (0); +delete from test_zero_date where a = 0; +update test_zero_date set a = 0 where a = '2001-01-01 11:11:11'; +set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +insert into test_zero_date values (0); +Error 1292 (22007): Incorrect timestamp value: '0' for column 'a' at row 1 +replace into test_zero_date values (0); +Error 1292 (22007): Incorrect timestamp value: '0' for column 'a' at row 1 +update test_zero_date set a = 0 where a = 0; +Error 1292 (22007): Incorrect timestamp value: '0' +delete from test_zero_date where a = 0; +select a, unix_timestamp(a) from test_zero_date; +a unix_timestamp(a) +drop table test_zero_date; +set session sql_mode=''; +create table test_zero_date (a timestamp default 0); +drop table test_zero_date; +create table test_zero_date (a int); +insert into test_zero_date values (0); +alter table test_zero_date modify a date; +set session sql_mode='NO_ZERO_DATE'; +drop table test_zero_date; +create table test_zero_date (a timestamp default 0); +drop table test_zero_date; +create table test_zero_date (a int); +insert into test_zero_date values (0); +alter table test_zero_date modify a date; +set session sql_mode='STRICT_TRANS_TABLES'; +drop table test_zero_date; +create table test_zero_date (a timestamp default 0); +drop table test_zero_date; +create table test_zero_date (a int); +insert into test_zero_date values (0); +alter table test_zero_date modify a date; +Error 1292 (22007): Truncated incorrect date value: '0' +set session sql_mode='NO_ZERO_DATE,STRICT_TRANS_TABLES'; +drop table test_zero_date; +create table test_zero_date (a timestamp default 0); +Error 1067 (42000): Invalid default value for 'a' +create table test_zero_date (a int); +insert into test_zero_date values (0); +alter table test_zero_date modify a date; +Error 1292 (22007): Truncated incorrect date value: '0' +drop table if exists test_zero_date; +set session sql_mode=default; +drop table if exists t; +create table t(c1 decimal default 1.7976931348623157E308); +Error 1067 (42000): Invalid default value for 'c1' +create table t( c1 varchar(2) default 'TiDB'); +Error 1067 (42000): Invalid default value for 'c1' +drop table if exists t_without_length; +create table t_without_length (a text primary key); +Error 1170 (42000): BLOB/TEXT column 'a' used in key specification without a key length +drop table if exists t; +create table t(xxx.t.a bigint); +Error 1102 (42000): Incorrect database name 'xxx' +create table t(ddl__db_integration.tttt.a bigint); +Error 1103 (42000): Incorrect table name 'tttt' +create table t(t.tttt.a bigint); +Error 1102 (42000): Incorrect database name 't' +drop table if exists t1; +create table t1 (quantity decimal(2) unsigned); +insert into t1 values (500), (-500), (~0), (-1); +Error 1264 (22003): Out of range value for column 'quantity' at row 1 +drop table t1; +set sql_mode=''; +create table t1 (quantity decimal(2) unsigned); +insert into t1 values (500), (-500), (~0), (-1); +select * from t1; +quantity +99 +0 +99 +0 +drop table t1; +set sql_mode=default; +drop table if exists issue3833, issue3833_2; +create table issue3833 (b char(0), c binary(0), d varchar(0)); +create index idx on issue3833 (b); +Error 1167 (42000): The used storage engine can't index column 'b' +alter table issue3833 add index idx (b); +Error 1167 (42000): The used storage engine can't index column 'b' +create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(b)); +Error 1167 (42000): The used storage engine can't index column 'b' +create index idx on issue3833 (c); +Error 1167 (42000): The used storage engine can't index column 'c' +alter table issue3833 add index idx (c); +Error 1167 (42000): The used storage engine can't index column 'c' +create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(c)); +Error 1167 (42000): The used storage engine can't index column 'c' +create index idx on issue3833 (d); +Error 1167 (42000): The used storage engine can't index column 'd' +alter table issue3833 add index idx (d); +Error 1167 (42000): The used storage engine can't index column 'd' +create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(d)); +Error 1167 (42000): The used storage engine can't index column 'd' +drop table if exists test_error_code_succ, test_error_code1, test_error_code_2, test_error_code_3, test_error_code_null, test_error_code_succ; +drop table if exists t1, t2, test_add_columns_on_update, test_drop_column, test_drop_columns; +create database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +create database test; +Error 1007 (HY000): Can't create database 'test'; database exists +create database test1 character set uft8; +[parser:1115]Unknown character set: 'uft8' +create database test2 character set gkb; +[parser:1115]Unknown character set: 'gkb' +create database test3 character set laitn1; +[parser:1115]Unknown character set: 'laitn1' +drop database db_not_exist; +Error 1008 (HY000): Can't drop database 'db_not_exist'; database doesn't exist +create table test_error_code_succ (c1 int, c2 int, c3 int, primary key(c3)); +create table test_error_code_succ (c1 int, c2 int, c3 int); +Error 1050 (42S01): Table 'ddl__db_integration.test_error_code_succ' already exists +create table test_error_code1 (c1 int, c2 int, c2 int); +Error 1060 (42S21): Duplicate column name 'c2' +create table test_error_code1 (c1 int, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +create table test_error_code1 (c1 int, `_tidb_rowid` int); +Error 1166 (42000): Incorrect column name '_tidb_rowid' +create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +create table test_error_code1 (c1 int, c2 int, key aa (c1, c2), key aa (c1)); +Error 1061 (42000): duplicate key name aa +create table test_error_code1 (c1 int, c2 int, c3 int, key(c_not_exist)); +Error 1072 (42000): column does not exist: c_not_exist +create table test_error_code1 (c1 int, c2 int, c3 int, primary key(c_not_exist)); +Error 1072 (42000): Key column 'c_not_exist' doesn't exist in table +create table test_error_code1 (c1 int not null default ''); +Error 1067 (42000): Invalid default value for 'c1' +CREATE TABLE `t` (`a` double DEFAULT 1.0 DEFAULT 2.0 DEFAULT now()); +Error 1067 (42000): Invalid default value for 'a' +CREATE TABLE `t` (`a` double DEFAULT now()); +Error 1067 (42000): Invalid default value for 'a' +create table t1(a int) character set uft8; +[parser:1115]Unknown character set: 'uft8' +create table t1(a int) character set gkb; +[parser:1115]Unknown character set: 'gkb' +create table t1(a int) character set laitn1; +[parser:1115]Unknown character set: 'laitn1' +create table test_error_code (a int not null ,b int not null,c int not null, d int not null, foreign key (b, c) references product(id)); +Error 1239 (42000): Incorrect foreign key definition for 'fk_1': Key reference and table reference don't match +create table test_error_code_2; +Error 1113 (42000): A table must have at least 1 column +create table test_error_code_2 (unique(c1)); +Error 1113 (42000): A table must have at least 1 column +create table test_error_code_2(c1 int, c2 int, c3 int, primary key(c1), primary key(c2)); +Error 1068 (42000): Multiple primary key defined +create table test_error_code_3(pt blob ,primary key (pt)); +Error 1170 (42000): BLOB/TEXT column 'pt' used in key specification without a key length +create table test_error_code_3(a text, unique (a(769))); +Error 1071 (42000): Specified key was too long (3076 bytes); max key length is 3072 bytes +create table test_error_code_3(a text charset ascii, unique (a(3073))); +Error 1071 (42000): Specified key was too long (3073 bytes); max key length is 3072 bytes +create table test_error_code_3(`id` int, key `primary`(`id`)); +Error 1280 (42000): Incorrect index name 'primary' +create table t2(c1.c2 blob default null); +Error 1103 (42000): Incorrect table name 'c1' +create table t2 (id int default null primary key , age int); +Error 1067 (42000): Invalid default value for 'id' +create table t2 (id int null primary key , age int); +Error 1171 (42000): All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead +create table t2 (id int default null, age int, primary key(id)); +Error 1171 (42000): All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead +create table t2 (id int null, age int, primary key(id)); +Error 1171 (42000): All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead +create table t2 (id int auto_increment, c int auto_increment); +Error 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key +create table t2 (a datetime(2) default current_timestamp(3)); +Error 1067 (42000): Invalid default value for 'a' +create table t2 (a datetime(2) default current_timestamp(2) on update current_timestamp); +Error 1294 (HY000): Invalid ON UPDATE clause for 'a' column +create table t2 (a datetime default current_timestamp on update current_timestamp(2)); +Error 1294 (HY000): Invalid ON UPDATE clause for 'a' column +create table t2 (a datetime(2) default current_timestamp(2) on update current_timestamp(3)); +Error 1294 (HY000): Invalid ON UPDATE clause for 'a' column +create table t(a blob(10), index(a(0))); +Error 1391 (HY000): Key part 'a' length cannot be 0 +create table t(a char(10), index(a(0))); +Error 1391 (HY000): Key part 'a' length cannot be 0 +create table t2 (id int primary key , age int); +alter table test_error_code_succ add column c1 int; +Error 1060 (42S21): Duplicate column name 'c1' +alter table test_error_code_succ add column aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int; +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +alter table test_comment comment 'test comment'; +Error 1146 (42S02): Table 'ddl__db_integration.test_comment' doesn't exist +alter table test_error_code_succ add column `a ` int ; +Error 1166 (42000): Incorrect column name 'a ' +alter table test_error_code_succ add column `_tidb_rowid` int ; +Error 1166 (42000): Incorrect column name '_tidb_rowid' +create table test_on_update (c1 int, c2 int); +alter table test_on_update add column c3 int on update current_timestamp; +Error 1294 (HY000): Invalid ON UPDATE clause for 'c3' column +create table test_on_update_2(c int on update current_timestamp); +Error 1294 (HY000): Invalid ON UPDATE clause for 'c' column +alter table test_error_code_succ add column c1 int, add column c1 int; +Error 1060 (42S21): Duplicate column name 'c1' +alter table test_error_code_succ add column (aa int, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int); +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +alter table test_error_code_succ add column `a ` int, add column `b ` int; +Error 1166 (42000): Incorrect column name 'a ' +create table test_add_columns_on_update (c1 int, c2 int); +alter table test_add_columns_on_update add column cc int, add column c3 int on update current_timestamp; +Error 1294 (HY000): Invalid ON UPDATE clause for 'c3' column +alter table test_error_code_succ drop c_not_exist; +Error 1091 (42000): Can't DROP 'c_not_exist'; check that column/key exists +create table test_drop_column (c1 int ); +alter table test_drop_column drop column c1; +Error 1090 (42000): can't drop only column c1 in table test_drop_column +alter table test_error_code_succ drop c_not_exist, drop cc_not_exist; +Error 1091 (42000): Can't DROP 'c_not_exist'; check that column/key exists +create table test_drop_columns (c1 int); +alter table test_drop_columns add column c2 int first, add column c3 int after c1; +alter table test_drop_columns drop column c1, drop column c2, drop column c3; +Error 1090 (42000): You can't delete all columns with ALTER TABLE; use DROP TABLE instead +alter table test_drop_columns drop column c1, add column c2 int; +Error 1060 (42S21): Duplicate column name 'c2' +alter table test_drop_columns drop column c1, drop column c1; +Error 8200 (HY000): Unsupported operate same column 'c1' +alter table test_error_code_succ add index idx (c_not_exist); +Error 1072 (42000): column does not exist: c_not_exist +alter table test_error_code_succ add index idx (c1); +alter table test_error_code_succ add index idx (c1); +Error 1061 (42000): index already exist idx +alter table test_error_code_succ drop index idx_not_exist; +Error 1091 (42000): index idx_not_exist doesn't exist +alter table test_error_code_succ drop column c3; +Error 8200 (HY000): Unsupported drop integer primary key +alter table test_error_code_succ modify testx.test_error_code_succ.c1 bigint; +Error 1102 (42000): Incorrect database name 'testx' +alter table test_error_code_succ modify t.c1 bigint; +Error 1103 (42000): Incorrect table name 't' +alter table test_error_code_succ change c1 _tidb_rowid bigint; +Error 1166 (42000): Incorrect column name '_tidb_rowid' +alter table test_error_code_succ rename column c1 to _tidb_rowid; +Error 1166 (42000): Incorrect column name '_tidb_rowid' +create table test_error_code_null(c1 char(100) not null); +insert into test_error_code_null (c1) values(null); +Error 1048 (23000): Column 'c1' cannot be null +drop table if exists t; +create table t (a decimal(1, 2)); +Error 1427 (42000): For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'a'). +create table t (a float(1, 2)); +Error 1427 (42000): For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'a'). +create table t (a double(1, 2)); +Error 1427 (42000): For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'a'). +create table t (a double(1, 1)); +alter table t add column b decimal(1, 2); +Error 1427 (42000): For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'b'). +alter table t modify column a float(1, 4); +Error 1427 (42000): For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'a'). +alter table t change column a aa float(1, 4); +Error 1427 (42000): For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'aa'). +drop table t; +drop table if exists t_too_many_indexes; +create table t_too_many_indexes (c0 int,c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int,c9 int,c10 int,c11 int,c12 int,c13 int,c14 int,c15 int,c16 int,c17 int,c18 int,c19 int,c20 int,c21 int,c22 int,c23 int,c24 int,c25 int,c26 int,c27 int,c28 int,c29 int,c30 int,c31 int,c32 int,c33 int,c34 int,c35 int,c36 int,c37 int,c38 int,c39 int,c40 int,c41 int,c42 int,c43 int,c44 int,c45 int,c46 int,c47 int,c48 int,c49 int,c50 int,c51 int,c52 int,c53 int,c54 int,c55 int,c56 int,c57 int,c58 int,c59 int,c60 int,c61 int,c62 int,c63 int,c64 int,c65 int,c66 int,c67 int,c68 int,c69 int,c70 int,c71 int,c72 int,c73 int,c74 int,c75 int,c76 int,c77 int,c78 int,c79 int,c80 int,c81 int,c82 int,c83 int,c84 int,c85 int,c86 int,c87 int,c88 int,c89 int,c90 int,c91 int,c92 int,c93 int,c94 int,c95 int,c96 int,c97 int,c98 int,c99 int,key k0(c0),key k1(c1),key k2(c2),key k3(c3),key k4(c4),key k5(c5),key k6(c6),key k7(c7),key k8(c8),key k9(c9),key k10(c10),key k11(c11),key k12(c12),key k13(c13),key k14(c14),key k15(c15),key k16(c16),key k17(c17),key k18(c18),key k19(c19),key k20(c20),key k21(c21),key k22(c22),key k23(c23),key k24(c24),key k25(c25),key k26(c26),key k27(c27),key k28(c28),key k29(c29),key k30(c30),key k31(c31),key k32(c32),key k33(c33),key k34(c34),key k35(c35),key k36(c36),key k37(c37),key k38(c38),key k39(c39),key k40(c40),key k41(c41),key k42(c42),key k43(c43),key k44(c44),key k45(c45),key k46(c46),key k47(c47),key k48(c48),key k49(c49),key k50(c50),key k51(c51),key k52(c52),key k53(c53),key k54(c54),key k55(c55),key k56(c56),key k57(c57),key k58(c58),key k59(c59),key k60(c60),key k61(c61),key k62(c62),key k63(c63),key k64(c64),key k65(c65),key k66(c66),key k67(c67),key k68(c68),key k69(c69),key k70(c70),key k71(c71),key k72(c72),key k73(c73),key k74(c74),key k75(c75),key k76(c76),key k77(c77),key k78(c78),key k79(c79),key k80(c80),key k81(c81),key k82(c82),key k83(c83),key k84(c84),key k85(c85),key k86(c86),key k87(c87),key k88(c88),key k89(c89),key k90(c90),key k91(c91),key k92(c92),key k93(c93),key k94(c94),key k95(c95),key k96(c96),key k97(c97),key k98(c98),key k99(c99)); +Error 1069 (42000): Too many keys specified; max 64 keys allowed +drop table if exists t_too_many; +create table t_index_too_many (c0 int,c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int,c9 int,c10 int,c11 int,c12 int,c13 int,c14 int,c15 int,c16 int,c17 int,c18 int,c19 int,c20 int,c21 int,c22 int,c23 int,c24 int,c25 int,c26 int,c27 int,c28 int,c29 int,c30 int,c31 int,c32 int,c33 int,c34 int,c35 int,c36 int,c37 int,c38 int,c39 int,c40 int,c41 int,c42 int,c43 int,c44 int,c45 int,c46 int,c47 int,c48 int,c49 int,c50 int,c51 int,c52 int,c53 int,c54 int,c55 int,c56 int,c57 int,c58 int,c59 int,c60 int,c61 int,c62 int,c63 int,c64 int,c65 int,c66 int,c67 int,c68 int,c69 int,c70 int,c71 int,c72 int,c73 int,c74 int,c75 int,c76 int,c77 int,c78 int,c79 int,c80 int,c81 int,c82 int,c83 int,c84 int,c85 int,c86 int,c87 int,c88 int,c89 int,c90 int,c91 int,c92 int,c93 int,c94 int,c95 int,c96 int,c97 int,c98 int,c99 int,key k0(c0),key k1(c1),key k2(c2),key k3(c3),key k4(c4),key k5(c5),key k6(c6),key k7(c7),key k8(c8),key k9(c9),key k10(c10),key k11(c11),key k12(c12),key k13(c13),key k14(c14),key k15(c15),key k16(c16),key k17(c17),key k18(c18),key k19(c19),key k20(c20),key k21(c21),key k22(c22),key k23(c23),key k24(c24),key k25(c25),key k26(c26),key k27(c27),key k28(c28),key k29(c29),key k30(c30),key k31(c31),key k32(c32),key k33(c33),key k34(c34),key k35(c35),key k36(c36),key k37(c37),key k38(c38),key k39(c39),key k40(c40),key k41(c41),key k42(c42),key k43(c43),key k44(c44),key k45(c45),key k46(c46),key k47(c47),key k48(c48),key k49(c49),key k50(c50),key k51(c51),key k52(c52),key k53(c53),key k54(c54),key k55(c55),key k56(c56),key k57(c57),key k58(c58),key k59(c59),key k60(c60),key k61(c61),key k62(c62)); +create index idx1 on t_index_too_many (c62); +create index idx2 on t_index_too_many (c63); +Error 1069 (42000): Too many keys specified; max 64 keys allowed +drop table if exists t_column_too_many; +create table t_column_too_many (a0 int,a1 int,a2 int,a3 int,a4 int,a5 int,a6 int,a7 int,a8 int,a9 int,a10 int,a11 int,a12 int,a13 int,a14 int,a15 int,a16 int,a17 int,a18 int,a19 int,a20 int,a21 int,a22 int,a23 int,a24 int,a25 int,a26 int,a27 int,a28 int,a29 int,a30 int,a31 int,a32 int,a33 int,a34 int,a35 int,a36 int,a37 int,a38 int,a39 int,a40 int,a41 int,a42 int,a43 int,a44 int,a45 int,a46 int,a47 int,a48 int,a49 int,a50 int,a51 int,a52 int,a53 int,a54 int,a55 int,a56 int,a57 int,a58 int,a59 int,a60 int,a61 int,a62 int,a63 int,a64 int,a65 int,a66 int,a67 int,a68 int,a69 int,a70 int,a71 int,a72 int,a73 int,a74 int,a75 int,a76 int,a77 int,a78 int,a79 int,a80 int,a81 int,a82 int,a83 int,a84 int,a85 int,a86 int,a87 int,a88 int,a89 int,a90 int,a91 int,a92 int,a93 int,a94 int,a95 int,a96 int,a97 int,a98 int,a99 int,a100 int,a101 int,a102 int,a103 int,a104 int,a105 int,a106 int,a107 int,a108 int,a109 int,a110 int,a111 int,a112 int,a113 int,a114 int,a115 int,a116 int,a117 int,a118 int,a119 int,a120 int,a121 int,a122 int,a123 int,a124 int,a125 int,a126 int,a127 int,a128 int,a129 int,a130 int,a131 int,a132 int,a133 int,a134 int,a135 int,a136 int,a137 int,a138 int,a139 int,a140 int,a141 int,a142 int,a143 int,a144 int,a145 int,a146 int,a147 int,a148 int,a149 int,a150 int,a151 int,a152 int,a153 int,a154 int,a155 int,a156 int,a157 int,a158 int,a159 int,a160 int,a161 int,a162 int,a163 int,a164 int,a165 int,a166 int,a167 int,a168 int,a169 int,a170 int,a171 int,a172 int,a173 int,a174 int,a175 int,a176 int,a177 int,a178 int,a179 int,a180 int,a181 int,a182 int,a183 int,a184 int,a185 int,a186 int,a187 int,a188 int,a189 int,a190 int,a191 int,a192 int,a193 int,a194 int,a195 int,a196 int,a197 int,a198 int,a199 int,a200 int,a201 int,a202 int,a203 int,a204 int,a205 int,a206 int,a207 int,a208 int,a209 int,a210 int,a211 int,a212 int,a213 int,a214 int,a215 int,a216 int,a217 int,a218 int,a219 int,a220 int,a221 int,a222 int,a223 int,a224 int,a225 int,a226 int,a227 int,a228 int,a229 int,a230 int,a231 int,a232 int,a233 int,a234 int,a235 int,a236 int,a237 int,a238 int,a239 int,a240 int,a241 int,a242 int,a243 int,a244 int,a245 int,a246 int,a247 int,a248 int,a249 int,a250 int,a251 int,a252 int,a253 int,a254 int,a255 int,a256 int,a257 int,a258 int,a259 int,a260 int,a261 int,a262 int,a263 int,a264 int,a265 int,a266 int,a267 int,a268 int,a269 int,a270 int,a271 int,a272 int,a273 int,a274 int,a275 int,a276 int,a277 int,a278 int,a279 int,a280 int,a281 int,a282 int,a283 int,a284 int,a285 int,a286 int,a287 int,a288 int,a289 int,a290 int,a291 int,a292 int,a293 int,a294 int,a295 int,a296 int,a297 int,a298 int,a299 int,a300 int,a301 int,a302 int,a303 int,a304 int,a305 int,a306 int,a307 int,a308 int,a309 int,a310 int,a311 int,a312 int,a313 int,a314 int,a315 int,a316 int,a317 int,a318 int,a319 int,a320 int,a321 int,a322 int,a323 int,a324 int,a325 int,a326 int,a327 int,a328 int,a329 int,a330 int,a331 int,a332 int,a333 int,a334 int,a335 int,a336 int,a337 int,a338 int,a339 int,a340 int,a341 int,a342 int,a343 int,a344 int,a345 int,a346 int,a347 int,a348 int,a349 int,a350 int,a351 int,a352 int,a353 int,a354 int,a355 int,a356 int,a357 int,a358 int,a359 int,a360 int,a361 int,a362 int,a363 int,a364 int,a365 int,a366 int,a367 int,a368 int,a369 int,a370 int,a371 int,a372 int,a373 int,a374 int,a375 int,a376 int,a377 int,a378 int,a379 int,a380 int,a381 int,a382 int,a383 int,a384 int,a385 int,a386 int,a387 int,a388 int,a389 int,a390 int,a391 int,a392 int,a393 int,a394 int,a395 int,a396 int,a397 int,a398 int,a399 int,a400 int,a401 int,a402 int,a403 int,a404 int,a405 int,a406 int,a407 int,a408 int,a409 int,a410 int,a411 int,a412 int,a413 int,a414 int,a415 int,a416 int,a417 int,a418 int,a419 int,a420 int,a421 int,a422 int,a423 int,a424 int,a425 int,a426 int,a427 int,a428 int,a429 int,a430 int,a431 int,a432 int,a433 int,a434 int,a435 int,a436 int,a437 int,a438 int,a439 int,a440 int,a441 int,a442 int,a443 int,a444 int,a445 int,a446 int,a447 int,a448 int,a449 int,a450 int,a451 int,a452 int,a453 int,a454 int,a455 int,a456 int,a457 int,a458 int,a459 int,a460 int,a461 int,a462 int,a463 int,a464 int,a465 int,a466 int,a467 int,a468 int,a469 int,a470 int,a471 int,a472 int,a473 int,a474 int,a475 int,a476 int,a477 int,a478 int,a479 int,a480 int,a481 int,a482 int,a483 int,a484 int,a485 int,a486 int,a487 int,a488 int,a489 int,a490 int,a491 int,a492 int,a493 int,a494 int,a495 int,a496 int,a497 int,a498 int,a499 int,a500 int,a501 int,a502 int,a503 int,a504 int,a505 int,a506 int,a507 int,a508 int,a509 int,a510 int,a511 int,a512 int,a513 int,a514 int,a515 int,a516 int,a517 int,a518 int,a519 int,a520 int,a521 int,a522 int,a523 int,a524 int,a525 int,a526 int,a527 int,a528 int,a529 int,a530 int,a531 int,a532 int,a533 int,a534 int,a535 int,a536 int,a537 int,a538 int,a539 int,a540 int,a541 int,a542 int,a543 int,a544 int,a545 int,a546 int,a547 int,a548 int,a549 int,a550 int,a551 int,a552 int,a553 int,a554 int,a555 int,a556 int,a557 int,a558 int,a559 int,a560 int,a561 int,a562 int,a563 int,a564 int,a565 int,a566 int,a567 int,a568 int,a569 int,a570 int,a571 int,a572 int,a573 int,a574 int,a575 int,a576 int,a577 int,a578 int,a579 int,a580 int,a581 int,a582 int,a583 int,a584 int,a585 int,a586 int,a587 int,a588 int,a589 int,a590 int,a591 int,a592 int,a593 int,a594 int,a595 int,a596 int,a597 int,a598 int,a599 int,a600 int,a601 int,a602 int,a603 int,a604 int,a605 int,a606 int,a607 int,a608 int,a609 int,a610 int,a611 int,a612 int,a613 int,a614 int,a615 int,a616 int,a617 int,a618 int,a619 int,a620 int,a621 int,a622 int,a623 int,a624 int,a625 int,a626 int,a627 int,a628 int,a629 int,a630 int,a631 int,a632 int,a633 int,a634 int,a635 int,a636 int,a637 int,a638 int,a639 int,a640 int,a641 int,a642 int,a643 int,a644 int,a645 int,a646 int,a647 int,a648 int,a649 int,a650 int,a651 int,a652 int,a653 int,a654 int,a655 int,a656 int,a657 int,a658 int,a659 int,a660 int,a661 int,a662 int,a663 int,a664 int,a665 int,a666 int,a667 int,a668 int,a669 int,a670 int,a671 int,a672 int,a673 int,a674 int,a675 int,a676 int,a677 int,a678 int,a679 int,a680 int,a681 int,a682 int,a683 int,a684 int,a685 int,a686 int,a687 int,a688 int,a689 int,a690 int,a691 int,a692 int,a693 int,a694 int,a695 int,a696 int,a697 int,a698 int,a699 int,a700 int,a701 int,a702 int,a703 int,a704 int,a705 int,a706 int,a707 int,a708 int,a709 int,a710 int,a711 int,a712 int,a713 int,a714 int,a715 int,a716 int,a717 int,a718 int,a719 int,a720 int,a721 int,a722 int,a723 int,a724 int,a725 int,a726 int,a727 int,a728 int,a729 int,a730 int,a731 int,a732 int,a733 int,a734 int,a735 int,a736 int,a737 int,a738 int,a739 int,a740 int,a741 int,a742 int,a743 int,a744 int,a745 int,a746 int,a747 int,a748 int,a749 int,a750 int,a751 int,a752 int,a753 int,a754 int,a755 int,a756 int,a757 int,a758 int,a759 int,a760 int,a761 int,a762 int,a763 int,a764 int,a765 int,a766 int,a767 int,a768 int,a769 int,a770 int,a771 int,a772 int,a773 int,a774 int,a775 int,a776 int,a777 int,a778 int,a779 int,a780 int,a781 int,a782 int,a783 int,a784 int,a785 int,a786 int,a787 int,a788 int,a789 int,a790 int,a791 int,a792 int,a793 int,a794 int,a795 int,a796 int,a797 int,a798 int,a799 int,a800 int,a801 int,a802 int,a803 int,a804 int,a805 int,a806 int,a807 int,a808 int,a809 int,a810 int,a811 int,a812 int,a813 int,a814 int,a815 int,a816 int,a817 int,a818 int,a819 int,a820 int,a821 int,a822 int,a823 int,a824 int,a825 int,a826 int,a827 int,a828 int,a829 int,a830 int,a831 int,a832 int,a833 int,a834 int,a835 int,a836 int,a837 int,a838 int,a839 int,a840 int,a841 int,a842 int,a843 int,a844 int,a845 int,a846 int,a847 int,a848 int,a849 int,a850 int,a851 int,a852 int,a853 int,a854 int,a855 int,a856 int,a857 int,a858 int,a859 int,a860 int,a861 int,a862 int,a863 int,a864 int,a865 int,a866 int,a867 int,a868 int,a869 int,a870 int,a871 int,a872 int,a873 int,a874 int,a875 int,a876 int,a877 int,a878 int,a879 int,a880 int,a881 int,a882 int,a883 int,a884 int,a885 int,a886 int,a887 int,a888 int,a889 int,a890 int,a891 int,a892 int,a893 int,a894 int,a895 int,a896 int,a897 int,a898 int,a899 int,a900 int,a901 int,a902 int,a903 int,a904 int,a905 int,a906 int,a907 int,a908 int,a909 int,a910 int,a911 int,a912 int,a913 int,a914 int,a915 int,a916 int,a917 int,a918 int,a919 int,a920 int,a921 int,a922 int,a923 int,a924 int,a925 int,a926 int,a927 int,a928 int,a929 int,a930 int,a931 int,a932 int,a933 int,a934 int,a935 int,a936 int,a937 int,a938 int,a939 int,a940 int,a941 int,a942 int,a943 int,a944 int,a945 int,a946 int,a947 int,a948 int,a949 int,a950 int,a951 int,a952 int,a953 int,a954 int,a955 int,a956 int,a957 int,a958 int,a959 int,a960 int,a961 int,a962 int,a963 int,a964 int,a965 int,a966 int,a967 int,a968 int,a969 int,a970 int,a971 int,a972 int,a973 int,a974 int,a975 int,a976 int,a977 int,a978 int,a979 int,a980 int,a981 int,a982 int,a983 int,a984 int,a985 int,a986 int,a987 int,a988 int,a989 int,a990 int,a991 int,a992 int,a993 int,a994 int,a995 int,a996 int,a997 int,a998 int,a999 int,a1000 int,a1001 int,a1002 int,a1003 int,a1004 int,a1005 int,a1006 int,a1007 int,a1008 int,a1009 int,a1010 int,a1011 int,a1012 int,a1013 int,a1014 int,a1015 int); +alter table t_column_too_many add column a_512 int; +alter table t_column_too_many add column a_513 int; +Error 1117 (HY000): Too many columns +drop table if exists t; +CREATE TABLE t ( +c01 varchar(255) NOT NULL, +c02 varchar(255) NOT NULL, +c03 varchar(255) NOT NULL, +c04 varchar(255) DEFAULT NULL, +c05 varchar(255) DEFAULT NULL, +c06 varchar(255) DEFAULT NULL, +PRIMARY KEY (c01,c02,c03) clustered, +KEY c04 (c04) +); +drop table t; +CREATE TABLE t ( +c01 varchar(255) NOT NULL, +c02 varchar(255) NOT NULL, +c03 varchar(255) NOT NULL, +c04 varchar(255) NOT NULL, +c05 varchar(255) DEFAULT NULL, +c06 varchar(255) DEFAULT NULL, +PRIMARY KEY (c01,c02,c03,c04) clustered +); +Error 1071 (42000): Specified key was too long (4080 bytes); max key length is 3072 bytes +CREATE TABLE t ( +c01 varchar(255) NOT NULL, +c02 varchar(255) NOT NULL, +c03 varchar(255) NOT NULL, +c04 varchar(255) DEFAULT NULL, +c05 varchar(255) DEFAULT NULL, +c06 varchar(255) DEFAULT NULL, +PRIMARY KEY (c01,c02,c03) clustered, +unique key c04 (c04) +); +drop table t; +CREATE TABLE t ( +c01 varchar(255) NOT NULL, +c02 varchar(255) NOT NULL, +c03 varchar(255) NOT NULL, +c04 varchar(255) DEFAULT NULL, +c05 varchar(255) DEFAULT NULL, +c06 varchar(255) DEFAULT NULL, +PRIMARY KEY (c01,c02) clustered +); +create index idx1 on t(c03); +create index idx2 on t(c03, c04); +create unique index uk2 on t(c03, c04); +drop table t; +CREATE TABLE t ( +c01 varchar(255) NOT NULL, +c02 varchar(255) NOT NULL, +c03 varchar(255) NOT NULL, +c04 varchar(255) DEFAULT NULL, +c05 varchar(255) DEFAULT NULL, +c06 varchar(255) DEFAULT NULL, +Index idx1(c03), +PRIMARY KEY (c01,c02) clustered, +unique index uk1(c06) +); +alter table t change c03 c10 varchar(256) default null; +alter table t change c10 c100 varchar(1024) default null; +Error 1071 (42000): Specified key was too long (4096 bytes); max key length is 3072 bytes +alter table t modify c10 varchar(600) default null; +alter table t modify c06 varchar(600) default null; +alter table t modify c01 varchar(510); +drop table if exists t2; +create table t2 like t; +drop table if exists t; +create table t( +a int, +b varchar(100), +c int, +INDEX idx_c(c)) +PARTITION BY RANGE COLUMNS( a ) ( +PARTITION p0 VALUES LESS THAN (6), +PARTITION p1 VALUES LESS THAN (11), +PARTITION p2 VALUES LESS THAN (16), +PARTITION p3 VALUES LESS THAN (21) +); +insert into t values (4, 'xxx', 4); +insert into t values (4, 'xxx', 9); +insert into t values (17, 'xxx', 12); +alter table t add unique index idx_a(a); +Error 1062 (23000): Duplicate entry '4' for key 't.idx_a' +delete from t where a = 4; +alter table t add unique index idx_a(a); +alter table t add unique index idx_ac(a, c); +alter table t add unique index idx_b(b); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +drop table if exists t; +drop table if exists t_ft; +create table t_ft (a text, fulltext key (a)); +show warnings; +Level Code Message +Warning 1214 The used table type doesn't support FULLTEXT indexes +alter table t_ft add fulltext key (a); +show warnings; +Level Code Message +Warning 1214 The used table type doesn't support FULLTEXT indexes +show create table t_ft; +Table Create Table +t_ft CREATE TABLE `t_ft` ( + `a` text DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t_ft; +drop table if exists t; +create table t (a int default b'1'); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT '1' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t; +drop table if exists t; +create table t (c int(10), c1 varchar(256) default (uuid())); +alter table t add column c2 varchar(256) default (uuid()); +Error 1674 (HY000): Statement is unsafe because it uses a system function that may return a different value on the slave +insert into t(c) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +select count(distinct c1) from t; +count(distinct c1) +10 +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `c` int(10) DEFAULT NULL, + `c1` varchar(256) DEFAULT uuid() +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t1; +create table t1 (a int(11) not null auto_increment key, b int(11), c bigint, unique key (a, b, c)); +alter table t1 drop index a; +drop table if exists t1; +create table t1 (a int auto_increment, unique key (a)); +alter table t1 drop index a; +drop table if exists t1; +create table t1 (a int(11) not null auto_increment, b int(11), c bigint, unique key (a, b, c)); +alter table t1 drop index a; +drop table if exists t1; +create table t1 (a int, b int as (-a) virtual, c int as (-a) stored); +insert into t1 values (1, default, default); +select * from t1; +a b c +1 -1 -1 +delete from t1; +insert into t1(a,b) values (1, default), (2, default); +select * from t1; +a b c +1 -1 -1 +2 -2 -2 +delete from t1; +insert into t1(b) values (default); +select * from t1; +a b c +NULL NULL NULL +delete from t1; +insert into t1(c) values (default); +select * from t1; +a b c +NULL NULL NULL +delete from t1; +drop table if exists t2; +create table t2 like t1; +alter table t2 add index idx1(a); +alter table t2 add index idx2(b); +insert into t2 values (1, default, default); +select * from t2; +a b c +1 -1 -1 +delete from t2; +alter table t2 drop index idx1; +alter table t2 drop index idx2; +insert into t2 values (1, default, default); +select * from t2; +a b c +1 -1 -1 +drop table if exists t3; +create table t3 (gc1 int as (r+1), gc2 int as (r+1) stored, gc3 int as (gc2+1), gc4 int as (gc1+1) stored, r int); +insert into t3 values (default, default, default, default, 1); +select * from t3; +gc1 gc2 gc3 gc4 r +2 2 3 3 1 +drop table if exists t4; +create table t4 (a int key, b int, c int as (a+1), d int as (b+1) stored); +insert into t4 values (1, 10, default, default); +select * from t4; +a b c d +1 10 2 11 +replace into t4 values (1, 20, default, default); +select * from t4; +a b c d +1 20 2 21 +drop table if exists t5; +create table t5 (a int default 10, b int as (a+1)); +insert into t5 values (20, default(a)); +Error 3105 (HY000): The value specified for generated column 'b' in table 't5' is not allowed. +drop table t1, t2, t3, t4, t5; +drop table if exists t; +create table t(a int, b json); +insert into t values (1, '{"a": 1}'); +alter table t add index idx((cast(b->'$.a' as char(255)))); +select * from t force index(idx); +a b +1 {"a": 1} +select * from t ignore index(idx); +a b +1 {"a": 1} +alter table t add index idx1((cast(b->>'$.a' as char(255)))); +select * from t force index(idx1); +a b +1 {"a": 1} +select * from t ignore index(idx1); +a b +1 {"a": 1} +alter table t add index idx2((json_type(b))); +select * from t force index(idx2) where json_type(b) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx2) where json_type(b) = 'OBJECT'; +a b +1 {"a": 1} +alter table t add index idx_wrong((b->'$.a')); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((b->>'$.a')); +Error 3757 (HY000): Cannot create an expression index on an expression that returns a BLOB or TEXT. Please consider using CAST +alter table t add index idx_wrong((json_pretty(b))); +Error 3757 (HY000): Cannot create an expression index on an expression that returns a BLOB or TEXT. Please consider using CAST +drop table if exists t; +create table t(a char(255), index idx((json_quote(a)))); +Error 1071 (42000): Specified key was too long (6128 bytes); max key length is 3072 bytes +create table t(a char(40)); +insert into t values ('[1, 2, 3]'); +alter table t add index idx3((json_quote(a))); +select * from t force index(idx3) where json_quote(a) = '"[1, 2, 3]"'; +a +[1, 2, 3] +select * from t ignore index(idx3) where json_quote(a) = '"[1, 2, 3]"'; +a +[1, 2, 3] +drop table if exists t; +create table t(a int, b json); +alter table t add index idx_wrong((json_array(b))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_object('key', b))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_merge_preserve(b, '{"k": "v"}'))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_set(b, '$.a', 'v'))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_insert(b, '$.a', 'v'))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_replace(b, '$.a', 'v'))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_remove(b, '$.a'))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_array_append(b, '$.a', 1))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_merge_patch(b, '{"k": "v"}'))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_search(b, 'one', 'a'))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +alter table t add index idx_wrong((json_keys(b))); +Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value +drop table if exists t; +create table t(a int, b json); +insert into t values (1, '{"a": 1}'); +alter table t add index idx0((json_type(json_search(b, 'one', 'a')))); +alter table t add index idx1((json_type(json_array(b)))); +alter table t add index idx2((json_type(json_object('key', b)))); +alter table t add index idx3((json_type(json_merge_preserve(b, '{"k": "v"}')))); +alter table t add index idx4((json_type(json_set(b, '$.a', 'v')))); +alter table t add index idx5((json_type(json_insert(b, '$.a', 'v')))); +alter table t add index idx6((json_type(json_replace(b, '$.a', 'v')))); +alter table t add index idx7((json_type(json_remove(b, '$.a')))); +alter table t add index idx8((json_type(json_array_append(b, '$.a', 1)))); +alter table t add index idx9((json_type(json_merge_patch(b, '{"k": "v"}')))); +alter table t add index idx10((json_type(json_keys(b)))); +alter table t add index idx11((cast(json_quote(cast(a as char(10))) as char(64)))); +alter table t add index idx12((json_storage_size(b))); +alter table t add index idx13((json_depth(b))); +alter table t add index idx14((json_length(b))); +select * from t force index(idx0) where json_type(json_search(b, 'one', 'a')) is NULL; +a b +1 {"a": 1} +select * from t force index(idx1) where json_type(json_array(b)) = 'ARRAY'; +a b +1 {"a": 1} +select * from t force index(idx2) where json_type(json_object('key', b)) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx3) where json_type(json_merge_preserve(b, '{"k": "v"}')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx4) where json_type(json_set(b, '$.a', 'v')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx5) where json_type(json_insert(b, '$.a', 'v')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx6) where json_type(json_replace(b, '$.a', 'v')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx7) where json_type(json_remove(b, '$.a')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx8) where json_type(json_array_append(b, '$.a', 1)) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx9) where json_type(json_merge_patch(b, '{"k": "v"}')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t force index(idx10) where json_type(json_keys(b)) = 'ARRAY'; +a b +1 {"a": 1} +select * from t force index(idx11) where cast(json_quote(cast(a as char(10))) as char(64)) = '"1"'; +a b +1 {"a": 1} +select * from t force index(idx12) where json_storage_size(b) > 1; +a b +1 {"a": 1} +select * from t force index(idx13) where json_depth(b) > 0; +a b +1 {"a": 1} +select * from t force index(idx14) where json_length(b) > 0; +a b +1 {"a": 1} +select * from t ignore index(idx0) where json_type(json_search(b, 'one', 'a')) is NULL; +a b +1 {"a": 1} +select * from t ignore index(idx1) where json_type(json_array(b)) = 'ARRAY'; +a b +1 {"a": 1} +select * from t ignore index(idx2) where json_type(json_object('key', b)) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx3) where json_type(json_merge_preserve(b, '{"k": "v"}')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx4) where json_type(json_set(b, '$.a', 'v')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx5) where json_type(json_insert(b, '$.a', 'v')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx6) where json_type(json_replace(b, '$.a', 'v')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx7) where json_type(json_remove(b, '$.a')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx8) where json_type(json_array_append(b, '$.a', 1)) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx9) where json_type(json_merge_patch(b, '{"k": "v"}')) = 'OBJECT'; +a b +1 {"a": 1} +select * from t ignore index(idx10) where json_type(json_keys(b)) = 'ARRAY'; +a b +1 {"a": 1} +select * from t ignore index(idx11) where cast(json_quote(cast(a as char(10))) as char(64)) = '"1"'; +a b +1 {"a": 1} +select * from t ignore index(idx12) where json_storage_size(b) > 1; +a b +1 {"a": 1} +select * from t ignore index(idx13) where json_depth(b) > 0; +a b +1 {"a": 1} +select * from t ignore index(idx14) where json_length(b) > 0; +a b +1 {"a": 1} +drop table if exists t; +create table t( +a int, +b varchar(100), +c int) +PARTITION BY RANGE ( a ) ( +PARTITION p0 VALUES LESS THAN (6), +PARTITION p1 VALUES LESS THAN (11), +PARTITION p2 VALUES LESS THAN (16), +PARTITION p3 VALUES LESS THAN (21) +); +insert into t values (1, 'test', 2), (12, 'test', 3), (15, 'test', 10), (20, 'test', 20); +alter table t add index idx((a+c)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) DEFAULT NULL, + `b` varchar(100) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + KEY `idx` ((`a` + `c`)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY RANGE (`a`) +(PARTITION `p0` VALUES LESS THAN (6), + PARTITION `p1` VALUES LESS THAN (11), + PARTITION `p2` VALUES LESS THAN (16), + PARTITION `p3` VALUES LESS THAN (21)) +select * from t order by a; +a b c +1 test 2 +12 test 3 +15 test 10 +20 test 20 +drop table if exists t; +drop table if exists t1; +create table t(a int auto_increment key clustered) auto_id_cache 100; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_id_cache] AUTO_ID_CACHE=100 */ +insert into t values(); +select * from t; +a +1 +delete from t; +rename table t to t1; +insert into t1 values(); +select * from t1; +a +101 +drop table if exists t; +drop table if exists t1; +create table t(a int) auto_id_cache 100; +insert into t values(); +select _tidb_rowid from t; +_tidb_rowid +1 +delete from t; +rename table t to t1; +insert into t1 values(); +select _tidb_rowid from t1; +_tidb_rowid +101 +drop table if exists t; +drop table if exists t1; +create table t(a int null, b int auto_increment unique) auto_id_cache 100; +insert into t(b) values(NULL); +select b, _tidb_rowid from t; +b _tidb_rowid +1 2 +delete from t; +rename table t to t1; +insert into t1(b) values(NULL); +select b, _tidb_rowid from t1; +b _tidb_rowid +101 102 +delete from t1; +alter table t1 auto_id_cache 200; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) NOT NULL AUTO_INCREMENT, + UNIQUE KEY `b` (`b`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=201 /*T![auto_id_cache] AUTO_ID_CACHE=200 */ +insert into t1(b) values(NULL); +select b, _tidb_rowid from t1; +b _tidb_rowid +201 202 +delete from t1; +rename table t1 to t; +insert into t(b) values(NULL); +select b, _tidb_rowid from t; +b _tidb_rowid +401 402 +delete from t; +drop table if exists t; +drop table if exists t1; +create table t(a int auto_increment key clustered) auto_id_cache 3; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_id_cache] AUTO_ID_CACHE=3 */ +insert into t(a) values(NULL),(NULL),(NULL); +insert into t(a) values(NULL); +select a from t; +a +1 +2 +3 +4 +delete from t; +rename table t to t1; +insert into t1(a) values(NULL); +select a from t1; +a +7 +drop table if exists t; +create table t(a int) auto_id_cache = 9223372036854775808; +Error 1105 (HY000): table option auto_id_cache overflows int64 +create table t(a int) auto_id_cache = 9223372036854775807; +alter table t auto_id_cache = 9223372036854775808; +Error 1105 (HY000): table option auto_id_cache overflows int64 +drop table if exists t, t1, t2, t3; +create table t(a int NOT NULL, b int, key(a), unique(b) invisible); +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +index_name is_visible +a YES +b NO +alter table t alter index a invisible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +index_name is_visible +a NO +b NO +alter table t alter index b visible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +index_name is_visible +a NO +b YES +alter table t alter index b invisible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +index_name is_visible +a NO +b NO +alter table t alter index non_exists_idx visible; +Error 1176 (42000): Key 'non_exists_idx' doesn't exist in table 't' +create table t1(a int NOT NULL, unique(a)); +alter table t1 alter index a invisible; +Error 3522 (HY000): A primary key index cannot be invisible +create table t2(a int, primary key(a)); +alter table t2 alter index PRIMARY invisible; +[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 34 near "PRIMARY invisible;" +create table t3(a int NOT NULL, b int); +alter table t3 add index idx((a+b)); +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't3' order by index_name; +index_name is_visible +idx YES +alter table t3 alter index idx invisible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't3' order by index_name; +index_name is_visible +idx NO +drop table if exists t_drop_last_column, t_drop_last_columns; +create table t_drop_last_column(x int, key((1+1))); +alter table t_drop_last_column drop column x; +Error 1113 (42000): A table must have at least 1 column +create table t_drop_last_columns(x int, y int, key((1+1))); +alter table t_drop_last_columns drop column x, drop column y; +Error 1113 (42000): A table must have at least 1 column +drop table if exists t_drop_last_column, t_drop_last_columns; +drop table if exists issue20741_2; +create table issue20741_2(id int primary key, c int); +insert into issue20741_2(id, c) values(1, 2), (2, 2); +alter table issue20741_2 add column cc set('a', 'b', 'c', 'd') not null; +update issue20741_2 set c=2 where id=1; +select * from issue20741_2; +id c cc +1 2 +2 2 +select * from issue20741_2 where cc = 0; +id c cc +1 2 +2 2 +select * from issue20741_2 where cc = 1; +id c cc +insert into issue20741_2(id, c) values (3, 3); +Error 1364 (HY000): Field 'cc' doesn't have a default value +drop table if exists t; +create table t( col decimal(1,2) not null default 0); +Error 1427 (42000): For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'col'). +drop table if exists tplacement1, tplacement2; +drop database if exists db2; +drop placement policy if exists x; +create placement policy x primary_region='r1' regions='r1'; +create temporary table tplacement2 (id int) placement policy='x'; +Error 8006 (HY000): `PLACEMENT` is unsupported on temporary tables. +create global temporary table tplacement1 (id int) on commit delete rows; +alter table tplacement1 placement policy='x'; +Error 8006 (HY000): `placement` is unsupported on temporary tables. +create temporary table tplacement2 (id int); +alter table tplacement2 placement policy='x'; +Error 8200 (HY000): TiDB doesn't support ALTER TABLE for local temporary table +create database db2 placement policy x; +create global temporary table db2.tplacement3 (id int) on commit delete rows; +show create table db2.tplacement3; +Table Create Table +tplacement3 CREATE GLOBAL TEMPORARY TABLE `tplacement3` ( + `id` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ON COMMIT DELETE ROWS +create temporary table db2.tplacement4 (id int); +show create table db2.tplacement4; +Table Create Table +tplacement4 CREATE TEMPORARY TABLE `tplacement4` ( + `id` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +create table db2.t1 (a int) placement policy 'default'; +create global temporary table db2.tplacement5 like db2.t1 on commit delete rows; +show create table db2.tplacement5; +Table Create Table +tplacement5 CREATE GLOBAL TEMPORARY TABLE `tplacement5` ( + `a` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ON COMMIT DELETE ROWS +create temporary table db2.tplacement6 like db2.t1; +show create table db2.tplacement6; +Table Create Table +tplacement6 CREATE TEMPORARY TABLE `tplacement6` ( + `a` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table db2.tplacement6; +drop table db2.tplacement5; +drop table db2.t1; +drop table db2.tplacement3; +drop database db2; +drop table tplacement1, tplacement2; +drop placement policy x; +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2; +create table tb(id int); +create table tb2(id int); +create global temporary table temp(id int) on commit delete rows; +create global temporary table temp1(id int) on commit delete rows; +create temporary table ltemp1(id int); +create temporary table ltemp2(id int); +drop global temporary table tb; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table ddl__db_integration.tb; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table ltemp1; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table ddl__db_integration.ltemp1; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table ltemp1, temp; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table temp, ltemp1; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table xxx, ltemp1; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table xxx; +Error 1051 (42S02): Unknown table 'ddl__db_integration.xxx' +drop global temporary table if exists tb; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table if exists ltemp1; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table if exists xxx; +show warnings; +Level Code Message +Note 1051 Unknown table 'ddl__db_integration.xxx' +drop global temporary table if exists xxx,tb; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table if exists ddl__db_integration.tb; +Error 8007 (HY000): `drop global temporary table` can only drop global temporary table +drop global temporary table temp; +select * from temp; +Error 1146 (42S02): Table 'ddl__db_integration.temp' doesn't exist +drop global temporary table ddl__db_integration.temp1; +select * from temp2; +Error 1146 (42S02): Table 'ddl__db_integration.temp2' doesn't exist +create global temporary table temp (id int) on commit delete rows; +create global temporary table temp1 (id int) on commit delete rows; +drop global temporary table temp, temp1; +select * from temp; +Error 1146 (42S02): Table 'ddl__db_integration.temp' doesn't exist +select * from temp1; +Error 1146 (42S02): Table 'ddl__db_integration.temp1' doesn't exist +create global temporary table temp (id int) on commit delete rows; +create global temporary table temp1 (id int) on commit delete rows; +drop global temporary table if exists temp; +show warnings; +Level Code Message +select * from temp; +Error 1146 (42S02): Table 'ddl__db_integration.temp' doesn't exist +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2; +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2, testt.ltemp3; +create table tb(id int); +create table tb2(id int); +insert into tb2 values(1); +create temporary table tb2(id int); +create global temporary table temp(id int) on commit delete rows; +create global temporary table temp1(id int) on commit delete rows; +create temporary table ltemp1(id int); +create temporary table ltemp2(id int); +create database if not exists testt; +create temporary table testt.ltemp3(id int); +drop temporary table tb; +Error 1051 (42S02): Unknown table 'ddl__db_integration.tb' +drop temporary table ddl__db_integration.tb; +Error 1051 (42S02): Unknown table 'ddl__db_integration.tb' +drop temporary table temp1; +Error 1051 (42S02): Unknown table 'ddl__db_integration.temp1' +drop temporary table ddl__db_integration.temp1; +Error 1051 (42S02): Unknown table 'ddl__db_integration.temp1' +drop temporary table ltemp1, tb; +Error 1051 (42S02): Unknown table 'ddl__db_integration.tb' +drop temporary table temp, ltemp1; +Error 1051 (42S02): Unknown table 'ddl__db_integration.temp' +drop temporary table xxx, ltemp1; +Error 1051 (42S02): Unknown table 'ddl__db_integration.xxx' +drop temporary table xxx; +Error 1051 (42S02): Unknown table 'ddl__db_integration.xxx' +drop temporary table if exists xxx; +show warnings; +Level Code Message +Note 1051 Unknown table 'ddl__db_integration.xxx' +drop temporary table if exists ltemp1, xxx; +show warnings; +Level Code Message +Note 1051 Unknown table 'ddl__db_integration.xxx' +drop temporary table if exists tb1, xxx; +show warnings; +Level Code Message +Note 1051 Unknown table 'ddl__db_integration.tb1,ddl__db_integration.xxx' +drop temporary table if exists temp1; +show warnings; +Level Code Message +Note 1051 Unknown table 'ddl__db_integration.temp1' +drop temporary table if exists temp1, xxx; +show warnings; +Level Code Message +Note 1051 Unknown table 'ddl__db_integration.temp1,ddl__db_integration.xxx' +drop temporary table if exists testt.ltemp4; +show warnings; +Level Code Message +Note 1051 Unknown table 'testt.ltemp4' +drop temporary table if exists testt.ltemp3, tb1; +show warnings; +Level Code Message +Note 1051 Unknown table 'ddl__db_integration.tb1' +drop temporary table ltemp1; +select * from ltemp1; +Error 1146 (42S02): Table 'ddl__db_integration.ltemp1' doesn't exist +drop temporary table ddl__db_integration.ltemp2; +select * from ltemp2; +Error 1146 (42S02): Table 'ddl__db_integration.ltemp2' doesn't exist +drop temporary table tb2; +select * from tb2; +id +1 +create temporary table ltemp1 (id int); +create temporary table ltemp2 (id int); +drop temporary table testt.ltemp3, ltemp1; +select * from testt.ltemp3; +Error 1146 (42S02): Table 'testt.ltemp3' doesn't exist +select * from ltemp1; +Error 1146 (42S02): Table 'ddl__db_integration.ltemp1' doesn't exist +drop temporary table if exists ltemp2; +show warnings; +Level Code Message +select * from ltemp2; +Error 1146 (42S02): Table 'ddl__db_integration.ltemp2' doesn't exist +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2, testt.ltemp3; +drop database testt; +drop table if exists t1; +create table t1 (id int); +insert into t1 values(1); +drop table if exists t2; +create table t2 (id int); +insert into t2 values(1); +drop view if exists v1; +create view v1 as select 1,1; +select * from v1; +1 Name_exp_1 +1 1 +drop view if exists v1; +create view v1 as select 1, 2, 1, 2, 1, 2, 1, 2; +select * from v1; +1 2 Name_exp_1 Name_exp_2 Name_exp_1_1 Name_exp_1_2 Name_exp_2_1 Name_exp_2_2 +1 2 1 2 1 2 1 2 +drop view if exists v1; +create view v1 as select 't', 't', 1 as t; +select * from v1; +Name_exp_t Name_exp_1_t t +t t 1 +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1, 1 union all select 1, 1; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` SQL SECURITY DEFINER VIEW `v1` (`1`, `Name_exp_1`) AS SELECT 1 AS `1`,1 AS `Name_exp_1` UNION ALL SELECT 1 AS `1`,1 AS `1` utf8mb4 utf8mb4_general_ci +select * from v1; +1 Name_exp_1 +1 1 +1 1 +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 'id', id from t1; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` SQL SECURITY DEFINER VIEW `v1` (`Name_exp_id`, `id`) AS SELECT _UTF8MB4'id' AS `Name_exp_id`,`id` AS `id` FROM `ddl__db_integration`.`t1` utf8mb4 utf8mb4_general_ci +select * from v1; +Name_exp_id id +id 1 +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1, (select id from t1 where t1.id=t2.id) as '1' from t2; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` SQL SECURITY DEFINER VIEW `v1` (`Name_exp_1`, `1`) AS SELECT 1 AS `Name_exp_1`,(SELECT `id` AS `id` FROM `ddl__db_integration`.`t1` WHERE `t1`.`id`=`t2`.`id`) AS `1` FROM `ddl__db_integration`.`t2` utf8mb4 utf8mb4_general_ci +select * from v1; +Name_exp_1 1 +1 1 +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1 as 'abs(t1.id)', abs(t1.id) from t1; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`127.0.0.1` SQL SECURITY DEFINER VIEW `v1` (`abs(t1.id)`, `Name_exp_abs(t1.id)`) AS SELECT 1 AS `abs(t1.id)`,ABS(`t1`.`id`) AS `Name_exp_abs(t1.id)` FROM `ddl__db_integration`.`t1` utf8mb4 utf8mb4_general_ci +select * from v1; +abs(t1.id) Name_exp_abs(t1.id) +1 1 +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1 as t,1 as t; +Error 1060 (42S21): Duplicate column name 't' +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1 as id, id from t1; +Error 1060 (42S21): Duplicate column name 'id' +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select * from t1 left join t2 on t1.id=t2.id; +Error 1060 (42S21): Duplicate column name 'id' +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select t1.id, t2.id from t1,t2 where t1.id=t2.id; +Error 1060 (42S21): Duplicate column name 'id' +drop view if exists v1; +drop table t2; +drop table t1; +drop table if exists t; +create table t(a int) partition by range (a) (partition p0 values less than (0), partition `p1 ` values less than (3)); +Error 1567 (HY000): Incorrect partition name +create table t(a int) partition by range (a) (partition `` values less than (0), partition `p1` values less than (3)); +Error 1567 (HY000): Incorrect partition name +create table t(a int) partition by range (a) (partition `p0` values less than (0), partition `p1` values less than (3)); +alter table t add partition (partition `p2 ` values less than (5)); +Error 1567 (HY000): Incorrect partition name +drop table if exists reg_like; +create table reg_like(a varchar(50), b varchar(50), c int generated always as (regexp_like(a, b))); +insert into reg_like(a, b) values('123', '2'); +insert into reg_like(a, b) values('456', '1'); +select * from reg_like; +a b c +123 2 1 +456 1 0 +drop table if exists reg_sub; +create table reg_sub(a varchar(50),b varchar(50),c varchar(50) generated always as (regexp_substr(a, b))); +insert into reg_sub(a, b) values('abcd', 'bc.'); +insert into reg_sub(a, b) values('1234', '23.'); +select * from reg_sub; +a b c +abcd bc. bcd +1234 23. 234 +drop table if exists reg_instr; +create table reg_instr(a varchar(50),b varchar(50),c varchar(50) generated always as (regexp_instr(a, b))); +insert into reg_instr(a, b) values('abcd', 'bc.'); +insert into reg_instr(a, b) values('1234', '23.'); +select * from reg_instr; +a b c +abcd bc. 2 +1234 23. 2 +drop table if exists reg_replace; +create table reg_replace(a varchar(50),b varchar(50),c varchar(50),d varchar(50) generated always as (regexp_replace(a, b, c))); +insert into reg_replace(a, b, c) values('abcd', 'bc.', 'xzx'); +insert into reg_replace(a, b, c) values('1234', '23.', 'xzx'); +select * from reg_replace; +a b c d +abcd bc. xzx axzx +1234 23. xzx 1xzx +drop table if exists reg_like; +drop table if exists t; +CREATE TABLE t (id int, d varchar(255)) partition by range (id) (partition p0 values less than (1000000), partition p1 values less than (2000000), partition p2 values less than (3000000)); +ALTER TABLE t REORGANIZE PARTITION p0,p2 INTO (PARTITION p0 VALUES LESS THAN (1000000)); +Error 8200 (HY000): Unsupported REORGANIZE PARTITION of RANGE; not adjacent partitions +ALTER TABLE t REORGANIZE PARTITION p0,p2 INTO (PARTITION p0 VALUES LESS THAN (4000000)); +Error 8200 (HY000): Unsupported REORGANIZE PARTITION of RANGE; not adjacent partitions +drop table if exists members, member_level; +CREATE TABLE members ( +id int, +fname varchar(255), +lname varchar(255), +dob date, +data json +) +PARTITION BY RANGE (YEAR(dob)) ( +PARTITION pBefore1950 VALUES LESS THAN (1950), +PARTITION p1950 VALUES LESS THAN (1960), +PARTITION p1960 VALUES LESS THAN (1970), +PARTITION p1970 VALUES LESS THAN (1980), +PARTITION p1980 VALUES LESS THAN (1990), +PARTITION p1990 VALUES LESS THAN (2000)); +CREATE TABLE member_level ( +id int, +level int, +achievements json +) +PARTITION BY LIST (level) ( +PARTITION l1 VALUES IN (1), +PARTITION l2 VALUES IN (2), +PARTITION l3 VALUES IN (3), +PARTITION l4 VALUES IN (4), +PARTITION l5 VALUES IN (5)); +ALTER TABLE members DROP PARTITION p1990; +ALTER TABLE member_level DROP PARTITION l5; +ALTER TABLE members TRUNCATE PARTITION p1980; +ALTER TABLE member_level TRUNCATE PARTITION l4; +ALTER TABLE members ADD PARTITION (PARTITION `p1990to2010` VALUES LESS THAN (2010)); +ALTER TABLE member_level ADD PARTITION (PARTITION l5_6 VALUES IN (5,6)); +ALTER TABLE members ADD PARTITION (PARTITION p1990 VALUES LESS THAN (2000)); +Error 1493 (HY000): VALUES LESS THAN value must be strictly increasing for each partition +ALTER TABLE members REORGANIZE PARTITION p1990to2010 INTO +(PARTITION p1990 VALUES LESS THAN (2000), +PARTITION p2000 VALUES LESS THAN (2010), +PARTITION p2010 VALUES LESS THAN (2020), +PARTITION p2020 VALUES LESS THAN (2030), +PARTITION pMax VALUES LESS THAN (MAXVALUE)); +ALTER TABLE member_level REORGANIZE PARTITION l5_6 INTO +(PARTITION l5 VALUES IN (5), +PARTITION l6 VALUES IN (6)); +ALTER TABLE members REORGANIZE PARTITION pBefore1950,p1950 INTO (PARTITION pBefore1960 VALUES LESS THAN (1960)); +ALTER TABLE member_level REORGANIZE PARTITION l1,l2 INTO (PARTITION l1_2 VALUES IN (1,2)); +ALTER TABLE members REORGANIZE PARTITION pBefore1960,p1960,p1970,p1980,p1990,p2000,p2010,p2020,pMax INTO +(PARTITION p1800 VALUES LESS THAN (1900), +PARTITION p1900 VALUES LESS THAN (2000), +PARTITION p2000 VALUES LESS THAN (2100)); +ALTER TABLE member_level REORGANIZE PARTITION l1_2,l3,l4,l5,l6 INTO +(PARTITION lOdd VALUES IN (1,3,5), +PARTITION lEven VALUES IN (2,4,6)); +ALTER TABLE members REORGANIZE PARTITION p1800,p2000 INTO (PARTITION p2000 VALUES LESS THAN (2100)); +Error 8200 (HY000): Unsupported REORGANIZE PARTITION of RANGE; not adjacent partitions +INSERT INTO members VALUES (313, "John", "Doe", "2022-11-22", NULL); +ALTER TABLE members REORGANIZE PARTITION p2000 INTO (PARTITION p2000 VALUES LESS THAN (2050)); +ALTER TABLE members REORGANIZE PARTITION p2000 INTO (PARTITION p2000 VALUES LESS THAN (2020)); +Error 1526 (HY000): Table has no partition for value 2022 +INSERT INTO member_level (id, level) values (313, 6); +ALTER TABLE member_level REORGANIZE PARTITION lEven INTO (PARTITION lEven VALUES IN (2,4)); +Error 1526 (HY000): Table has no partition for value 6 +select @@global.tidb_enable_ddl; +@@global.tidb_enable_ddl +1 +set @@global.tidb_enable_ddl=false; +Error 8246 (HY000): Error happened when disabling DDL: can not disable ddl owner when it is the only one tidb instance +set @@global.tidb_enable_ddl=false; +Error 8246 (HY000): Error happened when disabling DDL: can not disable ddl owner when it is the only one tidb instance +select @@global.tidb_enable_ddl; +@@global.tidb_enable_ddl +1 +drop table if exists t; +create table t (id bigint, b varchar(20), index idxb(b)) partition by range(id) (partition p0 values less than (20), partition p1 values less than (100)); +alter table t reorganize partition p0 into (partition p01 values less than (10), partition p02 values less than (20)); +show warnings; +Level Code Message +Warning 1105 The statistics of related partitions will be outdated after reorganizing partitions. Please use 'ANALYZE TABLE' statement if you want to update it now diff --git a/tests/integrationtest/r/ddl/db_rename.result b/tests/integrationtest/r/ddl/db_rename.result new file mode 100644 index 0000000000000..2b71ae58e7ca0 --- /dev/null +++ b/tests/integrationtest/r/ddl/db_rename.result @@ -0,0 +1,15 @@ +drop table if exists t; +create table t (pk int primary key, c int default 1, c1 int default 1, unique key k1(c), key k2(c1)); +alter table t rename index k1 to k3; +admin check index t k3; + +alter table t rename index k3 to k3; +admin check index t k3; + +alter table t rename index x to x; +Error 1176 (42000): Key 'x' doesn't exist in table 't' +alter table t rename index k3 to k2; +Error 1061 (42000): Duplicate key name 'k2' +alter table t rename index k2 to K2; +alter table t rename key k3 to K2; +Error 1061 (42000): Duplicate key name 'K2' diff --git a/tests/integrationtest/r/ddl/db_table.result b/tests/integrationtest/r/ddl/db_table.result new file mode 100644 index 0000000000000..a94e844175bce --- /dev/null +++ b/tests/integrationtest/r/ddl/db_table.result @@ -0,0 +1,78 @@ +drop table if exists t1,t2,t3,t4; +create table t1 (a int, b int, index(a), index(b)); +create table t2 (c int, foreign key (a) references t1(a)); +Error 1072 (42000): Key column 'a' doesn't exist in table +create table t3 (a int, b int); +alter table t1 add foreign key (c) REFERENCES t3(a); +Error 1072 (42000): Key column 'c' doesn't exist in table +alter table t1 add foreign key (a) REFERENCES t3(a, b); +Error 1239 (42000): Incorrect foreign key definition for 'fk_1': Key reference and table reference don't match +create table t4 (c int,d int,foreign key (d) references t1 (b)); +alter table t4 drop column d; +Error 1828 (HY000): Cannot drop column 'd': needed in a foreign key constraint 'fk_1' +alter table t4 change column d e bigint; +Error 3780 (HY000): Referencing column 'd' and referenced column 'b' in foreign key constraint 'fk_1' are incompatible. +alter table t4 modify column d bigint; +Error 3780 (HY000): Referencing column 'd' and referenced column 'b' in foreign key constraint 'fk_1' are incompatible. +select count(*) from information_schema.KEY_COLUMN_USAGE; +alter table t4 drop foreign key fk_1; +alter table t4 modify column d bigint; +drop table if exists t1,t2,t3,t4; +drop table if exists t; +create table t (c1 int, s1 varchar(10), s2 text); +select count(*) from information_schema.columns where table_schema = 'ddl__db_table' and table_name = 't' and character_set_name != 'utf8mb4'; +count(*) +0 +select count(*) from information_schema.columns where table_schema = 'ddl__db_table' and table_name = 't' and character_set_name = 'utf8mb4'; +count(*) +2 +create table t1(id int) charset=UTF8; +create table t2(id int) charset=BINARY; +create table t3(id int) charset=LATIN1; +create table t4(id int) charset=ASCII; +create table t5(id int) charset=UTF8MB4; +create table t11(id int) charset=utf8; +create table t12(id int) charset=binary; +create table t13(id int) charset=latin1; +create table t14(id int) charset=ascii; +create table t15(id int) charset=utf8mb4; +drop table if exists t1; +create table t1 (c1 int, c2 int as (c1 + 1)); +alter table t1 with validation; +show warnings; +Level Code Message +Warning 8200 ALTER TABLE WITH VALIDATION is currently unsupported +alter table t1 without validation; +show warnings; +Level Code Message +Warning 8200 ALTER TABLE WITHOUT VALIDATION is currently unsupported +drop table if exists t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( `id` int(11) NOT NULL default '0', `id2` int(11) NOT NULL default '0', `id3` int(11) NOT NULL default '0', `dummy1` char(30) default NULL, PRIMARY KEY (`id`,`id2`), KEY `index_id3` (`id3`)); +insert into t1 (id,id2) values (1,1),(1,2),(1,3); +LOCK TABLE t1 WRITE; +select dummy1,count(distinct id) from t1 group by dummy1; +dummy1 count(distinct id) +NULL 1 +update t1 set id=-1 where id=1; +LOCK TABLE t1 READ; +update t1 set id=1 where id=1; +unlock tables; +update t1 set id=1 where id=-1; +drop table t1; +drop table if exists t; +CREATE TABLE t ( +c0 int(11), +c1 int(11), +c2 decimal(16,4) GENERATED ALWAYS AS ((case when (c0 = 0) then 0when (c0 > 0) then (c1 / c0) end)) +); +[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 4 column 83 near "then (c1 / c0) end)) +);" +create table t (a bigint, b int, c int generated always as (b+1)) partition by hash(a) partitions 4; +alter table t drop column a; +Error 3855 (HY000): Column 'a' has a partitioning function dependency and cannot be dropped or renamed +alter table t modify column c int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end)); +[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 97 near "then (b / a) end));" +alter table t add column d int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end)); +[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 94 near "then (b / a) end));" +drop table if exists t; diff --git a/tests/integrationtest/t/ddl/constraint.test b/tests/integrationtest/t/ddl/constraint.test new file mode 100644 index 0000000000000..8a53e8a79ad37 --- /dev/null +++ b/tests/integrationtest/t/ddl/constraint.test @@ -0,0 +1,661 @@ +set @@global.tidb_enable_check_constraint = 1; + +# TestDropColumnWithCheckConstraints +drop table if exists t; +create table t(a int check(a > 0), b int, c int, check(c > 0), check (b > c)); +alter table t drop column a; +show create table t; +-- error 3959 +alter table t drop column b; +-- error 3959 +alter table t rename column c to c1; + +# TestCheckConstraintsNotEnforcedWorks +drop table if exists t; +create table t(a int check(a > 0), b int check(b < 10) not enforced, c int); +alter table t alter constraint t_chk_1 not enforced; +insert into t values(-1, 1, 0); +alter table t alter constraint t_chk_2 enforced; +-- error 3819 +insert into t values(-1, 11, 0); +alter table t add check(c = 0); +-- error 3819 +insert into t values(-1, 1, 1); +alter table t alter constraint t_chk_3 not enforced; +insert into t values(-1, 1, 0); + +# TestUnsupportedCheckConstraintsExprWhenCreateTable +drop table if exists t; +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + NOW() > '2011-11-21')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIMESTAMP() > '2011-11-21 01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIMESTAMP > '2011-11-21 01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + CURDATE() > '2011-11-21')); +-- error 3814 +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + CURTIME() > '23:11:21')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_DATE() > '2011-11-21')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_DATE > '2011-11-21')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIME() > '01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + CURRENT_TIME > '01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + LOCALTIME() > '23:11:21')); +-- error 3814 +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + LOCALTIME > '23:11:21')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + LOCALTIMESTAMP() > '2011-11-21 01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + LOCALTIMESTAMP > '2011-11-21 01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + UNIX_TIMESTAMP() > '2011-11-21 01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + UTC_DATE() > '2011-11-21')); +-- error 3814 +CREATE TABLE t1 (f1 TIMESTAMP CHECK (f1 + UTC_TIMESTAMP() > '2011-11-21 01:02:03')); +-- error 3814 +CREATE TABLE t1 (f1 DATETIME CHECK (f1 + UTC_TIME() > '23:11:21')); +-- error 3814 +CREATE TABLE t1 (f1 INT CHECK (f1 + CONNECTION_ID() < 929)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(32) CHECK (CURRENT_USER() != a)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(32) CHECK (CURRENT_USER != a)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(32) CHECK (SESSION_USER() != a)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(32) CHECK (VERSION() != a)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(1024), b INT CHECK (b + FOUND_ROWS() > 2000)); +-- error 3814 +CREATE TABLE t1 (a INT CHECK ((a + LAST_INSERT_ID()) < 929)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(32) CHECK (SYSTEM_USER() != a)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(32) CHECK (USER() != a)); +-- error 3814 +CREATE TABLE t1 (f1 FLOAT CHECK (f1 + RAND() < 929.929)); +-- error 3814 +CREATE TABLE t1 (a INT CHECK (a + ROW_COUNT() > 1000)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (GET_LOCK(b,10) != 0)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (IS_FREE_LOCK(b) != 0)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (IS_USED_LOCK(b) != 0)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024) CHECK (RELEASE_LOCK(b) != 0)); +-- error 3814 +CREATE TABLE t1 (a VARCHAR(1024), b VARCHAR(1024), CHECK (RELEASE_ALL_LOCKS() != 0)); +-- error 3814 +CREATE TABLE t1 (f1 VARCHAR(1024), f2 VARCHAR(1024) CHECK (LOAD_FILE(f2) != NULL)); +-- error 3814 +CREATE TABLE t1 (id CHAR(40) CHECK(UUID() != id)); +-- error 3814 +CREATE TABLE t1 (id INT CHECK(UUID_SHORT() != id)); +-- error 3814 +CREATE TABLE t1 (id INT CHECK(SLEEP(id) != 0)); +set @a = 1; +-- error 3816 +CREATE TABLE t1 (f1 int CHECK (f1 > @a)); +-- error 3816 +CREATE TABLE t1 (f1 int CHECK (f1 > @@session.tidb_mem_quota_query)); +-- error 3816 +CREATE TABLE t1 (f1 int CHECK (f1 > @@global.tidb_mem_quota_query)); +-- error 3818 +CREATE TABLE t1 (f1 int primary key auto_increment, f2 int, CHECK (f1 != f2)); +-- error 3814 +CREATE TABLE t1 (f1 INT CHECK (f1 = default(f1))); +-- error 3815 +CREATE TABLE t1 (id INT CHECK (id != (SELECT 1))); +-- error 3815 +CREATE TABLE t1 (a int check(a in (SELECT COALESCE(NULL, 1, 1)))); + +# TestUnsupportedCheckConstraintsExprWhenAlterTable +drop table if exists t; +create table t1(f1 TIMESTAMP, f2 DATETIME, f3 INT, f4 VARCHAR(32), f5 FLOAT, f6 CHAR(40), f7 INT PRIMARY KEY AUTO_INCREMENT); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + NOW() > '2011-11-21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIMESTAMP() > '2011-11-21 01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIMESTAMP > '2011-11-21 01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f2 + CURDATE() > '2011-11-21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f2 + CURTIME() > '23:11:21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_DATE() > '2011-11-21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_DATE > '2011-11-21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIME() > '01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + CURRENT_TIME > '01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f2 + LOCALTIME() > '23:11:21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f2 + LOCALTIME > '23:11:21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + LOCALTIMESTAMP() > '2011-11-21 01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + LOCALTIMESTAMP > '2011-11-21 01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + UNIX_TIMESTAMP() > '2011-11-21 01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f2 + UTC_DATE() > '2011-11-21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 + UTC_TIMESTAMP() > '2011-11-21 01:02:03'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f2 + UTC_TIME() > '23:11:21'); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f3 + CONNECTION_ID() < 929); +-- error 3814 +ALTER TABLE t1 ADD CHECK (CURRENT_USER() != f4); +-- error 3814 +ALTER TABLE t1 ADD CHECK (CURRENT_USER != f4); +-- error 3814 +ALTER TABLE t1 ADD CHECK (SESSION_USER() != f4); +-- error 3814 +ALTER TABLE t1 ADD CHECK (VERSION() != f4); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f3 + FOUND_ROWS() > 2000); +-- error 3814 +ALTER TABLE t1 ADD CHECK ((f3 + LAST_INSERT_ID()) < 929); +-- error 3814 +ALTER TABLE t1 ADD CHECK (SYSTEM_USER() != f4); +-- error 3814 +ALTER TABLE t1 ADD CHECK (USER() != f4); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f5 + RAND() < 929.929); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f3 + ROW_COUNT() > 1000); +-- error 3814 +ALTER TABLE t1 ADD CHECK (GET_LOCK(f4,10) != 0); +-- error 3814 +ALTER TABLE t1 ADD CHECK (IS_FREE_LOCK(f4) != 0); +-- error 3814 +ALTER TABLE t1 ADD CHECK (IS_USED_LOCK(f4) != 0); +-- error 3814 +ALTER TABLE t1 ADD CHECK (RELEASE_LOCK(f4) != 0); +-- error 3814 +ALTER TABLE t1 ADD CHECK (RELEASE_ALL_LOCKS() != 0); +-- error 3814 +ALTER TABLE t1 ADD CHECK (LOAD_FILE(f4) != NULL); +-- error 3814 +ALTER TABLE t1 ADD CHECK(UUID() != f6); +-- error 3814 +ALTER TABLE t1 ADD CHECK(UUID_SHORT() != f3); +-- error 3814 +ALTER TABLE t1 ADD CHECK(SLEEP(f3) != 0); +set @a = 1; +-- error 3816 +ALTER TABLE t1 ADD CHECK (f3 > @a); +-- error 3816 +ALTER TABLE t1 ADD CHECK (f3 > @@session.tidb_mem_quota_query); +-- error 3816 +ALTER TABLE t1 ADD CHECK (f3 > @@global.tidb_mem_quota_query); +-- error 3818 +ALTER TABLE t1 ADD CHECK (f7 != f3); +-- error 3814 +ALTER TABLE t1 ADD CHECK (f1 = default(f1)); +-- error 3815 +ALTER TABLE t1 ADD CHECK (f3 != (SELECT 1)); +-- error 3815 +ALTER TABLE t1 ADD check (f3 in (SELECT COALESCE(NULL, 1, 1))); + +# TestNameInCreateTableLike +drop table if exists t, s; +create table t(a int check(a > 10), b int constraint bbb check(b > 5), c int, check(c < 0)); +create table s like t; +show create table s; +-- error 3819 +insert into s(a) values(1); +-- error 3819 +insert into s(b) values(2); +-- error 3819 +insert into s(c) values(3); +alter table s add check(a > 0); +alter table s add constraint aaa check(a > 0); +show create table s; + +# TestInsertUpdateIgnoreWarningMessage +drop table if exists t; +create table t(a int check(a > 10)); +-- error 3819 +insert into t values(1),(11),(15); +insert ignore into t values(1),(11),(15); +show warnings; +select a from t; +update ignore t set a = a-2; +show warnings; +select a from t; + +# TestCheckConstraintForeignKey +drop table if exists t, s, t1, t2; +create table t(a int, b int, index(a), index(a, b)); +-- error 3823 +create table s(a int, check (a > 0), foreign key (a) references t(a) on update cascade); +-- error 3823 +create table s(a int, b int, check (a > 0), foreign key (a, b) references t(a, b) on update cascade); +create table t1(a int, foreign key (a) references t(a) on update cascade); +-- error 3823 +alter table t1 add check ( a > 0 ); +create table t2(a int, b int, foreign key (a, b) references t(a, b) on update cascade); +-- error 3823 +alter table t2 add check ( a > 0 ); +drop table t, t1, t2; + +# TestCheckConstrainNonBoolExpr +drop table if exists t; +-- error 3812 +create table t(a int, check(a)); +-- error 3812 +create table t(a int, check(1)); +-- error 3812 +create table t(a int, check('1')); +-- error 3812 +create table t(a int check(a)); +-- error 3812 +create table t(a int, check(1+1)); +-- error 3812 +create table t(a int, check(1/2)); +-- error 3812 +create table t(a int, check(a + 1/2)); +-- error 3812 +create table t(a int check(a + 1/2)); +-- error 3812 +create table t(a int, check(true + 1)); +-- error 3812 +create table t(a int, check(abs(1))); +-- error 3812 +create table t(a int, check(length(a))); +-- error 3812 +create table t(a int, check(length(1))); +-- error 3812 +create table t(a int, check(floor(1.1))); +-- error 3812 +create table t(a int, check(mod(3, 2))); +-- error 3812 +create table t(a int, check('true')); +create table t(a int, check(true)); +-- error 3812 +alter table t add check(a); +-- error 3812 +alter table t add check(1); +-- error 3812 +alter table t add check('1'); +-- error 3812 +alter table t add check(1/2); +-- error 3812 +alter table t add check(a + 1/2); +-- error 3812 +alter table t add check(true + 1); +-- error 3812 +alter table t add check(abs(1)); +-- error 3812 +alter table t add check(length(a)); +-- error 3812 +alter table t add check(length(1)); +-- error 3812 +alter table t add check(length(1)); +-- error 3812 +alter table t add check(mod(3, 2)); +-- error 3812 +alter table t add check('true'); + +# TestAlterAddCheckConstrainColumnBadErr +drop table if exists t; +create table t(a int); +-- error 1054 +alter table t add check(b > 0); + +# TestCheckConstraintBoolExpr +drop table if exists t; +create table t(a json, b varchar(20)); +alter table t add check (JSON_VALID(a)); +alter table t add check (REGEXP_LIKE(b,'@')); + +# TestCheckConstraintNameMaxLength +drop table if exists t; +create table t(a int constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +drop table t; +create table t(a int, constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +drop table t; +-- error 1059 +create table t(a int constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +-- error 1059 +create table t(a int, constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0)); +-- error 1059 +create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int check(a > 0)); +-- error 1059 +create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int, check(a > 0)); +create table t(a int); +-- error 1059 +alter table t add constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0); +alter table t add constraint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa check(a > 0); +drop table t; +create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int); +-- error 1059 +alter table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa add check(a > 0); + +# TestCheckConstraintNameCaseAndAccentSensitivity +drop table if exists t; +create table t(a int); +alter table t add constraint `cafe` check(a > 0); +-- error 3822 +alter table t add constraint `CAFE` check(a > 0); +alter table t add constraint `café` check(a > 0); + +# TestCheckConstraintEvaluated +drop table if exists t, s; +create table t(a int check(a > 0)); +insert into t values(1); +create table s(a int); +insert into s values(-1); +-- error 3819 +insert into t values(-1); +insert into t values(1); +-- error 3819 +insert into t(a) values(-1); +insert into t(a) values(1); +-- error 3819 +insert into t set a = -1; +insert into t set a = 1; +-- error 3819 +insert into t(a) select -1; +insert into t(a) select 1; +-- error 3819 +insert into t(a) select a from s; +insert into t(a) select a + 2 from s; +-- error 3819 +update t set a = -1; +update t set a = 1; +-- error 3819 +update t set a = a-1; +update t set a = a+1; +-- error 3819 +update t set a = -1 where a > 0; +update t set a = 1 where a > 0; +-- error 3819 +update t set a = (select a from s where a < 0) where a > 0; +update t set a = (select a + 2 from s where a < 0) where a > 0; +-- error 3819 +update t as a, s as b set a.a=b.a; +update t as a, s as b set a.a=b.a + 2; +-- error 3819 +replace into t(a) values(-1); +replace into t(a) values(1); +-- error 3819 +replace into t(a) select -1; +replace into t(a) select 1; +-- error 3819 +replace into t set a = -1; +replace into t set a = 1; + +# TestGenerateColumnCheckConstraint +drop table if exists t; +create table t( a int, b int as (a+1), CHECK (b > 0)); +insert into t(a) values(0); +-- error 3819 +insert into t(a) values(-2); +show create table t; +alter table t alter constraint t_chk_1 not enforced; +insert into t(a) values(-2); +alter table t drop constraint t_chk_1; +drop table t; +create table t(a int, b int as (a+1)); +alter table t add check(b > 0); +insert into t(a) values(0); +-- error 3819 +insert into t(a) values(-2); +alter table t alter constraint t_chk_1 not enforced; +insert into t(a) values(-2); +alter table t drop constraint t_chk_1; +-- error 3819 +alter table t add check(b > 0); + +# TestTemporaryTableCheckConstraint +drop table if exists t; +create table t(a int, CHECK (a < -999)); +drop temporary table if exists t; +create temporary table t(a int, CHECK (a > 0)); +insert into t(a) values(1); +-- error 3819 +insert into t(a) values(-2); +drop temporary table t; +create temporary table t(a int, CHECK (a > 0) not enforced); +insert into t values(-1); +create global temporary table tt(a int, check(a > 0)) on commit delete rows; +insert into tt(a) values(1); +-- error 3819 +insert into tt(a) values(-2); +alter table tt alter constraint tt_chk_1 not enforced; +insert into tt(a) values(-2); +alter table tt drop constraint tt_chk_1; +drop temporary table t; +drop global temporary table tt; + +# TestCheckConstraintWithPrepareInsertCheckConstraint +drop table if exists t; +create table t(a int CHECK (a != 0)); +prepare stmt from 'insert into t values(?)'; +set @a = 1; +execute stmt using @a; +set @a = 0; +-- error 3819 +execute stmt using @a; +deallocate prepare stmt; + +# TestCheckConstraintOnDuplicateKeyUpdate +drop table if exists t, s; +create table t(a int primary key, b int, check (b > 0)); +insert into t values(1, 1); +-- error 3819 +insert into t values(1, -10) on duplicate key update b = -1; +insert ignore into t values(1, -10) on duplicate key update b = -1; +select * from t; +create table s(a int primary key, check (a > 0)); +insert into s values(1); +-- error 3819 +insert into s values(1) on duplicate key update a = -1; +insert ignore into s values(1) on duplicate key update a = -1; +select * from s; + +# TestCheckConstraintOnInsert +drop table if exists t1, t2; +CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0)); +-- error 3819 +insert into t1 values (2, 2); +-- error 3819 +insert into t1 values (9, 2); +-- error 3819 +insert into t1 values (14, -4); +-- error 3819 +insert into t1(c1) values (9); +-- error 3819 +insert into t1(c2) values (-3); +insert into t1 values (14, 4); +insert into t1 values (null, 4); +insert into t1 values (13, null); +insert into t1 values (null, null); +insert into t1(c1) values (null); +insert into t1(c2) values (null); +CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15)); +-- error 3819 +insert into t2(c1, c2) values (11, 1); +insert into t2(c1, c2) values (12, 7); + +# TestCheckConstraintOnUpdate +drop table if exists t1, t2; +CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0)); +insert into t1 values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +-- error 3819 +update t1 set c2 = -c2; +-- error 3819 +update t1 set c2 = c1; +-- error 3819 +update t1 set c1 = c1 - 10; +-- error 3819 +update t1 set c2 = -10 where c2 = 12; +CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15)); +insert into t2(c1, c2) values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +-- error 3819 +update t2 set c2 = c2 - 10; +update t2 set c2 = c2 - 5; + +# TestCheckConstraintOnUpdateWithPartition +drop table if exists t1, t2; +CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0)) partition by hash(c2) partitions 5; +insert into t1 values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +-- error 3819 +update t1 set c2 = -c2; +-- error 3819 +update t1 set c2 = c1; +-- error 3819 +update t1 set c1 = c1 - 10; +-- error 3819 +update t1 set c2 = -10 where c2 = 12; +CREATE TABLE t2 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 int as (c1 + c2) check(c3 > 15)) partition by hash(c2) partitions 5; +insert into t2(c1, c2) values (11, 12), (12, 13), (13, 14), (14, 15), (15, 16); +-- error 3819 +update t2 set c2 = c2 - 10; +update t2 set c2 = c2 - 5; + +# TestShowCheckConstraint +drop table if exists t; +create table t(a int check (a>1), b int, constraint my_constr check(a<10)); +show create table t; +alter table t add constraint my_constr2 check (a 0)); +show warnings; +show create table t; +drop table t; +set @@global.tidb_enable_check_constraint = 1; +create table t(a int check(a > 0)); +show warnings; +show create table t; +alter table t add constraint chk check(true); +show warnings; +alter table t alter constraint chk not enforced; +show warnings; +alter table t drop constraint chk; +show warnings; +set @@global.tidb_enable_check_constraint = 0; +alter table t drop constraint t_chk_1; +show warnings; +alter table t alter constraint t_chk_1 not enforced; +show warnings; +show create table t; +set @@global.tidb_enable_check_constraint = 1; + +# TestCreateTableWithCheckConstraints +drop table if exists t; +create table t(a int not null check(a>0)); +show create table t; +drop table t; +create table t(a bigint key constraint my_constr check(a<10), b int constraint check(b > 1) not enforced); +show create table t; +drop table t; +create table t(a int constraint check(a > 1) not enforced, constraint my_constr check(a < 10)); +show create table t; +drop table t; +-- error 3813 +create table t(a int not null check(b>0)); +-- error 3813 +create table t(a int not null check(b>a)); +-- error 3820 +create table t(a int not null check(a>0), b int, constraint check(c>b)); +create table t(a int not null check(a>0), b int, constraint check(a>b)); +show create table t; +drop table t; +create table t(a int not null check(a > '12345')); +show create table t; +drop table t; +create table t(a int not null primary key check(a > '12345')); +show create table t; +drop table t; +create table t(a varchar(10) not null primary key check(a > '12345')); +show create table t; +drop table t; + +# TestAlterTableAddCheckConstraints +drop table if exists t; +create table t(a int not null check(a>0)); +alter table t add constraint haha check(a<10); +show create table t; +alter table t add constraint check(a<11) not enforced; +show create table t; +-- error 3822 +alter table t add constraint haha check(a); +-- error 1054 +alter table t add constraint check(b); +alter table t add constraint check(a*2 < a+1) not enforced; +drop table t; +create table t(a int); +insert into t values(1), (2), (3); +-- error 3819 +alter table t add constraint check(a < 2); +-- error 3819 +alter table t add constraint check(a < 2) not enforced; + +# TestAlterTableDropCheckConstraints +drop table if exists t; +set @@global.tidb_enable_check_constraint = 1; +create table t(a int not null check(a>0), b int, constraint haha check(a < b), check(a 0)); +-- error 3819 +insert into t values(0); +alter table t drop constraint t_chk_1; +insert into t values(0); + +# TestAlterTableAlterCheckConstraints +drop table if exists t; +set @@global.tidb_enable_check_constraint = 1; +create table t(a int not null check(a>0) not enforced, b int, constraint haha check(a < b)); +show create table t; +-- error 3940 +alter table t alter constraint unknown not enforced; +alter table t alter constraint haha not enforced; +show create table t; +alter table t alter constraint t_chk_1 enforced; +show create table t; +# Alter table alter constraint will violate check. +# Here a=1, b=0 doesn't satisfy "a < b" constraint. +# Since "a'$.a' as char(255)))); +select * from t force index(idx); +select * from t ignore index(idx); +alter table t add index idx1((cast(b->>'$.a' as char(255)))); +select * from t force index(idx1); +select * from t ignore index(idx1); +alter table t add index idx2((json_type(b))); +select * from t force index(idx2) where json_type(b) = 'OBJECT'; +select * from t ignore index(idx2) where json_type(b) = 'OBJECT'; +-- error 3753 +alter table t add index idx_wrong((b->'$.a')); +-- error 3757 +alter table t add index idx_wrong((b->>'$.a')); +-- error 3757 +alter table t add index idx_wrong((json_pretty(b))); +drop table if exists t; +-- error 1071 +create table t(a char(255), index idx((json_quote(a)))); +create table t(a char(40)); +insert into t values ('[1, 2, 3]'); +alter table t add index idx3((json_quote(a))); +select * from t force index(idx3) where json_quote(a) = '"[1, 2, 3]"'; +select * from t ignore index(idx3) where json_quote(a) = '"[1, 2, 3]"'; +drop table if exists t; +create table t(a int, b json); +-- error 3753 +alter table t add index idx_wrong((json_array(b))); +-- error 3753 +alter table t add index idx_wrong((json_object('key', b))); +-- error 3753 +alter table t add index idx_wrong((json_merge_preserve(b, '{"k": "v"}'))); +-- error 3753 +alter table t add index idx_wrong((json_set(b, '$.a', 'v'))); +-- error 3753 +alter table t add index idx_wrong((json_insert(b, '$.a', 'v'))); +-- error 3753 +alter table t add index idx_wrong((json_replace(b, '$.a', 'v'))); +-- error 3753 +alter table t add index idx_wrong((json_remove(b, '$.a'))); +-- error 3753 +alter table t add index idx_wrong((json_array_append(b, '$.a', 1))); +-- error 3753 +alter table t add index idx_wrong((json_merge_patch(b, '{"k": "v"}'))); +-- error 3753 +alter table t add index idx_wrong((json_search(b, 'one', 'a'))); +-- error 3753 +alter table t add index idx_wrong((json_keys(b))); +drop table if exists t; +create table t(a int, b json); +insert into t values (1, '{"a": 1}'); +alter table t add index idx0((json_type(json_search(b, 'one', 'a')))); +alter table t add index idx1((json_type(json_array(b)))); +alter table t add index idx2((json_type(json_object('key', b)))); +alter table t add index idx3((json_type(json_merge_preserve(b, '{"k": "v"}')))); +alter table t add index idx4((json_type(json_set(b, '$.a', 'v')))); +alter table t add index idx5((json_type(json_insert(b, '$.a', 'v')))); +alter table t add index idx6((json_type(json_replace(b, '$.a', 'v')))); +alter table t add index idx7((json_type(json_remove(b, '$.a')))); +alter table t add index idx8((json_type(json_array_append(b, '$.a', 1)))); +alter table t add index idx9((json_type(json_merge_patch(b, '{"k": "v"}')))); +alter table t add index idx10((json_type(json_keys(b)))); +alter table t add index idx11((cast(json_quote(cast(a as char(10))) as char(64)))); +alter table t add index idx12((json_storage_size(b))); +alter table t add index idx13((json_depth(b))); +alter table t add index idx14((json_length(b))); +select * from t force index(idx0) where json_type(json_search(b, 'one', 'a')) is NULL; +select * from t force index(idx1) where json_type(json_array(b)) = 'ARRAY'; +select * from t force index(idx2) where json_type(json_object('key', b)) = 'OBJECT'; +select * from t force index(idx3) where json_type(json_merge_preserve(b, '{"k": "v"}')) = 'OBJECT'; +select * from t force index(idx4) where json_type(json_set(b, '$.a', 'v')) = 'OBJECT'; +select * from t force index(idx5) where json_type(json_insert(b, '$.a', 'v')) = 'OBJECT'; +select * from t force index(idx6) where json_type(json_replace(b, '$.a', 'v')) = 'OBJECT'; +select * from t force index(idx7) where json_type(json_remove(b, '$.a')) = 'OBJECT'; +select * from t force index(idx8) where json_type(json_array_append(b, '$.a', 1)) = 'OBJECT'; +select * from t force index(idx9) where json_type(json_merge_patch(b, '{"k": "v"}')) = 'OBJECT'; +select * from t force index(idx10) where json_type(json_keys(b)) = 'ARRAY'; +select * from t force index(idx11) where cast(json_quote(cast(a as char(10))) as char(64)) = '"1"'; +select * from t force index(idx12) where json_storage_size(b) > 1; +select * from t force index(idx13) where json_depth(b) > 0; +select * from t force index(idx14) where json_length(b) > 0; +select * from t ignore index(idx0) where json_type(json_search(b, 'one', 'a')) is NULL; +select * from t ignore index(idx1) where json_type(json_array(b)) = 'ARRAY'; +select * from t ignore index(idx2) where json_type(json_object('key', b)) = 'OBJECT'; +select * from t ignore index(idx3) where json_type(json_merge_preserve(b, '{"k": "v"}')) = 'OBJECT'; +select * from t ignore index(idx4) where json_type(json_set(b, '$.a', 'v')) = 'OBJECT'; +select * from t ignore index(idx5) where json_type(json_insert(b, '$.a', 'v')) = 'OBJECT'; +select * from t ignore index(idx6) where json_type(json_replace(b, '$.a', 'v')) = 'OBJECT'; +select * from t ignore index(idx7) where json_type(json_remove(b, '$.a')) = 'OBJECT'; +select * from t ignore index(idx8) where json_type(json_array_append(b, '$.a', 1)) = 'OBJECT'; +select * from t ignore index(idx9) where json_type(json_merge_patch(b, '{"k": "v"}')) = 'OBJECT'; +select * from t ignore index(idx10) where json_type(json_keys(b)) = 'ARRAY'; +select * from t ignore index(idx11) where cast(json_quote(cast(a as char(10))) as char(64)) = '"1"'; +select * from t ignore index(idx12) where json_storage_size(b) > 1; +select * from t ignore index(idx13) where json_depth(b) > 0; +select * from t ignore index(idx14) where json_length(b) > 0; + +# TestAddExpressionIndexOnPartition +drop table if exists t; +create table t( + a int, + b varchar(100), + c int) + PARTITION BY RANGE ( a ) ( + PARTITION p0 VALUES LESS THAN (6), + PARTITION p1 VALUES LESS THAN (11), + PARTITION p2 VALUES LESS THAN (16), + PARTITION p3 VALUES LESS THAN (21) + ); +insert into t values (1, 'test', 2), (12, 'test', 3), (15, 'test', 10), (20, 'test', 20); +alter table t add index idx((a+c)); +show create table t; +--sorted_result +select * from t order by a; + +# TestCreateTableWithAutoIdCache test the auto_id_cache table option. +# `auto_id_cache` take effects on handle too when `PKIshandle` is false, +# or even there is no auto_increment column at all. +drop table if exists t; +drop table if exists t1; +create table t(a int auto_increment key clustered) auto_id_cache 100; +show create table t; +insert into t values(); +select * from t; +delete from t; +rename table t to t1; +insert into t1 values(); +select * from t1; +drop table if exists t; +drop table if exists t1; +create table t(a int) auto_id_cache 100; +insert into t values(); +select _tidb_rowid from t; +delete from t; +rename table t to t1; +insert into t1 values(); +select _tidb_rowid from t1; +drop table if exists t; +drop table if exists t1; +create table t(a int null, b int auto_increment unique) auto_id_cache 100; +insert into t(b) values(NULL); +select b, _tidb_rowid from t; +delete from t; +rename table t to t1; +insert into t1(b) values(NULL); +select b, _tidb_rowid from t1; +delete from t1; +alter table t1 auto_id_cache 200; +show create table t1; +insert into t1(b) values(NULL); +select b, _tidb_rowid from t1; +delete from t1; +rename table t1 to t; +insert into t(b) values(NULL); +select b, _tidb_rowid from t; +delete from t; +drop table if exists t; +drop table if exists t1; +create table t(a int auto_increment key clustered) auto_id_cache 3; +show create table t; +insert into t(a) values(NULL),(NULL),(NULL); +insert into t(a) values(NULL); +select a from t; +delete from t; +rename table t to t1; +insert into t1(a) values(NULL); +select a from t1; +drop table if exists t; +-- error 1105 +create table t(a int) auto_id_cache = 9223372036854775808; +create table t(a int) auto_id_cache = 9223372036854775807; +-- error 1105 +alter table t auto_id_cache = 9223372036854775808; + +# TestAlterIndexVisibility +drop table if exists t, t1, t2, t3; +create table t(a int NOT NULL, b int, key(a), unique(b) invisible); +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +alter table t alter index a invisible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +alter table t alter index b visible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +alter table t alter index b invisible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't' order by index_name; +-- error 1176 +alter table t alter index non_exists_idx visible; +create table t1(a int NOT NULL, unique(a)); +-- error 3522 +alter table t1 alter index a invisible; +create table t2(a int, primary key(a)); +-- error 1064 +alter table t2 alter index PRIMARY invisible; +create table t3(a int NOT NULL, b int); +alter table t3 add index idx((a+b)); +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't3' order by index_name; +alter table t3 alter index idx invisible; +select distinct index_name, is_visible from information_schema.statistics where table_schema = 'ddl__db_integration' and table_name = 't3' order by index_name; + +# TestDropLastVisibleColumnOrColumns +drop table if exists t_drop_last_column, t_drop_last_columns; +create table t_drop_last_column(x int, key((1+1))); +-- error 1113 +alter table t_drop_last_column drop column x; +create table t_drop_last_columns(x int, y int, key((1+1))); +-- error 1113 +alter table t_drop_last_columns drop column x, drop column y; +drop table if exists t_drop_last_column, t_drop_last_columns; + +# TestIssue20741WithSetField +drop table if exists issue20741_2; +create table issue20741_2(id int primary key, c int); +insert into issue20741_2(id, c) values(1, 2), (2, 2); +alter table issue20741_2 add column cc set('a', 'b', 'c', 'd') not null; +update issue20741_2 set c=2 where id=1; +select * from issue20741_2; +select * from issue20741_2 where cc = 0; +select * from issue20741_2 where cc = 1; +-- error 1364 +insert into issue20741_2(id, c) values (3, 3); + +# TestIssue21835 +drop table if exists t; +-- error 1427 +create table t( col decimal(1,2) not null default 0); + +# TestPlacementOnTemporaryTable +drop table if exists tplacement1, tplacement2; +drop database if exists db2; +drop placement policy if exists x; +create placement policy x primary_region='r1' regions='r1'; +-- error 8006 +create temporary table tplacement2 (id int) placement policy='x'; +create global temporary table tplacement1 (id int) on commit delete rows; +-- error 8006 +alter table tplacement1 placement policy='x'; +create temporary table tplacement2 (id int); +-- error 8200 +alter table tplacement2 placement policy='x'; +create database db2 placement policy x; +create global temporary table db2.tplacement3 (id int) on commit delete rows; +show create table db2.tplacement3; +create temporary table db2.tplacement4 (id int); +show create table db2.tplacement4; +create table db2.t1 (a int) placement policy 'default'; +create global temporary table db2.tplacement5 like db2.t1 on commit delete rows; +show create table db2.tplacement5; +create temporary table db2.tplacement6 like db2.t1; +show create table db2.tplacement6; +drop table db2.tplacement6; +drop table db2.tplacement5; +drop table db2.t1; +drop table db2.tplacement3; +drop database db2; +drop table tplacement1, tplacement2; +drop placement policy x; + +# TestDropWithGlobalTemporaryTableKeyWord +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2; +create table tb(id int); +create table tb2(id int); +create global temporary table temp(id int) on commit delete rows; +create global temporary table temp1(id int) on commit delete rows; +create temporary table ltemp1(id int); +create temporary table ltemp2(id int); +-- error 8007 +drop global temporary table tb; +-- error 8007 +drop global temporary table ddl__db_integration.tb; +-- error 8007 +drop global temporary table ltemp1; +-- error 8007 +drop global temporary table ddl__db_integration.ltemp1; +-- error 8007 +drop global temporary table ltemp1, temp; +-- error 8007 +drop global temporary table temp, ltemp1; +-- error 8007 +drop global temporary table xxx, ltemp1; +-- error 1051 +drop global temporary table xxx; +-- error 8007 +drop global temporary table if exists tb; +-- error 8007 +drop global temporary table if exists ltemp1; +drop global temporary table if exists xxx; +show warnings; +-- error 8007 +drop global temporary table if exists xxx,tb; +-- error 8007 +drop global temporary table if exists ddl__db_integration.tb; +drop global temporary table temp; +-- error 1146 +select * from temp; +drop global temporary table ddl__db_integration.temp1; +-- error 1146 +select * from temp2; +create global temporary table temp (id int) on commit delete rows; +create global temporary table temp1 (id int) on commit delete rows; +drop global temporary table temp, temp1; +-- error 1146 +select * from temp; +-- error 1146 +select * from temp1; +create global temporary table temp (id int) on commit delete rows; +create global temporary table temp1 (id int) on commit delete rows; +drop global temporary table if exists temp; +show warnings; +-- error 1146 +select * from temp; +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2; + +# TestDropWithLocalTemporaryTableKeyWord +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2, testt.ltemp3; +create table tb(id int); +create table tb2(id int); +insert into tb2 values(1); +create temporary table tb2(id int); +create global temporary table temp(id int) on commit delete rows; +create global temporary table temp1(id int) on commit delete rows; +create temporary table ltemp1(id int); +create temporary table ltemp2(id int); +create database if not exists testt; +create temporary table testt.ltemp3(id int); +-- error 1051 +drop temporary table tb; +-- error 1051 +drop temporary table ddl__db_integration.tb; +-- error 1051 +drop temporary table temp1; +-- error 1051 +drop temporary table ddl__db_integration.temp1; +-- error 1051 +drop temporary table ltemp1, tb; +-- error 1051 +drop temporary table temp, ltemp1; +-- error 1051 +drop temporary table xxx, ltemp1; +-- error 1051 +drop temporary table xxx; +drop temporary table if exists xxx; +show warnings; +drop temporary table if exists ltemp1, xxx; +show warnings; +drop temporary table if exists tb1, xxx; +show warnings; +drop temporary table if exists temp1; +show warnings; +drop temporary table if exists temp1, xxx; +show warnings; +drop temporary table if exists testt.ltemp4; +show warnings; +drop temporary table if exists testt.ltemp3, tb1; +show warnings; +drop temporary table ltemp1; +-- error 1146 +select * from ltemp1; +drop temporary table ddl__db_integration.ltemp2; +-- error 1146 +select * from ltemp2; +drop temporary table tb2; +select * from tb2; +create temporary table ltemp1 (id int); +create temporary table ltemp2 (id int); +drop temporary table testt.ltemp3, ltemp1; +-- error 1146 +select * from testt.ltemp3; +-- error 1146 +select * from ltemp1; +drop temporary table if exists ltemp2; +show warnings; +-- error 1146 +select * from ltemp2; +drop table if exists tb, tb2, temp, temp1, ltemp1, ltemp2, testt.ltemp3; +drop database testt; + +# TestIssue29326 +drop table if exists t1; +create table t1 (id int); +insert into t1 values(1); +drop table if exists t2; +create table t2 (id int); +insert into t2 values(1); +drop view if exists v1; +create view v1 as select 1,1; +select * from v1; +drop view if exists v1; +create view v1 as select 1, 2, 1, 2, 1, 2, 1, 2; +select * from v1; +drop view if exists v1; +create view v1 as select 't', 't', 1 as t; +select * from v1; +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1, 1 union all select 1, 1; +show create view v1; +select * from v1; +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 'id', id from t1; +show create view v1; +select * from v1; +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1, (select id from t1 where t1.id=t2.id) as '1' from t2; +show create view v1; +select * from v1; +drop view if exists v1; +create definer=`root`@`127.0.0.1` view v1 as select 1 as 'abs(t1.id)', abs(t1.id) from t1; +show create view v1; +select * from v1; +drop view if exists v1; +-- error 1060 +create definer=`root`@`127.0.0.1` view v1 as select 1 as t,1 as t; +drop view if exists v1; +-- error 1060 +create definer=`root`@`127.0.0.1` view v1 as select 1 as id, id from t1; +drop view if exists v1; +-- error 1060 +create definer=`root`@`127.0.0.1` view v1 as select * from t1 left join t2 on t1.id=t2.id; +drop view if exists v1; +-- error 1060 +create definer=`root`@`127.0.0.1` view v1 as select t1.id, t2.id from t1,t2 where t1.id=t2.id; +drop view if exists v1; +drop table t2; +drop table t1; + +# TestInvalidPartitionNameWhenCreateTable +drop table if exists t; +-- error 1567 +create table t(a int) partition by range (a) (partition p0 values less than (0), partition `p1 ` values less than (3)); +-- error 1567 +create table t(a int) partition by range (a) (partition `` values less than (0), partition `p1` values less than (3)); +create table t(a int) partition by range (a) (partition `p0` values less than (0), partition `p1` values less than (3)); +-- error 1567 +alter table t add partition (partition `p2 ` values less than (5)); + +# TestRegexpFunctionsGeneratedColumn +drop table if exists reg_like; +create table reg_like(a varchar(50), b varchar(50), c int generated always as (regexp_like(a, b))); +insert into reg_like(a, b) values('123', '2'); +insert into reg_like(a, b) values('456', '1'); +select * from reg_like; +drop table if exists reg_sub; +create table reg_sub(a varchar(50),b varchar(50),c varchar(50) generated always as (regexp_substr(a, b))); +insert into reg_sub(a, b) values('abcd', 'bc.'); +insert into reg_sub(a, b) values('1234', '23.'); +select * from reg_sub; +drop table if exists reg_instr; +create table reg_instr(a varchar(50),b varchar(50),c varchar(50) generated always as (regexp_instr(a, b))); +insert into reg_instr(a, b) values('abcd', 'bc.'); +insert into reg_instr(a, b) values('1234', '23.'); +select * from reg_instr; +drop table if exists reg_replace; +create table reg_replace(a varchar(50),b varchar(50),c varchar(50),d varchar(50) generated always as (regexp_replace(a, b, c))); +insert into reg_replace(a, b, c) values('abcd', 'bc.', 'xzx'); +insert into reg_replace(a, b, c) values('1234', '23.', 'xzx'); +select * from reg_replace; +drop table if exists reg_like; + +# TestReorgPartitionRangeFailure +drop table if exists t; +CREATE TABLE t (id int, d varchar(255)) partition by range (id) (partition p0 values less than (1000000), partition p1 values less than (2000000), partition p2 values less than (3000000)); +-- error 8200 +ALTER TABLE t REORGANIZE PARTITION p0,p2 INTO (PARTITION p0 VALUES LESS THAN (1000000)); +-- error 8200 +ALTER TABLE t REORGANIZE PARTITION p0,p2 INTO (PARTITION p0 VALUES LESS THAN (4000000)); + +# TestReorgPartitionDocs +drop table if exists members, member_level; +CREATE TABLE members ( + id int, + fname varchar(255), + lname varchar(255), + dob date, + data json +) +PARTITION BY RANGE (YEAR(dob)) ( + PARTITION pBefore1950 VALUES LESS THAN (1950), + PARTITION p1950 VALUES LESS THAN (1960), + PARTITION p1960 VALUES LESS THAN (1970), + PARTITION p1970 VALUES LESS THAN (1980), + PARTITION p1980 VALUES LESS THAN (1990), + PARTITION p1990 VALUES LESS THAN (2000)); +CREATE TABLE member_level ( + id int, + level int, + achievements json +) +PARTITION BY LIST (level) ( + PARTITION l1 VALUES IN (1), + PARTITION l2 VALUES IN (2), + PARTITION l3 VALUES IN (3), + PARTITION l4 VALUES IN (4), + PARTITION l5 VALUES IN (5)); +ALTER TABLE members DROP PARTITION p1990; +ALTER TABLE member_level DROP PARTITION l5; +ALTER TABLE members TRUNCATE PARTITION p1980; +ALTER TABLE member_level TRUNCATE PARTITION l4; +ALTER TABLE members ADD PARTITION (PARTITION `p1990to2010` VALUES LESS THAN (2010)); +ALTER TABLE member_level ADD PARTITION (PARTITION l5_6 VALUES IN (5,6)); +-- error 1493 +ALTER TABLE members ADD PARTITION (PARTITION p1990 VALUES LESS THAN (2000)); +ALTER TABLE members REORGANIZE PARTITION p1990to2010 INTO +(PARTITION p1990 VALUES LESS THAN (2000), + PARTITION p2000 VALUES LESS THAN (2010), + PARTITION p2010 VALUES LESS THAN (2020), + PARTITION p2020 VALUES LESS THAN (2030), + PARTITION pMax VALUES LESS THAN (MAXVALUE)); +ALTER TABLE member_level REORGANIZE PARTITION l5_6 INTO +(PARTITION l5 VALUES IN (5), + PARTITION l6 VALUES IN (6)); +ALTER TABLE members REORGANIZE PARTITION pBefore1950,p1950 INTO (PARTITION pBefore1960 VALUES LESS THAN (1960)); +ALTER TABLE member_level REORGANIZE PARTITION l1,l2 INTO (PARTITION l1_2 VALUES IN (1,2)); +ALTER TABLE members REORGANIZE PARTITION pBefore1960,p1960,p1970,p1980,p1990,p2000,p2010,p2020,pMax INTO +(PARTITION p1800 VALUES LESS THAN (1900), + PARTITION p1900 VALUES LESS THAN (2000), + PARTITION p2000 VALUES LESS THAN (2100)); +ALTER TABLE member_level REORGANIZE PARTITION l1_2,l3,l4,l5,l6 INTO +(PARTITION lOdd VALUES IN (1,3,5), + PARTITION lEven VALUES IN (2,4,6)); +-- error 8200 +ALTER TABLE members REORGANIZE PARTITION p1800,p2000 INTO (PARTITION p2000 VALUES LESS THAN (2100)); +INSERT INTO members VALUES (313, "John", "Doe", "2022-11-22", NULL); +ALTER TABLE members REORGANIZE PARTITION p2000 INTO (PARTITION p2000 VALUES LESS THAN (2050)); +-- error 1526 +ALTER TABLE members REORGANIZE PARTITION p2000 INTO (PARTITION p2000 VALUES LESS THAN (2020)); +INSERT INTO member_level (id, level) values (313, 6); +-- error 1526 +ALTER TABLE member_level REORGANIZE PARTITION lEven INTO (PARTITION lEven VALUES IN (2,4)); + +# TestDisableDDL +# https://github.com/pingcap/tidb/issues/41277 +select @@global.tidb_enable_ddl; +-- error 8246 +set @@global.tidb_enable_ddl=false; +-- error 8246 +set @@global.tidb_enable_ddl=false; +select @@global.tidb_enable_ddl; + +# TestReorganizePartitionWarning +# https://github.com/pingcap/tidb/issues/42183 +drop table if exists t; +create table t (id bigint, b varchar(20), index idxb(b)) partition by range(id) (partition p0 values less than (20), partition p1 values less than (100)); +alter table t reorganize partition p0 into (partition p01 values less than (10), partition p02 values less than (20)); +show warnings; + diff --git a/tests/integrationtest/t/ddl/db_rename.test b/tests/integrationtest/t/ddl/db_rename.test new file mode 100644 index 0000000000000..85e8d37c2be71 --- /dev/null +++ b/tests/integrationtest/t/ddl/db_rename.test @@ -0,0 +1,15 @@ +# TestRenameIndex +drop table if exists t; +create table t (pk int primary key, c int default 1, c1 int default 1, unique key k1(c), key k2(c1)); +alter table t rename index k1 to k3; +admin check index t k3; +alter table t rename index k3 to k3; +admin check index t k3; +-- error 1176 +alter table t rename index x to x; +-- error 1061 +alter table t rename index k3 to k2; +alter table t rename index k2 to K2; +-- error 1061 +alter table t rename key k3 to K2; + diff --git a/tests/integrationtest/t/ddl/db_table.test b/tests/integrationtest/t/ddl/db_table.test new file mode 100644 index 0000000000000..1aa987c8ea5cf --- /dev/null +++ b/tests/integrationtest/t/ddl/db_table.test @@ -0,0 +1,82 @@ +# TestTableForeignKey +drop table if exists t1,t2,t3,t4; +create table t1 (a int, b int, index(a), index(b)); +-- error 1072 +create table t2 (c int, foreign key (a) references t1(a)); +create table t3 (a int, b int); +-- error 1072 +alter table t1 add foreign key (c) REFERENCES t3(a); +-- error 1239 +alter table t1 add foreign key (a) REFERENCES t3(a, b); +create table t4 (c int,d int,foreign key (d) references t1 (b)); +-- error 1828 +alter table t4 drop column d; +-- error 3780 +alter table t4 change column d e bigint; +-- error 3780 +alter table t4 modify column d bigint; +--disable_result_log +select count(*) from information_schema.KEY_COLUMN_USAGE; +--enable_result_log +alter table t4 drop foreign key fk_1; +alter table t4 modify column d bigint; +drop table if exists t1,t2,t3,t4; + +# TestCharacterSetInColumns +drop table if exists t; +create table t (c1 int, s1 varchar(10), s2 text); +select count(*) from information_schema.columns where table_schema = 'ddl__db_table' and table_name = 't' and character_set_name != 'utf8mb4'; +select count(*) from information_schema.columns where table_schema = 'ddl__db_table' and table_name = 't' and character_set_name = 'utf8mb4'; +create table t1(id int) charset=UTF8; +create table t2(id int) charset=BINARY; +create table t3(id int) charset=LATIN1; +create table t4(id int) charset=ASCII; +create table t5(id int) charset=UTF8MB4; +create table t11(id int) charset=utf8; +create table t12(id int) charset=binary; +create table t13(id int) charset=latin1; +create table t14(id int) charset=ascii; +create table t15(id int) charset=utf8mb4; + +# TestAlterTableWithValidation +drop table if exists t1; +create table t1 (c1 int, c2 int as (c1 + 1)); +alter table t1 with validation; +show warnings; +alter table t1 without validation; +show warnings; +drop table if exists t1; + +# TestLock +# port from MySQL +# https://github.com/mysql/mysql-server/blob/124c7ab1d6f914637521fd4463a993aa73403513/mysql-test/t/lock.test +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( `id` int(11) NOT NULL default '0', `id2` int(11) NOT NULL default '0', `id3` int(11) NOT NULL default '0', `dummy1` char(30) default NULL, PRIMARY KEY (`id`,`id2`), KEY `index_id3` (`id3`)); +insert into t1 (id,id2) values (1,1),(1,2),(1,3); +LOCK TABLE t1 WRITE; +select dummy1,count(distinct id) from t1 group by dummy1; +update t1 set id=-1 where id=1; +LOCK TABLE t1 READ; +-- error 1099 +update t1 set id=1 where id=1; +unlock tables; +update t1 set id=1 where id=-1; +drop table t1; + +# TestDDLWithInvalidTableInfo +drop table if exists t; +-- error 1064 +CREATE TABLE t ( + c0 int(11), + c1 int(11), + c2 decimal(16,4) GENERATED ALWAYS AS ((case when (c0 = 0) then 0when (c0 > 0) then (c1 / c0) end)) +); +create table t (a bigint, b int, c int generated always as (b+1)) partition by hash(a) partitions 4; +-- error 3855 +alter table t drop column a; +-- error 1064 +alter table t modify column c int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end)); +-- error 1064 +alter table t add column d int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end)); +drop table if exists t; +