Skip to content

Commit

Permalink
config: use tidb_enable_list_partition to enable list table partition…
Browse files Browse the repository at this point in the history
… feature (#22864) (#22957)
  • Loading branch information
ti-srebot authored Mar 1, 2021
1 parent 68ab7e3 commit f41ca49
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 48 deletions.
24 changes: 13 additions & 11 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (s *testIntegrationSuite7) TestCreateTableWithRangeColumnPartition(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists log_message_1;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`
create table log_message_1 (
add_time datetime not null default '2000-01-01 00:00:00',
Expand Down Expand Up @@ -538,6 +538,7 @@ func (s *testIntegrationSuite1) TestDisableTablePartition(c *C) {
tk.MustExec("use test;")
for _, v := range []string{"'AUTO'", "'OFF'", "0", "'ON'"} {
tk.MustExec("set @@session.tidb_enable_table_partition = " + v)
tk.MustExec("set @@session.tidb_enable_list_partition = OFF")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int) partition by list (id) (
partition p0 values in (1,2),partition p1 values in (3,4));`)
Expand Down Expand Up @@ -567,7 +568,7 @@ func (s *testIntegrationSuite1) generatePartitionTableByNum(num int) string {
func (s *testIntegrationSuite1) TestCreateTableWithListPartition(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
type errorCase struct {
sql string
Expand Down Expand Up @@ -707,7 +708,7 @@ func (s *testIntegrationSuite1) TestCreateTableWithListPartition(c *C) {
func (s *testIntegrationSuite1) TestCreateTableWithListColumnsPartition(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
type errorCase struct {
sql string
Expand Down Expand Up @@ -905,7 +906,7 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartitionByList(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`create table t (id int) partition by list (id) (
partition p0 values in (1,2),
partition p1 values in (3,4),
Expand Down Expand Up @@ -1020,7 +1021,7 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartitionByListColumns(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`create table t (id int, name varchar(10)) partition by list columns (id,name) (
partition p0 values in ((1,'a'),(2,'b')),
partition p1 values in ((3,'a'),(4,'b')),
Expand Down Expand Up @@ -1087,7 +1088,7 @@ func (s *testIntegrationSuite5) TestAlterTableDropPartitionByList(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`create table t (id int) partition by list (id) (
partition p0 values in (1,2),
partition p1 values in (3,4),
Expand Down Expand Up @@ -1122,7 +1123,7 @@ func (s *testIntegrationSuite5) TestAlterTableDropPartitionByListColumns(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`create table t (id int, name varchar(10)) partition by list columns (id,name) (
partition p0 values in ((1,'a'),(2,'b')),
partition p1 values in ((3,'a'),(4,'b')),
Expand Down Expand Up @@ -1159,7 +1160,7 @@ func (s *testIntegrationSuite5) TestAlterTableTruncatePartitionByList(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`create table t (id int) partition by list (id) (
partition p0 values in (1,2),
partition p1 values in (3,4),
Expand Down Expand Up @@ -1190,7 +1191,7 @@ func (s *testIntegrationSuite5) TestAlterTableTruncatePartitionByListColumns(c *
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`create table t (id int, name varchar(10)) partition by list columns (id,name) (
partition p0 values in ((1,'a'),(2,'b')),
partition p1 values in ((3,'a'),(4,'b')),
Expand Down Expand Up @@ -3295,7 +3296,7 @@ func (s *testIntegrationSuite7) TestAddPartitionForTableWithWrongType(c *C) {
func (s *testIntegrationSuite7) TestPartitionListWithTimeType(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("create table t_list1(a date) partition by list columns (a) (partition p0 values in ('2010-02-02', '20180203'), partition p1 values in ('20200202'));")
tk.MustExec("insert into t_list1(a) values (20180203);")
tk.MustQuery(`select * from t_list1 partition (p0);`).Check(testkit.Rows("2018-02-03"))
Expand All @@ -3306,7 +3307,8 @@ func (s *testIntegrationSuite7) TestPartitionListWithNewCollation(c *C) {
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustGetErrCode(`create table t (a char(10) collate utf8mb4_general_ci) partition by list columns (a) (partition p0 values in ('a', 'A'));`, mysql.ErrMultipleDefConstInListPart)
tk.MustExec("create table t11(a char(10) collate utf8mb4_general_ci) partition by list columns (a) (partition p0 values in ('a', 'b'), partition p1 values in ('C', 'D'));")
tk.MustExec("insert into t11(a) values ('A'), ('c'), ('C'), ('d'), ('B');")
Expand Down
5 changes: 2 additions & 3 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/tablecodec"
Expand Down Expand Up @@ -308,8 +307,8 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.PartitionOptions, tb
enable = true
}
case model.PartitionTypeList:
// Partition by list is enabled only when tidb_enable_table_partition is 'nightly'.
enable = strings.EqualFold(ctx.GetSessionVars().EnableTablePartition, variable.Nightly)
// Partition by list is enabled only when tidb_enable_list_partition is 'ON'.
enable = ctx.GetSessionVars().EnableListTablePartition
}

if !enable {
Expand Down
2 changes: 1 addition & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4269,7 +4269,7 @@ func (s *testSuiteP1) TestSelectPartition(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test`)
tk.MustExec(`drop table if exists th, tr, tl`)
tk.MustExec("set @@session.tidb_enable_table_partition = nightly;")
tk.MustExec("set @@session.tidb_enable_list_partition = ON;")
tk.MustExec(`create table th (a int, b int) partition by hash(a) partitions 3;`)
tk.MustExec(`create table tr (a int, b int)
partition by range (a) (
Expand Down
2 changes: 1 addition & 1 deletion executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (s *testInfoschemaTableSerialSuite) TestPartitionsTable(c *C) {
tk.MustQuery("select PARTITION_NAME,PARTITION_METHOD,PARTITION_EXPRESSION from information_schema.partitions where table_name = 'test_partitions1';").Check(testkit.Rows("p0 RANGE COLUMNS id", "p1 RANGE COLUMNS id", "p2 RANGE COLUMNS id"))
tk.MustExec("DROP TABLE test_partitions1")

tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("create table test_partitions (a int) partition by list (a) (partition p0 values in (1), partition p1 values in (2));")
tk.MustQuery("select PARTITION_NAME,PARTITION_METHOD,PARTITION_EXPRESSION from information_schema.partitions where table_name = 'test_partitions';").Check(testkit.Rows("p0 LIST `a`", "p1 LIST `a`"))
tk.MustExec("drop table test_partitions")
Expand Down
3 changes: 2 additions & 1 deletion executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ partition p2 values less than (10))`)

func (s *partitionTableSuite) TestPartitionIndexJoin(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("set @@session.tidb_enable_table_partition = 1")
tk.MustExec("set @@session.tidb_enable_list_partition = 1")
for i := 0; i < 3; i++ {
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("drop table if exists p, t")
if i == 0 {
// Test for range partition
Expand Down
2 changes: 1 addition & 1 deletion executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ func (s *testSuite5) TestShowCreateTable(c *C) {
c.Assert(result, Matches, `(?s).*GENERATED ALWAYS AS \(_utf8'a'\).*`)

// Test show list partition table
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec(`DROP TABLE IF EXISTS t`)
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec(`create table t (id int, name varchar(10), unique index idx (id)) partition by list (id) (
partition p0 values in (3,5,6,9,17),
partition p1 values in (1,2,10,11,19,20),
Expand Down
29 changes: 15 additions & 14 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2878,7 +2878,7 @@ from t order by c_str;`).Check(testkit.Rows("10"))
func (s *testSuite4) TestWriteListPartitionTable(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int, name varchar(10), unique index idx (id)) partition by list (id) (
partition p0 values in (3,5,6,9,17),
Expand Down Expand Up @@ -2926,7 +2926,7 @@ func (s *testSuite4) TestWriteListPartitionTable(c *C) {
func (s *testSuite4) TestWriteListColumnsPartitionTable(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int, name varchar(10), unique index idx (id)) partition by list columns (id) (
partition p0 values in (3,5,6,9,17),
Expand Down Expand Up @@ -2975,7 +2975,7 @@ func (s *testSuite4) TestWriteListColumnsPartitionTable(c *C) {
func (s *testSuite4) TestWriteListPartitionTable1(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int, name varchar(10)) partition by list (id) (
partition p0 values in (3,5,6,9,17),
Expand Down Expand Up @@ -3100,7 +3100,7 @@ func (s *testSuite4) TestWriteListPartitionTable1(c *C) {
func (s *testSuite4) TestWriteListPartitionTable2(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int, name varchar(10),b int generated always as (length(name)+1) virtual)
partition by list (id*2 + b*b + b*b - b*b*2 - abs(id)) (
Expand Down Expand Up @@ -3225,7 +3225,8 @@ func (s *testSuite4) TestWriteListPartitionTable2(c *C) {
func (s *testSuite4) TestWriteListColumnsPartitionTable1(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")

tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int, name varchar(10)) partition by list columns (id) (
partition p0 values in (3,5,6,9,17),
Expand Down Expand Up @@ -3350,7 +3351,7 @@ func (s *testSuite4) TestWriteListColumnsPartitionTable1(c *C) {
func (s *testSuite4) TestWriteListColumnsPartitionTable2(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (location varchar(10), id int, a int) partition by list columns (location,id) (
partition p_west values in (('w', 1),('w', 2),('w', 3),('w', 4)),
Expand Down Expand Up @@ -3499,7 +3500,7 @@ func (s *testSuite4) TestWriteListColumnsPartitionTable2(c *C) {
func (s *testSuite4) TestWriteListPartitionTableIssue21437(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (a int) partition by list (a%10) (partition p0 values in (0,1));`)
_, err := tk.Exec("replace into t values (null)")
Expand All @@ -3509,7 +3510,7 @@ func (s *testSuite4) TestWriteListPartitionTableIssue21437(c *C) {
func (s *testSuite4) TestListPartitionWithAutoRandom(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (a bigint key auto_random (3), b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4));`)
tk.MustExec("set @@allow_auto_random_explicit_insert = true")
Expand All @@ -3532,7 +3533,7 @@ func (s *testSuite4) TestListPartitionWithAutoRandom(c *C) {
func (s *testSuite4) TestListPartitionWithAutoIncrement(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (a bigint key auto_increment, b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4));`)
tk.MustExec("set @@allow_auto_random_explicit_insert = true")
Expand All @@ -3555,7 +3556,7 @@ func (s *testSuite4) TestListPartitionWithAutoIncrement(c *C) {
func (s *testSuite4) TestListPartitionWithGeneratedColumn(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
// Test for generated column with bigint type.
tableDefs := []string{
// Test for virtual generated column for list partition
Expand Down Expand Up @@ -3600,7 +3601,7 @@ func (s *testSuite4) TestListPartitionWithGeneratedColumn(c *C) {
func (s *testSuite4) TestListPartitionWithGeneratedColumn1(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
// Test for generated column with year type.
tableDefs := []string{
// Test for virtual generated column for list partition
Expand Down Expand Up @@ -3668,7 +3669,7 @@ func (s *testSuite4) TestListPartitionWithGeneratedColumn1(c *C) {
func (s *testSuite4) TestListPartitionWithGeneratedColumn2(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
tableDefs := []string{
// Test for virtual generated column for datetime type in list partition.
`create table t (a datetime, b bigint GENERATED ALWAYS AS (to_seconds(a)) VIRTUAL, index idx(a)) partition by list (1 + b - 1) (
Expand Down Expand Up @@ -3710,7 +3711,7 @@ func (s *testSuite4) TestListPartitionWithGeneratedColumn2(c *C) {
func (s *testSuite4) TestListColumnsPartitionWithGeneratedColumn(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
// Test for generated column with substr expression.
tableDefs := []string{
// Test for virtual generated column
Expand All @@ -3734,7 +3735,7 @@ func (s *testSuite4) TestListColumnsPartitionWithGeneratedColumn(c *C) {
func (s *testSerialSuite2) TestListColumnsPartitionWithGlobalIndex(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition = nightly")
tk.MustExec("set @@session.tidb_enable_list_partition = ON")
// Test generated column with global index
restoreConfig := config.RestoreFunc()
defer restoreConfig()
Expand Down
Loading

0 comments on commit f41ca49

Please sign in to comment.