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

*: Exchange partition, fix LIST COLUMNs validation as well as NULL validation (#46533) #46697

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix conflict
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
  • Loading branch information
YangKeao committed Sep 8, 2023
commit ce1c66e7bdef3c4f2233c303c91c52c7161079f7
314 changes: 0 additions & 314 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5132,319 +5132,6 @@ partition p1 values less than maxvalue)`)
"(PARTITION `p0` VALUES LESS THAN (1998),\n" +
" PARTITION `p1` VALUES LESS THAN (MAXVALUE))"))
}
<<<<<<< HEAD:ddl/db_partition_test.go
=======

func TestRemoveRangePartitioning(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database RemovePartitioning")
tk.MustExec("use RemovePartitioning")
tk.MustExec(`create table tRange (a int unsigned primary key, b varchar(255))
partition by range (a)
(partition p0 values less than (1000000),
partition pMax values less than maxvalue)`)
tk.MustExec(`insert into tRange values (0, "Zero"), (999999, "999999"), (1000000, "1000000"), (20000000, "20000000")`)
tk.MustQuery(`show create table tRange`).Check(testkit.Rows("" +
"tRange CREATE TABLE `tRange` (\n" +
" `a` int(10) unsigned NOT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" +
"PARTITION BY RANGE (`a`)\n" +
"(PARTITION `p0` VALUES LESS THAN (1000000),\n" +
" PARTITION `pMax` VALUES LESS THAN (MAXVALUE))"))
tk.MustExec(`alter table tRange remove partitioning`)
tk.MustQuery(`show create table tRange`).Check(testkit.Rows("" +
"tRange CREATE TABLE `tRange` (\n" +
" `a` int(10) unsigned NOT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}

func TestRemoveRangeColumnPartitioning(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database RemovePartitioning")
tk.MustExec("use RemovePartitioning")
tk.MustExec(`create table tRange (a varchar(55) primary key, b varchar(255))
partition by range columns (a)
(partition p0 values less than ("1000000"),
partition pMax values less than maxvalue)`)
tk.MustExec(`insert into tRange values ("0", "Zero"), ("0999999", "0999999"), ("1000000", "1000000"), ("20000000", "20000000")`)
tk.MustQuery(`show create table tRange`).Check(testkit.Rows("" +
"tRange CREATE TABLE `tRange` (\n" +
" `a` varchar(55) NOT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" +
"PARTITION BY RANGE COLUMNS(`a`)\n" +
"(PARTITION `p0` VALUES LESS THAN ('1000000'),\n" +
" PARTITION `pMax` VALUES LESS THAN (MAXVALUE))"))
tk.MustExec(`alter table tRange remove partitioning`)
tk.MustQuery(`show create table tRange`).Check(testkit.Rows("" +
"tRange CREATE TABLE `tRange` (\n" +
" `a` varchar(55) NOT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}

func TestRemoveRangeColumnsPartitioning(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database RemovePartitioning")
tk.MustExec("use RemovePartitioning")
tk.MustExec(`create table tRange (a varchar(55), b varchar(255))
partition by range columns (a,b)
(partition p0 values less than ("1000000","1000000"),
partition pMax values less than (maxvalue,1))`)
tk.MustExec(`insert into tRange values ("0", "0Zero"), ("0999999", "0999999"), ("1000000", "1000000"), ("20000000", "20000000")`)
tk.MustQuery(`show create table tRange`).Check(testkit.Rows("" +
"tRange CREATE TABLE `tRange` (\n" +
" `a` varchar(55) DEFAULT NULL,\n" +
" `b` varchar(255) DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" +
"PARTITION BY RANGE COLUMNS(`a`,`b`)\n" +
"(PARTITION `p0` VALUES LESS THAN ('1000000','1000000'),\n" +
" PARTITION `pMax` VALUES LESS THAN (MAXVALUE,'1'))"))
tk.MustExec(`alter table tRange remove partitioning`)
tk.MustQuery(`show create table tRange`).Check(testkit.Rows("" +
"tRange CREATE TABLE `tRange` (\n" +
" `a` varchar(55) DEFAULT NULL,\n" +
" `b` varchar(255) DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}

func TestRemoveHashPartitioning(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database RemovePartitioning")
tk.MustExec("use RemovePartitioning")
tk.MustExec(`create table t (a int, b varchar(255), key (a,b), key (b)) partition by hash (a) partitions 7`)
for i := 32; i <= 126; i++ {
// Fill the data with int and ascii strings
tk.MustExec(fmt.Sprintf(`insert into t values (%d,char(%d,%d,%d,%d))`, i, i, i, i, i))
}
tk.MustExec(`analyze table t`)
tk.MustQuery(`select partition_name, table_rows from information_schema.partitions where table_schema = 'RemovePartitioning' and table_name = 't'`).Sort().Check(testkit.Rows(""+
"p0 14",
"p1 13",
"p2 13",
"p3 13",
"p4 14",
"p5 14",
"p6 14"))
tk.MustExec(`alter table t remove partitioning`)
tk.MustQuery(`show create table t`).Check(testkit.Rows("" +
"t CREATE TABLE `t` (\n" +
" `a` int(11) DEFAULT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" KEY `a` (`a`,`b`),\n" +
" KEY `b` (`b`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}

func TestRemoveKeyPartitioning(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
h := dom.StatsHandle()
tk.MustExec("create database RemovePartitioning")
tk.MustExec("use RemovePartitioning")
tk.MustExec(`create table t (a varchar(255), b varchar(255), key (a,b), key (b)) partition by key (a) partitions 7`)
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// Fill the data with ascii strings
for i := 32; i <= 126; i++ {
tk.MustExec(fmt.Sprintf(`insert into t values (char(%d,%d,%d),char(%d,%d,%d,%d))`, i, i, i, i, i, i, i))
}
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemovePartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemovePartitioning", "t", "global", "0", "95"},
{"RemovePartitioning", "t", "p0", "0", "9"},
{"RemovePartitioning", "t", "p1", "0", "11"},
{"RemovePartitioning", "t", "p2", "0", "12"},
{"RemovePartitioning", "t", "p3", "0", "13"},
{"RemovePartitioning", "t", "p4", "0", "16"},
{"RemovePartitioning", "t", "p5", "0", "23"},
{"RemovePartitioning", "t", "p6", "0", "11"}})
tk.MustQuery(`select partition_name, table_rows from information_schema.partitions where table_schema = 'RemovePartitioning' and table_name = 't'`).Sort().Check(testkit.Rows(""+
"p0 9",
"p1 11",
"p2 12",
"p3 13",
"p4 16",
"p5 23",
"p6 11"))
tk.MustExec(`alter table t remove partitioning`)
tk.MustQuery(`show create table t`).Check(testkit.Rows("" +
"t CREATE TABLE `t` (\n" +
" `a` varchar(255) DEFAULT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" KEY `a` (`a`,`b`),\n" +
" KEY `b` (`b`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
// Statistics are updated asynchronously
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// And also cached and lazy loaded
h.Clear()
require.NoError(t, h.Update(dom.InfoSchema()))
tk.MustQuery(`show stats_meta where db_name = 'RemovePartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemovePartitioning", "t", "", "0", "95"}})
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemovePartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemovePartitioning", "t", "", "0", "95"}})
}

func TestRemoveListPartitioning(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
h := dom.StatsHandle()
tk.MustExec("create database RemoveListPartitioning")
tk.MustExec("use RemoveListPartitioning")
tk.MustExec(`create table t (a int, b varchar(255), key (a,b), key (b)) partition by list (a) (partition p0 values in (0), partition p1 values in (1), partition p2 values in (2), partition p3 values in (3), partition p4 values in (4))`)
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// Fill the data with ascii strings
for i := 32; i <= 126; i++ {
tk.MustExec(fmt.Sprintf(`insert into t values (%d,char(%d,%d,%d,%d))`, i%5, i, i, i, i))
}
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "global", "0", "95"},
{"RemoveListPartitioning", "t", "p0", "0", "19"},
{"RemoveListPartitioning", "t", "p1", "0", "19"},
{"RemoveListPartitioning", "t", "p2", "0", "19"},
{"RemoveListPartitioning", "t", "p3", "0", "19"},
{"RemoveListPartitioning", "t", "p4", "0", "19"}})
tk.MustQuery(`select partition_name, table_rows from information_schema.partitions where table_schema = 'RemoveListPartitioning' and table_name = 't'`).Sort().Check(testkit.Rows(""+
"p0 19",
"p1 19",
"p2 19",
"p3 19",
"p4 19"))
tk.MustExec(`alter table t remove partitioning`)
tk.MustQuery(`show create table t`).Check(testkit.Rows("" +
"t CREATE TABLE `t` (\n" +
" `a` int(11) DEFAULT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" KEY `a` (`a`,`b`),\n" +
" KEY `b` (`b`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
// Statistics are updated asynchronously
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// And also cached and lazy loaded
h.Clear()
require.NoError(t, h.Update(dom.InfoSchema()))
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "", "0", "95"}})
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "", "0", "95"}})
}

func TestRemoveListColumnPartitioning(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
h := dom.StatsHandle()
tk.MustExec("create database RemoveListPartitioning")
tk.MustExec("use RemoveListPartitioning")
tk.MustExec(`create table t (a varchar(255), b varchar(255), key (a,b), key (b)) partition by list columns (a) (partition p0 values in ("0"), partition p1 values in ("1"), partition p2 values in ("2"), partition p3 values in ("3"), partition p4 values in ("4"))`)
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// Fill the data with ascii strings
for i := 32; i <= 126; i++ {
tk.MustExec(fmt.Sprintf(`insert into t values ("%d",char(%d,%d,%d,%d))`, i%5, i, i, i, i))
}
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "global", "0", "95"},
{"RemoveListPartitioning", "t", "p0", "0", "19"},
{"RemoveListPartitioning", "t", "p1", "0", "19"},
{"RemoveListPartitioning", "t", "p2", "0", "19"},
{"RemoveListPartitioning", "t", "p3", "0", "19"},
{"RemoveListPartitioning", "t", "p4", "0", "19"}})
tk.MustQuery(`select partition_name, table_rows from information_schema.partitions where table_schema = 'RemoveListPartitioning' and table_name = 't'`).Sort().Check(testkit.Rows(""+
"p0 19",
"p1 19",
"p2 19",
"p3 19",
"p4 19"))
tk.MustExec(`alter table t remove partitioning`)
tk.MustQuery(`show create table t`).Check(testkit.Rows("" +
"t CREATE TABLE `t` (\n" +
" `a` varchar(255) DEFAULT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" KEY `a` (`a`,`b`),\n" +
" KEY `b` (`b`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
// Statistics are updated asynchronously
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// And also cached and lazy loaded
h.Clear()
require.NoError(t, h.Update(dom.InfoSchema()))
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "", "0", "95"}})
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "", "0", "95"}})
}

func TestRemoveListColumnsPartitioning(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
h := dom.StatsHandle()
tk.MustExec("create database RemoveListPartitioning")
tk.MustExec("use RemoveListPartitioning")
tk.MustExec(`create table t (a int, b varchar(255), key (a,b), key (b)) partition by list columns (a,b) (partition p0 values in ((0,"0")), partition p1 values in ((1,"1")), partition p2 values in ((2,"2")), partition p3 values in ((3,"3")), partition p4 values in ((4,"4")))`)
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// Fill the data
for i := 32; i <= 126; i++ {
tk.MustExec(fmt.Sprintf(`insert into t values (%d,"%d")`, i%5, i%5))
}
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "global", "0", "95"},
{"RemoveListPartitioning", "t", "p0", "0", "19"},
{"RemoveListPartitioning", "t", "p1", "0", "19"},
{"RemoveListPartitioning", "t", "p2", "0", "19"},
{"RemoveListPartitioning", "t", "p3", "0", "19"},
{"RemoveListPartitioning", "t", "p4", "0", "19"}})
tk.MustQuery(`select partition_name, table_rows from information_schema.partitions where table_schema = 'RemoveListPartitioning' and table_name = 't'`).Sort().Check(testkit.Rows(""+
"p0 19",
"p1 19",
"p2 19",
"p3 19",
"p4 19"))
tk.MustExec(`alter table t remove partitioning`)
tk.MustQuery(`show create table t`).Check(testkit.Rows("" +
"t CREATE TABLE `t` (\n" +
" `a` int(11) DEFAULT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" KEY `a` (`a`,`b`),\n" +
" KEY `b` (`b`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
// Statistics are updated asynchronously
require.NoError(t, h.HandleDDLEvent(<-h.DDLEventCh()))
// And also cached and lazy loaded
h.Clear()
require.NoError(t, h.Update(dom.InfoSchema()))
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "", "0", "95"}})
tk.MustExec(`analyze table t`)
tk.MustQuery(`show stats_meta where db_name = 'RemoveListPartitioning' and table_name = 't'`).Sort().CheckAt([]int{0, 1, 2, 4, 5}, [][]interface{}{
{"RemoveListPartitioning", "t", "", "0", "95"}})
}

func TestListDefinitionError(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database ListRange")
tk.MustExec("use ListRange")
tk.MustContainErrMsg(`create table t (a int) partition by list (a) (partition p2 values less than (2))`, "[ddl:1480]Only RANGE PARTITIONING can use VALUES LESS THAN in partition definition")
tk.MustContainErrMsg(`create table t (a int) partition by list (a) (partition p2)`, "[ddl:1479]Syntax : LIST PARTITIONING requires definition of VALUES IN for each partition")
tk.MustExec(`create table t (a int) partition by list (a) (partition p1 values in (1))`)
tk.MustContainErrMsg(`alter table t add partition (partition p2 values less than (2))`, "[ddl:1480]Only RANGE PARTITIONING can use VALUES LESS THAN in partition definition")
tk.MustContainErrMsg(`alter table t add partition (partition p2)`, "[ddl:1479]Syntax : LIST PARTITIONING requires definition of VALUES IN for each partition")
}

func TestListExchangeValidate(t *testing.T) {
store := testkit.CreateMockStore(t)
Expand Down Expand Up @@ -5561,4 +5248,3 @@ func TestRangeExchangeValidate(t *testing.T) {
}

// TODO: check EXCHANGE how it handles null (for all types of partitioning!!!)
>>>>>>> e8b590c0cbf (*: Exchange partition, fix LIST COLUMNs validation as well as NULL validation (#46533)):ddl/tests/partition/db_partition_test.go