Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: close RecordSet #35341

Merged
merged 2 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func TestColumnTypeChangeBetweenInteger(t *testing.T) {
tk.MustGetErrCode("alter table t modify column a mediumint", errno.ErrDataOutOfRange)
tk.MustGetErrCode("alter table t modify column a smallint", errno.ErrDataOutOfRange)
tk.MustGetErrCode("alter table t modify column a tinyint", errno.ErrDataOutOfRange)
_, err = tk.Exec("admin check table t")
require.NoError(t, err)
tk.MustExec("admin check table t")
}

func TestColumnTypeChangeStateBetweenInteger(t *testing.T) {
Expand Down Expand Up @@ -1722,23 +1721,23 @@ func TestChangingColOriginDefaultValueAfterAddColAndCastSucc(t *testing.T) {
// For writable column:
// Insert / Update should set the column with the casted-related column value.
sql := fmt.Sprintf("insert into t values(%d, %d, '2021-06-06 12:13:14')", i+3, i+3)
_, err := tk1.Exec(sql)
err := tk1.ExecToErr(sql)
if err != nil {
checkErr = err
return
}
if job.SchemaState == model.StateWriteOnly {
// The casted value will be inserted into changing column too.
// for point get
_, err := tk1.Exec("update t set b = -1 where a = 1")
err := tk1.ExecToErr("update t set b = -1 where a = 1")
if err != nil {
checkErr = err
return
}
} else {
// The casted value will be inserted into changing column too.
// for point get
_, err := tk1.Exec("update t set b = -2 where a = 2")
err := tk1.ExecToErr("update t set b = -2 where a = 2")
if err != nil {
checkErr = err
return
Expand Down Expand Up @@ -2332,19 +2331,13 @@ func TestChangeNullValueFromOtherTypeToTimestamp(t *testing.T) {

prepare2()
// only from other type NULL to timestamp type NOT NULL, it should be successful. (timestamp to timestamp excluded)
_, err = tk.Exec("alter table t modify column a timestamp NOT NULL")
require.Error(t, err)
require.Equal(t, "[ddl:1265]Data truncated for column 'a' at row 1", err.Error())
tk.MustGetErrMsg("alter table t modify column a timestamp NOT NULL", "[ddl:1265]Data truncated for column 'a' at row 1")

// Some dml cases.
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a timestamp NOT NULL)")
_, err = tk.Exec("insert into t values()")
require.Error(t, err)
require.Equal(t, "[table:1364]Field 'a' doesn't have a default value", err.Error())

_, err = tk.Exec("insert into t values(null)")
require.Equal(t, "[table:1048]Column 'a' cannot be null", err.Error())
tk.MustGetErrMsg("insert into t values()", "[table:1364]Field 'a' doesn't have a default value")
tk.MustGetErrMsg("insert into t values(null)", "[table:1048]Column 'a' cannot be null")
}

func TestColumnTypeChangeBetweenFloatAndDouble(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions ddl/db_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/parser/auth"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/testkit"
Expand Down Expand Up @@ -170,8 +169,7 @@ func TestAlterTableCache(t *testing.T) {
tk.MustExec("begin")
tk.MustExec("insert into t1 set a=1;")
tk2.MustExec("alter table t1 cache;")
_, err = tk.Exec("commit")
require.True(t, terror.ErrorEqual(domain.ErrInfoSchemaChanged, err))
tk.MustGetDBError("commit", domain.ErrInfoSchemaChanged)
/* Test can skip schema checker */
tk.MustExec("begin")
tk.MustExec("alter table t1 nocache")
Expand Down
146 changes: 50 additions & 96 deletions ddl/db_integration_test.go

Large diffs are not rendered by default.

90 changes: 25 additions & 65 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestCreateTableWithPartition(t *testing.T) {
);`
tk.MustGetErrCode(sql4, tmysql.ErrPartitionMaxvalue)

_, err = tk.Exec(`CREATE TABLE rc (
tk.MustExec(`CREATE TABLE rc (
a INT NOT NULL,
b INT NOT NULL,
c INT NOT NULL
Expand All @@ -168,7 +168,6 @@ func TestCreateTableWithPartition(t *testing.T) {
partition p3 values less than (65,30,13),
partition p4 values less than (maxvalue,30,40)
);`)
require.NoError(t, err)

sql6 := `create table employees (
id int not null,
Expand Down Expand Up @@ -211,7 +210,7 @@ func TestCreateTableWithPartition(t *testing.T) {
);`
tk.MustGetErrCode(sql9, tmysql.ErrPartitionFunctionIsNotAllowed)

_, err = tk.Exec(`CREATE TABLE t9 (
tk.MustGetDBError(`CREATE TABLE t9 (
a INT NOT NULL,
b INT NOT NULL,
c INT NOT NULL
Expand All @@ -220,8 +219,7 @@ func TestCreateTableWithPartition(t *testing.T) {
partition p0 values less than (10),
partition p2 values less than (20),
partition p3 values less than (20)
);`)
require.True(t, dbterror.ErrRangeNotIncreasing.Equal(err))
);`, dbterror.ErrRangeNotIncreasing)

tk.MustGetErrCode(`create TABLE t10 (c1 int,c2 int) partition by range(c1 / c2 ) (partition p0 values less than (2));`, tmysql.ErrPartitionFunctionIsNotAllowed)

Expand Down Expand Up @@ -3088,11 +3086,8 @@ func TestPartitionErrorCode(t *testing.T) {
)
partition by hash(store_id)
partitions 4;`)
_, err := tk.Exec("alter table employees add partition partitions 8;")
require.True(t, dbterror.ErrUnsupportedAddPartition.Equal(err))

_, err = tk.Exec("alter table employees add partition (partition p5 values less than (42));")
require.True(t, dbterror.ErrUnsupportedAddPartition.Equal(err))
tk.MustGetDBError("alter table employees add partition partitions 8;", dbterror.ErrUnsupportedAddPartition)
tk.MustGetDBError("alter table employees add partition (partition p5 values less than (42));", dbterror.ErrUnsupportedAddPartition)

// coalesce partition
tk.MustExec(`create table clients (
Expand All @@ -3103,16 +3098,14 @@ func TestPartitionErrorCode(t *testing.T) {
)
partition by hash( month(signed) )
partitions 12;`)
_, err = tk.Exec("alter table clients coalesce partition 4;")
require.True(t, dbterror.ErrUnsupportedCoalescePartition.Equal(err))
tk.MustGetDBError("alter table clients coalesce partition 4;", dbterror.ErrUnsupportedCoalescePartition)

tk.MustExec(`create table t_part (a int key)
partition by range(a) (
partition p0 values less than (10),
partition p1 values less than (20)
);`)
_, err = tk.Exec("alter table t_part coalesce partition 4;")
require.True(t, dbterror.ErrCoalesceOnlyOnHashPartition.Equal(err))
tk.MustGetDBError("alter table t_part coalesce partition 4;", dbterror.ErrCoalesceOnlyOnHashPartition)

tk.MustGetErrCode(`alter table t_part reorganize partition p0, p1 into (
partition p0 values less than (1980));`, tmysql.ErrUnsupportedDDLOperation)
Expand All @@ -3135,9 +3128,7 @@ func TestPartitionErrorCode(t *testing.T) {
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")
tk2.MustExec("alter table t truncate partition p0;")

_, err = tk1.Exec("commit")
require.NoError(t, err)
tk1.MustExec("commit")
}

func TestConstAndTimezoneDepent(t *testing.T) {
Expand Down Expand Up @@ -3337,8 +3328,7 @@ func TestCommitWhenSchemaChange(t *testing.T) {
tk.MustExec("insert into nt values (1), (3), (5);")
tk2.MustExec("alter table pt exchange partition p1 with table nt;")
tk.MustExec("insert into nt values (7), (9);")
_, err = tk.Session().Execute(context.Background(), "commit")
require.True(t, domain.ErrInfoSchemaChanged.Equal(err))
tk.MustGetDBError("commit", domain.ErrInfoSchemaChanged)

tk.MustExec("admin check table pt")
tk.MustQuery("select * from pt").Check(testkit.Rows())
Expand All @@ -3349,8 +3339,7 @@ func TestCommitWhenSchemaChange(t *testing.T) {
tk.MustExec("insert into pt values (1), (3), (5);")
tk2.MustExec("alter table pt exchange partition p1 with table nt;")
tk.MustExec("insert into pt values (7), (9);")
_, err = tk.Session().Execute(context.Background(), "commit")
require.True(t, domain.ErrInfoSchemaChanged.Equal(err))
tk.MustGetDBError("commit", domain.ErrInfoSchemaChanged)

tk.MustExec("admin check table pt")
tk.MustQuery("select * from pt").Check(testkit.Rows())
Expand All @@ -3365,34 +3354,28 @@ func TestCreatePartitionTableWithWrongType(t *testing.T) {
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
var err error
_, err = tk.Exec(`create table t(
tk.MustGetDBError(`create table t(
b int(10)
) partition by range columns (b) (
partition p0 values less than (0x10),
partition p3 values less than (0x20)
)`)
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))
)`, dbterror.ErrWrongTypeColumnValue)

_, err = tk.Exec(`create table t(
tk.MustGetDBError(`create table t(
b int(10)
) partition by range columns (b) (
partition p0 values less than ('g'),
partition p3 values less than ('k')
)`)
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))
)`, dbterror.ErrWrongTypeColumnValue)

_, err = tk.Exec(`create table t(
tk.MustGetDBError(`create table t(
b char(10)
) partition by range columns (b) (
partition p0 values less than (30),
partition p3 values less than (60)
)`)
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))
)`, dbterror.ErrWrongTypeColumnValue)

_, err = tk.Exec(`create table t(
err = tk.ExecToErr(`create table t(
b datetime
) partition by range columns (b) (
partition p0 values less than ('g'),
Expand Down Expand Up @@ -3422,35 +3405,13 @@ func TestAddPartitionForTableWithWrongType(t *testing.T) {
partition p0 values less than ('2020-09-01')
)`)

var err error

_, err = tk.Exec("alter table t_int add partition (partition p1 values less than ('g'))")
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))

_, err = tk.Exec("alter table t_int add partition (partition p1 values less than (0x20))")
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))

_, err = tk.Exec("alter table t_char add partition (partition p1 values less than (0x20))")
require.Error(t, err)
require.True(t, dbterror.ErrRangeNotIncreasing.Equal(err))

_, err = tk.Exec("alter table t_char add partition (partition p1 values less than (10))")
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))

_, err = tk.Exec("alter table t_date add partition (partition p1 values less than ('m'))")
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))

_, err = tk.Exec("alter table t_date add partition (partition p1 values less than (0x20))")
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))

_, err = tk.Exec("alter table t_date add partition (partition p1 values less than (20))")
require.Error(t, err)
require.True(t, dbterror.ErrWrongTypeColumnValue.Equal(err))
tk.MustGetDBError("alter table t_int add partition (partition p1 values less than ('g'))", dbterror.ErrWrongTypeColumnValue)
tk.MustGetDBError("alter table t_int add partition (partition p1 values less than (0x20))", dbterror.ErrWrongTypeColumnValue)
tk.MustGetDBError("alter table t_char add partition (partition p1 values less than (0x20))", dbterror.ErrRangeNotIncreasing)
tk.MustGetDBError("alter table t_char add partition (partition p1 values less than (10))", dbterror.ErrWrongTypeColumnValue)
tk.MustGetDBError("alter table t_date add partition (partition p1 values less than ('m'))", dbterror.ErrWrongTypeColumnValue)
tk.MustGetDBError("alter table t_date add partition (partition p1 values less than (0x20))", dbterror.ErrWrongTypeColumnValue)
tk.MustGetDBError("alter table t_date add partition (partition p1 values less than (20))", dbterror.ErrWrongTypeColumnValue)
}

func TestPartitionListWithTimeType(t *testing.T) {
Expand Down Expand Up @@ -3517,8 +3478,7 @@ func TestAddTableWithPartition(t *testing.T) {
tk.MustGetErrCode("create temporary table local_partition_table (a int, b int) partition by hash(a) partitions 3;", errno.ErrPartitionNoTemporary)
tk.MustExec("drop table if exists local_partition_table;")
tk.MustExec("drop table if exists partition_table;")
_, err = tk.Exec("create table partition_table (a int, b int) partition by hash(a) partitions 3;")
require.NoError(t, err)
tk.MustExec("create table partition_table (a int, b int) partition by hash(a) partitions 3;")
tk.MustExec("drop table if exists partition_table;")
tk.MustExec("drop table if exists local_partition_range_table;")
tk.MustGetErrCode(`create temporary table local_partition_range_table (c1 smallint(6) not null, c2 char(5) default null) partition by range ( c1 ) (
Expand Down
Loading