Skip to content

Commit

Permalink
*: enable range typed table partition (#8011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and zz-jason committed Oct 26, 2018
1 parent 4cfa774 commit 5831de2
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 40 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
bin
/interpreter/interpreter
/interpreter/test
/parser/parser.go
/tidb-server/tidb-server
/tidb-server/debug
coverage.out
Expand Down
1 change: 0 additions & 1 deletion ddl/db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ func (s *testStateChangeSuite) TestShowIndex(c *C) {
callback = &ddl.TestDDLCallback{}
d.(ddl.DDLForTest).SetHook(callback)

_, err = s.se.Execute(context.Background(), "set @@tidb_enable_table_partition = 1")
c.Assert(err, IsNil)

_, err = s.se.Execute(context.Background(), `create table tr(
Expand Down
10 changes: 0 additions & 10 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ func (s *testDBSuite) TestAddIndex(c *C) {
func (s *testDBSuite) testAddIndex(c *C, testPartition bool, createTableSQL string) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use " + s.schemaName)
s.tk.MustExec("set @@tidb_enable_table_partition = 1")
s.tk.MustExec("drop table if exists test_add_index")
s.tk.MustExec(createTableSQL)

Expand Down Expand Up @@ -2624,7 +2623,6 @@ func (s *testDBSuite) TestBackwardCompatibility(c *C) {
func (s *testDBSuite) TestAlterTableAddPartition(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test;")
s.tk.MustExec("set @@session.tidb_enable_table_partition=1")
s.tk.MustExec("drop table if exists employees;")
s.tk.MustExec(`create table employees (
id int not null,
Expand Down Expand Up @@ -2725,7 +2723,6 @@ func (s *testDBSuite) TestAlterTableAddPartition(c *C) {
func (s *testDBSuite) TestAlterTableDropPartition(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test")
s.tk.MustExec("set @@session.tidb_enable_table_partition=1")
s.tk.MustExec("drop table if exists employees")
s.tk.MustExec(`create table employees (
id int not null,
Expand Down Expand Up @@ -2863,7 +2860,6 @@ func (s *testDBSuite) TestAlterTableDropPartition(c *C) {
func (s *testDBSuite) TestAddPartitionTooManyPartitions(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test")
s.tk.MustExec("set @@session.tidb_enable_table_partition=1")
count := ddl.PartitionCountLimit
s.tk.MustExec("drop table if exists p1;")
sql1 := `create table p1 (
Expand Down Expand Up @@ -2946,7 +2942,6 @@ func (s *testDBSuite) TestTruncatePartitionAndDropTable(c *C) {

// Test truncate table partition.
s.tk.MustExec("drop table if exists t3;")
s.tk.MustExec("set @@session.tidb_enable_table_partition=1;")
s.tk.MustExec(`create table t3(
id int, name varchar(50),
purchased date
Expand Down Expand Up @@ -2985,7 +2980,6 @@ func (s *testDBSuite) TestTruncatePartitionAndDropTable(c *C) {

// Test drop table partition.
s.tk.MustExec("drop table if exists t4;")
s.tk.MustExec("set @@session.tidb_enable_table_partition=1;")
s.tk.MustExec(`create table t4(
id int, name varchar(50),
purchased date
Expand Down Expand Up @@ -3053,7 +3047,6 @@ func (s *testDBSuite) TestTruncatePartitionAndDropTable(c *C) {
func (s *testDBSuite) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test;")
s.tk.MustExec("set @@session.tidb_enable_table_partition=1;")
s.tk.MustExec("drop table if exists part1;")
s.tk.MustExec(`create table part1 (
col1 int not null,
Expand Down Expand Up @@ -3246,7 +3239,6 @@ func (s *testDBSuite) TestPartitionDropIndex(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
done := make(chan error, 1)
s.tk.MustExec("use " + s.schemaName)
s.tk.MustExec("set @@session.tidb_enable_table_partition=1;")
s.tk.MustExec("drop table if exists partition_drop_idx;")
s.tk.MustExec(`create table partition_drop_idx (
c1 int, c2 int, c3 int
Expand Down Expand Up @@ -3326,7 +3318,6 @@ LOOP:
func (s *testDBSuite) TestPartitionCancelAddIndex(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.mustExec(c, "use test_db")
s.mustExec(c, "set @@session.tidb_enable_table_partition=1;")
s.mustExec(c, "drop table if exists t1;")
s.mustExec(c, `create table t1 (
c1 int, c2 int, c3 int
Expand Down Expand Up @@ -3565,7 +3556,6 @@ LOOP:
func (s *testDBSuite) TestPartitionAddIndex(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition=1;")
tk.MustExec(`create table partition_add_idx (
id int not null,
hired date not null
Expand Down
15 changes: 14 additions & 1 deletion ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,22 @@ func buildTablePartitionInfo(ctx sessionctx.Context, d *ddl, s *ast.CreateTableS
if s.Partition == nil {
return nil, nil
}
var enable bool
switch ctx.GetSessionVars().EnableTablePartition {
case "on":
enable = true
case "off":
enable = false
default:
// When tidb_enable_table_partition = 'auto',
// Partition by range expression is enabled by default.
if s.Partition.Tp == model.PartitionTypeRange && s.Partition.ColumnNames == nil {
enable = true
}
}
pi := &model.PartitionInfo{
Type: s.Partition.Tp,
Enable: ctx.GetSessionVars().EnableTablePartition,
Enable: enable,
}
if s.Partition.Expr != nil {
buf := new(bytes.Buffer)
Expand Down
1 change: 0 additions & 1 deletion executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ func (s *testSuite) TestAdminCheckTable(c *C) {

// Test partitioned table.
tk.MustExec(`drop table if exists test`)
tk.MustExec(`set @@tidb_enable_table_partition = 1`)
tk.MustExec(`create table test (
a int not null,
c int not null,
Expand Down
1 change: 0 additions & 1 deletion executor/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

func (s *testSuite) TestAnalyzePartition(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@session.tidb_enable_table_partition=1")
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
createTable := `CREATE TABLE t (a int, b int, c varchar(10), primary key(a), index idx(b))
Expand Down
1 change: 0 additions & 1 deletion executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ func (s *testSuite) TestShowTableStatus(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition=1;")
tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t(a bigint);`)

Expand Down
3 changes: 0 additions & 3 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,6 @@ func (s *testSuite) TestReplace(c *C) {
func (s *testSuite) TestPartitionedTableReplace(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_table_partition=1")
testSQL := `drop table if exists replace_test;
create table replace_test (id int PRIMARY KEY AUTO_INCREMENT, c1 int, c2 int, c3 int default 1)
partition by range (id) (
Expand Down Expand Up @@ -1080,7 +1079,6 @@ func (s *testSuite) TestUpdate(c *C) {

func (s *testSuite) TestPartitionedTableUpdate(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@session.tidb_enable_table_partition=1")
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int not null default 1, name varchar(255))
Expand Down Expand Up @@ -1327,7 +1325,6 @@ func (s *testSuite) TestPartitionedTableDelete(c *C) {
PARTITION p3 VALUES LESS THAN (21))`

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@session.tidb_enable_table_partition=1")
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec(createTable)
Expand Down
1 change: 0 additions & 1 deletion planner/core/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ func (s *testAnalyzeSuite) TestAnalyze(c *C) {
testKit.MustExec("create table t3 (a int, b int)")
testKit.MustExec("create index a on t3 (a)")

testKit.MustExec("set @@session.tidb_enable_table_partition=1")
testKit.MustExec("create table t4 (a int, b int) partition by range (a) (partition p1 values less than (2), partition p2 values less than (3))")
testKit.MustExec("create index a on t4 (a)")
testKit.MustExec("create index b on t4 (b)")
Expand Down
1 change: 0 additions & 1 deletion sessionctx/binloginfo/binloginfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ func (s *testBinlogSuite) TestPartitionedTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.Se.GetSessionVars().BinlogClient = s.client
tk.MustExec("set @@session.tidb_enable_table_partition=1")
tk.MustExec("drop table if exists t")
tk.MustExec(`create table t (id int) partition by range (id) (
partition p0 values less than (1),
Expand Down
4 changes: 2 additions & 2 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ type SessionVars struct {
OptimizerSelectivityLevel int

// EnableTablePartition enables table partition feature.
EnableTablePartition bool
EnableTablePartition string

// EnableCascadesPlanner enables the cascades planner.
EnableCascadesPlanner bool
Expand Down Expand Up @@ -617,7 +617,7 @@ func (s *SessionVars) SetSystemVar(name string, val string) error {
case TiDBOptimizerSelectivityLevel:
s.OptimizerSelectivityLevel = tidbOptPositiveInt32(val, DefTiDBOptimizerSelectivityLevel)
case TiDBEnableTablePartition:
s.EnableTablePartition = TiDBOptOn(val)
s.EnableTablePartition = val
case TiDBDDLReorgWorkerCount:
SetDDLReorgWorkerCounter(int32(tidbOptPositiveInt32(val, DefTiDBDDLReorgWorkerCount)))
case TiDBDDLReorgPriority:
Expand Down
6 changes: 5 additions & 1 deletion sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ const (
// tidb_optimizer_selectivity_level is used to control the selectivity estimation level.
TiDBOptimizerSelectivityLevel = "tidb_optimizer_selectivity_level"

// tidb_enable_table_partition is used to enable table partition feature.
// tidb_enable_table_partition is used to control table partition feature.
// The valid value include auto/on/off:
// auto: enable table partition when that feature is implemented.
// on: always enable table partition.
// off: always disable table partition.
TiDBEnableTablePartition = "tidb_enable_table_partition"
)

Expand Down
8 changes: 4 additions & 4 deletions sessionctx/variable/varsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ func (s *testVarsutilSuite) TestVarsutil(c *C) {
c.Assert(val, Equals, "3")
c.Assert(v.RetryLimit, Equals, int64(3))

c.Assert(v.EnableTablePartition, IsFalse)
err = SetSessionSystemVar(v, TiDBEnableTablePartition, types.NewStringDatum("1"))
c.Assert(v.EnableTablePartition, Equals, "")
err = SetSessionSystemVar(v, TiDBEnableTablePartition, types.NewStringDatum("on"))
c.Assert(err, IsNil)
val, err = GetSessionSystemVar(v, TiDBEnableTablePartition)
c.Assert(err, IsNil)
c.Assert(val, Equals, "1")
c.Assert(v.EnableTablePartition, IsTrue)
c.Assert(val, Equals, "on")
c.Assert(v.EnableTablePartition, Equals, "on")
}
1 change: 0 additions & 1 deletion statistics/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (s *testStatsCacheSuite) TestDDLHistogram(c *C) {
func (s *testStatsCacheSuite) TestDDLPartition(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("set @@session.tidb_enable_table_partition=1")
testKit.MustExec("use test")
testKit.MustExec("drop table if exists t")
createTable := `CREATE TABLE t (a int, b int, primary key(a), index idx(b))
Expand Down
1 change: 0 additions & 1 deletion statistics/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (s *testDumpStatsSuite) TestConversion(c *C) {
func (s *testDumpStatsSuite) TestDumpPartitions(c *C) {
defer cleanEnv(c, s.store, s.do)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@session.tidb_enable_table_partition=1")
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
createTable := `CREATE TABLE t (a int, b int, primary key(a), index idx(b))
Expand Down
3 changes: 0 additions & 3 deletions statistics/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ func (s *testStatsUpdateSuite) TestTxnWithFailure(c *C) {
func (s *testStatsUpdateSuite) TestUpdatePartition(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("set @@session.tidb_enable_table_partition=1")
testKit.MustExec("use test")
testKit.MustExec("drop table if exists t")
createTable := `CREATE TABLE t (a int, b char(5)) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6),PARTITION p1 VALUES LESS THAN (11))`
Expand Down Expand Up @@ -460,7 +459,6 @@ func (s *testStatsUpdateSuite) TestAutoUpdate(c *C) {
func (s *testStatsUpdateSuite) TestAutoUpdatePartition(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("set @@session.tidb_enable_table_partition=1")
testKit.MustExec("use test")
testKit.MustExec("drop table if exists t")
testKit.MustExec("create table t (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6))")
Expand Down Expand Up @@ -828,7 +826,6 @@ func (s *testStatsUpdateSuite) TestQueryFeedbackForPartition(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("set @@session.tidb_enable_table_partition=1")
testKit.MustExec(`create table t (a bigint(64), b bigint(64), primary key(a), index idx(b))
partition by range (a) (
partition p0 values less than (3),
Expand Down
9 changes: 2 additions & 7 deletions table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ PARTITION BY RANGE ( id ) (
PARTITION p3 VALUES LESS THAN (21)
)`

_, err := ts.se.Execute(context.Background(), "set @@session.tidb_enable_table_partition=1")
c.Assert(err, IsNil)
_, err = ts.se.Execute(context.Background(), "drop table if exists t1;")
_, err := ts.se.Execute(context.Background(), "drop table if exists t1;")
c.Assert(err, IsNil)
_, err = ts.se.Execute(context.Background(), createTable1)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -408,9 +406,7 @@ PARTITION BY RANGE ( id ) (
PARTITION p3 VALUES LESS THAN (21)
)`

_, err := ts.se.Execute(context.Background(), "set @@session.tidb_enable_table_partition=1")
c.Assert(err, IsNil)
_, err = ts.se.Execute(context.Background(), "Drop table if exists test.t1;")
_, err := ts.se.Execute(context.Background(), "Drop table if exists test.t1;")
c.Assert(err, IsNil)
_, err = ts.se.Execute(context.Background(), createTable1)
c.Assert(err, IsNil)
Expand All @@ -428,7 +424,6 @@ PARTITION BY RANGE ( id ) (
func (ts *testSuite) TestGeneratePartitionExpr(c *C) {
_, err := ts.se.Execute(context.Background(), "use test")
c.Assert(err, IsNil)
_, err = ts.se.Execute(context.Background(), "set @@session.tidb_enable_table_partition=1")
c.Assert(err, IsNil)
_, err = ts.se.Execute(context.Background(), "drop table if exists t1;")
c.Assert(err, IsNil)
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/pingcap/parser/model/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5831de2

Please sign in to comment.