From 5d65a063883bcb09650e0c8f3b3c72ec94c3b9c8 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Thu, 5 Dec 2019 17:33:37 +0800 Subject: [PATCH 1/2] *: support split partition table region (#12213) --- executor/builder.go | 33 ++--- executor/executor_test.go | 114 +++++++++++++++- executor/split.go | 245 ++++++++++++++++++++++++++++------- executor/split_test.go | 2 +- go.mod | 2 + go.sum | 2 + planner/core/common_plans.go | 13 +- planner/core/planbuilder.go | 8 +- 8 files changed, 344 insertions(+), 75 deletions(-) diff --git a/executor/builder.go b/executor/builder.go index 7d93b2080a7e2..50ea69f340859 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -1335,28 +1335,31 @@ func (b *executorBuilder) buildSplitRegion(v *plannercore.SplitRegion) Executor base.maxChunkSize = 1 if v.IndexInfo != nil { return &SplitIndexRegionExec{ - baseExecutor: base, - tableInfo: v.TableInfo, - indexInfo: v.IndexInfo, - lower: v.Lower, - upper: v.Upper, - num: v.Num, - valueLists: v.ValueLists, + baseExecutor: base, + tableInfo: v.TableInfo, + partitionNames: v.PartitionNames, + indexInfo: v.IndexInfo, + lower: v.Lower, + upper: v.Upper, + num: v.Num, + valueLists: v.ValueLists, } } if len(v.ValueLists) > 0 { return &SplitTableRegionExec{ - baseExecutor: base, - tableInfo: v.TableInfo, - valueLists: v.ValueLists, + baseExecutor: base, + tableInfo: v.TableInfo, + partitionNames: v.PartitionNames, + valueLists: v.ValueLists, } } return &SplitTableRegionExec{ - baseExecutor: base, - tableInfo: v.TableInfo, - lower: v.Lower[0], - upper: v.Upper[0], - num: v.Num, + baseExecutor: base, + tableInfo: v.TableInfo, + partitionNames: v.PartitionNames, + lower: v.Lower[0], + upper: v.Upper[0], + num: v.Num, } } diff --git a/executor/executor_test.go b/executor/executor_test.go index 48dd323d69bcb..a18101565f633 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -3949,6 +3949,18 @@ func (s *testSuite) TestSplitRegion(c *C) { tk.MustExec("create table t1(a int, b int)") tk.MustQuery("split table t1 between(0) and (10000) regions 10;").Check(testkit.Rows("9 1")) tk.MustQuery("split table t1 between(10) and (10010) regions 5;").Check(testkit.Rows("4 1")) + + // Test split region for partition table. + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a int,b int) partition by hash(a) partitions 5;") + tk.MustQuery("split table t between (0) and (1000000) regions 5;").Check(testkit.Rows("20 1")) + // Test for `split for region` syntax. + tk.MustQuery("split region for partition table t between (1000000) and (100000000) regions 10;").Check(testkit.Rows("45 1")) + + // Test split region for partition table with specified partition. + tk.MustQuery("split table t partition (p1,p2) between (100000000) and (1000000000) regions 5;").Check(testkit.Rows("8 1")) + // Test for `split for region` syntax. + tk.MustQuery("split region for partition table t partition (p3,p4) between (100000000) and (1000000000) regions 5;").Check(testkit.Rows("8 1")) } func (s *testSuite) TestShowTableRegion(c *C) { @@ -4069,7 +4081,107 @@ func (s *testSuite) TestShowTableRegion(c *C) { c.Assert(rows[1][1], Equals, fmt.Sprintf("t_%d_r_2305843009213693952", tbl.Meta().ID)) c.Assert(rows[2][1], Equals, fmt.Sprintf("t_%d_r_4611686018427387904", tbl.Meta().ID)) c.Assert(rows[3][1], Equals, fmt.Sprintf("t_%d_r_6917529027641081856", tbl.Meta().ID)) - atomic.StoreUint32(&ddl.EnableSplitTableRegion, 0) + defer atomic.StoreUint32(&ddl.EnableSplitTableRegion, 0) + + // Test split partition table. + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a int,b int) partition by hash(a) partitions 5;") + tk.MustQuery("split table t between (0) and (4000000) regions 4;").Check(testkit.Rows("15 1")) + re = tk.MustQuery("show table t regions") + rows = re.Rows() + c.Assert(len(rows), Equals, 20) + tbl = testGetTableByName(c, tk.Se, "test", "t") + c.Assert(len(tbl.Meta().GetPartitionInfo().Definitions), Equals, 5) + for i, p := range tbl.Meta().GetPartitionInfo().Definitions { + c.Assert(rows[i*4+0][1], Equals, fmt.Sprintf("t_%d_", p.ID)) + c.Assert(rows[i*4+1][1], Equals, fmt.Sprintf("t_%d_r_1000000", p.ID)) + c.Assert(rows[i*4+2][1], Equals, fmt.Sprintf("t_%d_r_2000000", p.ID)) + c.Assert(rows[i*4+3][1], Equals, fmt.Sprintf("t_%d_r_3000000", p.ID)) + } + + // Test split region for partition table with specified partition. + tk.MustQuery("split table t partition (p4) between (1000000) and (2000000) regions 5;").Check(testkit.Rows("4 1")) + re = tk.MustQuery("show table t regions") + rows = re.Rows() + c.Assert(len(rows), Equals, 24) + tbl = testGetTableByName(c, tk.Se, "test", "t") + c.Assert(len(tbl.Meta().GetPartitionInfo().Definitions), Equals, 5) + for i := 0; i < 4; i++ { + p := tbl.Meta().GetPartitionInfo().Definitions[i] + c.Assert(rows[i*4+0][1], Equals, fmt.Sprintf("t_%d_", p.ID)) + c.Assert(rows[i*4+1][1], Equals, fmt.Sprintf("t_%d_r_1000000", p.ID)) + c.Assert(rows[i*4+2][1], Equals, fmt.Sprintf("t_%d_r_2000000", p.ID)) + c.Assert(rows[i*4+3][1], Equals, fmt.Sprintf("t_%d_r_3000000", p.ID)) + } + for i := 4; i < 5; i++ { + p := tbl.Meta().GetPartitionInfo().Definitions[i] + c.Assert(rows[i*4+0][1], Equals, fmt.Sprintf("t_%d_", p.ID)) + c.Assert(rows[i*4+1][1], Equals, fmt.Sprintf("t_%d_r_1000000", p.ID)) + + c.Assert(rows[i*4+2][1], Equals, fmt.Sprintf("t_%d_r_1200000", p.ID)) + c.Assert(rows[i*4+3][1], Equals, fmt.Sprintf("t_%d_r_1400000", p.ID)) + c.Assert(rows[i*4+4][1], Equals, fmt.Sprintf("t_%d_r_1600000", p.ID)) + c.Assert(rows[i*4+5][1], Equals, fmt.Sprintf("t_%d_r_1800000", p.ID)) + + c.Assert(rows[i*4+6][1], Equals, fmt.Sprintf("t_%d_r_2000000", p.ID)) + c.Assert(rows[i*4+7][1], Equals, fmt.Sprintf("t_%d_r_3000000", p.ID)) + } + + // Test split partition table index. + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a int,b int,index idx(a)) partition by hash(a) partitions 5;") + tk.MustQuery("split table t between (0) and (4000000) regions 4;").Check(testkit.Rows("20 1")) + tk.MustQuery("split table t index idx between (0) and (4000000) regions 4;").Check(testkit.Rows("20 1")) + re = tk.MustQuery("show table t regions") + rows = re.Rows() + c.Assert(len(rows), Equals, 40) + tbl = testGetTableByName(c, tk.Se, "test", "t") + c.Assert(len(tbl.Meta().GetPartitionInfo().Definitions), Equals, 5) + for i := 0; i < 5; i++ { + p := tbl.Meta().GetPartitionInfo().Definitions[i] + c.Assert(rows[i*8+0][1], Equals, fmt.Sprintf("t_%d_r", p.ID)) + c.Assert(rows[i*8+1][1], Equals, fmt.Sprintf("t_%d_r_1000000", p.ID)) + c.Assert(rows[i*8+2][1], Equals, fmt.Sprintf("t_%d_r_2000000", p.ID)) + c.Assert(rows[i*8+3][1], Equals, fmt.Sprintf("t_%d_r_3000000", p.ID)) + c.Assert(rows[i*8+4][1], Equals, fmt.Sprintf("t_%d_i_1_", p.ID)) + c.Assert(rows[i*8+5][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+6][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+7][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + } + + // Test split index region for partition table with specified partition. + tk.MustQuery("split table t partition (p4) index idx between (0) and (1000000) regions 5;").Check(testkit.Rows("4 1")) + re = tk.MustQuery("show table t regions") + rows = re.Rows() + c.Assert(len(rows), Equals, 44) + tbl = testGetTableByName(c, tk.Se, "test", "t") + c.Assert(len(tbl.Meta().GetPartitionInfo().Definitions), Equals, 5) + for i := 0; i < 4; i++ { + p := tbl.Meta().GetPartitionInfo().Definitions[i] + c.Assert(rows[i*8+0][1], Equals, fmt.Sprintf("t_%d_r", p.ID)) + c.Assert(rows[i*8+1][1], Equals, fmt.Sprintf("t_%d_r_1000000", p.ID)) + c.Assert(rows[i*8+2][1], Equals, fmt.Sprintf("t_%d_r_2000000", p.ID)) + c.Assert(rows[i*8+3][1], Equals, fmt.Sprintf("t_%d_r_3000000", p.ID)) + c.Assert(rows[i*8+4][1], Equals, fmt.Sprintf("t_%d_i_1_", p.ID)) + c.Assert(rows[i*8+5][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+6][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+7][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + } + for i := 4; i < 5; i++ { + p := tbl.Meta().GetPartitionInfo().Definitions[i] + c.Assert(rows[i*8+0][1], Equals, fmt.Sprintf("t_%d_r", p.ID)) + c.Assert(rows[i*8+1][1], Equals, fmt.Sprintf("t_%d_r_1000000", p.ID)) + c.Assert(rows[i*8+2][1], Equals, fmt.Sprintf("t_%d_r_2000000", p.ID)) + c.Assert(rows[i*8+3][1], Equals, fmt.Sprintf("t_%d_r_3000000", p.ID)) + c.Assert(rows[i*8+4][1], Equals, fmt.Sprintf("t_%d_i_1_", p.ID)) + c.Assert(rows[i*8+5][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+6][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+7][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+8][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+9][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+10][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + c.Assert(rows[i*8+11][1], Matches, fmt.Sprintf("t_%d_i_1_.*", p.ID)) + } } func (s *testSuite) TestChangePumpAndDrainer(c *C) { diff --git a/executor/split.go b/executor/split.go index ce1afaa4288b3..05e37428c1fcc 100755 --- a/executor/split.go +++ b/executor/split.go @@ -43,13 +43,14 @@ import ( type SplitIndexRegionExec struct { baseExecutor - tableInfo *model.TableInfo - indexInfo *model.IndexInfo - lower []types.Datum - upper []types.Datum - num int - valueLists [][]types.Datum - splitIdxKeys [][]byte + tableInfo *model.TableInfo + partitionNames []model.CIStr + indexInfo *model.IndexInfo + lower []types.Datum + upper []types.Datum + num int + valueLists [][]types.Datum + splitIdxKeys [][]byte done bool splitRegionResult @@ -115,38 +116,115 @@ func (e *SplitIndexRegionExec) splitIndexRegion(ctx context.Context) error { } func (e *SplitIndexRegionExec) getSplitIdxKeys() ([][]byte, error) { - var idxKeys [][]byte - if e.num > 0 { - idxKeys = make([][]byte, 0, e.num) - } else { - idxKeys = make([][]byte, 0, len(e.valueLists)+1) + // Split index regions by user specified value lists. + if len(e.valueLists) > 0 { + return e.getSplitIdxKeysFromValueList() + } + + return e.getSplitIdxKeysFromBound() +} + +func (e *SplitIndexRegionExec) getSplitIdxKeysFromValueList() (keys [][]byte, err error) { + pi := e.tableInfo.GetPartitionInfo() + if pi == nil { + keys = make([][]byte, 0, len(e.valueLists)+1) + return e.getSplitIdxPhysicalKeysFromValueList(e.tableInfo.ID, keys) + } + + // Split for all table partitions. + if len(e.partitionNames) == 0 { + keys = make([][]byte, 0, (len(e.valueLists)+1)*len(pi.Definitions)) + for _, p := range pi.Definitions { + keys, err = e.getSplitIdxPhysicalKeysFromValueList(p.ID, keys) + if err != nil { + return nil, err + } + } + return keys, nil + } + + // Split for specified table partitions. + keys = make([][]byte, 0, (len(e.valueLists)+1)*len(e.partitionNames)) + for _, name := range e.partitionNames { + pid, err := tables.FindPartitionByName(e.tableInfo, name.L) + if err != nil { + return nil, err + } + keys, err = e.getSplitIdxPhysicalKeysFromValueList(pid, keys) + if err != nil { + return nil, err + } + } + return keys, nil +} + +func (e *SplitIndexRegionExec) getSplitIdxPhysicalKeysFromValueList(physicalID int64, keys [][]byte) ([][]byte, error) { + keys = e.getSplitIdxPhysicalStartAndOtherIdxKeys(physicalID, keys) + index := tables.NewIndex(physicalID, e.tableInfo, e.indexInfo) + for _, v := range e.valueLists { + idxKey, _, err := index.GenIndexKey(e.ctx.GetSessionVars().StmtCtx, v, math.MinInt64, nil) + if err != nil { + return nil, err + } + keys = append(keys, idxKey) } + return keys, nil +} + +func (e *SplitIndexRegionExec) getSplitIdxPhysicalStartAndOtherIdxKeys(physicalID int64, keys [][]byte) [][]byte { // Split in the start of the index key. - startIdxKey := tablecodec.EncodeTableIndexPrefix(e.tableInfo.ID, e.indexInfo.ID) - idxKeys = append(idxKeys, startIdxKey) + startIdxKey := tablecodec.EncodeTableIndexPrefix(physicalID, e.indexInfo.ID) + keys = append(keys, startIdxKey) // Split in the end for the other index key. for _, idx := range e.tableInfo.Indices { if idx.ID <= e.indexInfo.ID { continue } - endIdxKey := tablecodec.EncodeTableIndexPrefix(e.tableInfo.ID, idx.ID) - idxKeys = append(idxKeys, endIdxKey) + endIdxKey := tablecodec.EncodeTableIndexPrefix(physicalID, idx.ID) + keys = append(keys, endIdxKey) break } + return keys +} - index := tables.NewIndex(e.tableInfo.ID, e.tableInfo, e.indexInfo) - // Split index regions by user specified value lists. - if len(e.valueLists) > 0 { - for _, v := range e.valueLists { - idxKey, _, err := index.GenIndexKey(e.ctx.GetSessionVars().StmtCtx, v, math.MinInt64, nil) +func (e *SplitIndexRegionExec) getSplitIdxKeysFromBound() (keys [][]byte, err error) { + pi := e.tableInfo.GetPartitionInfo() + if pi == nil { + keys = make([][]byte, 0, e.num) + return e.getSplitIdxPhysicalKeysFromBound(e.tableInfo.ID, keys) + } + + // Split for all table partitions. + if len(e.partitionNames) == 0 { + keys = make([][]byte, 0, e.num*len(pi.Definitions)) + for _, p := range pi.Definitions { + keys, err = e.getSplitIdxPhysicalKeysFromBound(p.ID, keys) if err != nil { return nil, err } - idxKeys = append(idxKeys, idxKey) } - return idxKeys, nil + return keys, nil + } + + // Split for specified table partitions. + keys = make([][]byte, 0, e.num*len(e.partitionNames)) + for _, name := range e.partitionNames { + pid, err := tables.FindPartitionByName(e.tableInfo, name.L) + if err != nil { + return nil, err + } + keys, err = e.getSplitIdxPhysicalKeysFromBound(pid, keys) + if err != nil { + return nil, err + } } + return keys, nil +} + +func (e *SplitIndexRegionExec) getSplitIdxPhysicalKeysFromBound(physicalID int64, keys [][]byte) ([][]byte, error) { + keys = e.getSplitIdxPhysicalStartAndOtherIdxKeys(physicalID, keys) + index := tables.NewIndex(physicalID, e.tableInfo, e.indexInfo) // Split index regions by lower, upper value and calculate the step by (upper - lower)/num. lowerIdxKey, _, err := index.GenIndexKey(e.ctx.GetSessionVars().StmtCtx, e.lower, math.MinInt64, nil) if err != nil { @@ -158,6 +236,7 @@ func (e *SplitIndexRegionExec) getSplitIdxKeys() ([][]byte, error) { if err != nil { return nil, err } + if bytes.Compare(lowerIdxKey, upperIdxKey) >= 0 { lowerStr, err1 := datumSliceToString(e.lower) upperStr, err2 := datumSliceToString(e.upper) @@ -166,7 +245,7 @@ func (e *SplitIndexRegionExec) getSplitIdxKeys() ([][]byte, error) { } return nil, errors.Errorf("Split index `%v` region lower value %v should less than the upper value %v", e.indexInfo.Name, lowerStr, upperStr) } - return getValuesList(lowerIdxKey, upperIdxKey, e.num, idxKeys), nil + return getValuesList(lowerIdxKey, upperIdxKey, e.num, keys), nil } // getValuesList is used to get `num` values between lower and upper value. @@ -245,12 +324,13 @@ func datumSliceToString(ds []types.Datum) (string, error) { type SplitTableRegionExec struct { baseExecutor - tableInfo *model.TableInfo - lower types.Datum - upper types.Datum - num int - valueLists [][]types.Datum - splitKeys [][]byte + tableInfo *model.TableInfo + partitionNames []model.CIStr + lower types.Datum + upper types.Datum + num int + valueLists [][]types.Datum + splitKeys [][]byte done bool splitRegionResult @@ -360,63 +440,130 @@ func isCtxDone(ctx context.Context) bool { } } -var minRegionStepValue = uint64(1000) +var minRegionStepValue = int64(1000) func (e *SplitTableRegionExec) getSplitTableKeys() ([][]byte, error) { + if len(e.valueLists) > 0 { + return e.getSplitTableKeysFromValueList() + } + + return e.getSplitTableKeysFromBound() +} + +func (e *SplitTableRegionExec) getSplitTableKeysFromValueList() ([][]byte, error) { var keys [][]byte - if e.num > 0 { - keys = make([][]byte, 0, e.num) - } else { + pi := e.tableInfo.GetPartitionInfo() + if pi == nil { keys = make([][]byte, 0, len(e.valueLists)) + return e.getSplitTablePhysicalKeysFromValueList(e.tableInfo.ID, keys), nil } - recordPrefix := tablecodec.GenTableRecordPrefix(e.tableInfo.ID) - if len(e.valueLists) > 0 { - for _, v := range e.valueLists { - key := tablecodec.EncodeRecordKey(recordPrefix, v[0].GetInt64()) - keys = append(keys, key) + + // Split for all table partitions. + if len(e.partitionNames) == 0 { + keys = make([][]byte, 0, len(e.valueLists)*len(pi.Definitions)) + for _, p := range pi.Definitions { + keys = e.getSplitTablePhysicalKeysFromValueList(p.ID, keys) + } + return keys, nil + } + + // Split for specified table partitions. + keys = make([][]byte, 0, len(e.valueLists)*len(e.partitionNames)) + for _, name := range e.partitionNames { + pid, err := tables.FindPartitionByName(e.tableInfo, name.L) + if err != nil { + return nil, err + } + keys = e.getSplitTablePhysicalKeysFromValueList(pid, keys) + } + return keys, nil +} + +func (e *SplitTableRegionExec) getSplitTablePhysicalKeysFromValueList(physicalID int64, keys [][]byte) [][]byte { + recordPrefix := tablecodec.GenTableRecordPrefix(physicalID) + for _, v := range e.valueLists { + key := tablecodec.EncodeRecordKey(recordPrefix, v[0].GetInt64()) + keys = append(keys, key) + } + return keys +} + +func (e *SplitTableRegionExec) getSplitTableKeysFromBound() ([][]byte, error) { + low, step, err := e.calculateBoundValue() + if err != nil { + return nil, err + } + var keys [][]byte + pi := e.tableInfo.GetPartitionInfo() + if pi == nil { + keys = make([][]byte, 0, e.num) + return e.getSplitTablePhysicalKeysFromBound(e.tableInfo.ID, low, step, keys), nil + } + + // Split for all table partitions. + if len(e.partitionNames) == 0 { + keys = make([][]byte, 0, e.num*len(pi.Definitions)) + for _, p := range pi.Definitions { + keys = e.getSplitTablePhysicalKeysFromBound(p.ID, low, step, keys) } return keys, nil } + + // Split for specified table partitions. + keys = make([][]byte, 0, e.num*len(e.partitionNames)) + for _, name := range e.partitionNames { + pid, err := tables.FindPartitionByName(e.tableInfo, name.L) + if err != nil { + return nil, err + } + keys = e.getSplitTablePhysicalKeysFromBound(pid, low, step, keys) + } + return keys, nil +} + +func (e *SplitTableRegionExec) calculateBoundValue() (lowerValue int64, step int64, err error) { isUnsigned := false if e.tableInfo.PKIsHandle { if pkCol := e.tableInfo.GetPkColInfo(); pkCol != nil { isUnsigned = mysql.HasUnsignedFlag(pkCol.Flag) } } - var step uint64 - var lowerValue int64 if isUnsigned { lowerRecordID := e.lower.GetUint64() upperRecordID := e.upper.GetUint64() if upperRecordID <= lowerRecordID { - return nil, errors.Errorf("Split table `%s` region lower value %v should less than the upper value %v", e.tableInfo.Name, lowerRecordID, upperRecordID) + return 0, 0, errors.Errorf("Split table `%s` region lower value %v should less than the upper value %v", e.tableInfo.Name, lowerRecordID, upperRecordID) } - step = (upperRecordID - lowerRecordID) / uint64(e.num) + step = int64(uint64(upperRecordID-lowerRecordID) / uint64(e.num)) lowerValue = int64(lowerRecordID) } else { lowerRecordID := e.lower.GetInt64() upperRecordID := e.upper.GetInt64() if upperRecordID <= lowerRecordID { - return nil, errors.Errorf("Split table `%s` region lower value %v should less than the upper value %v", e.tableInfo.Name, lowerRecordID, upperRecordID) + return 0, 0, errors.Errorf("Split table `%s` region lower value %v should less than the upper value %v", e.tableInfo.Name, lowerRecordID, upperRecordID) } - step = uint64(upperRecordID-lowerRecordID) / uint64(e.num) + step = (upperRecordID - lowerRecordID) / int64(e.num) lowerValue = lowerRecordID } if step < minRegionStepValue { - return nil, errors.Errorf("Split table `%s` region step value should more than %v, step %v is invalid", e.tableInfo.Name, minRegionStepValue, step) + return 0, 0, errors.Errorf("Split table `%s` region step value should more than %v, step %v is invalid", e.tableInfo.Name, minRegionStepValue, step) } + return lowerValue, step, nil +} +func (e *SplitTableRegionExec) getSplitTablePhysicalKeysFromBound(physicalID, low, step int64, keys [][]byte) [][]byte { + recordPrefix := tablecodec.GenTableRecordPrefix(physicalID) // Split a separate region for index. if len(e.tableInfo.Indices) > 0 { keys = append(keys, recordPrefix) } - recordID := lowerValue + recordID := low for i := 1; i < e.num; i++ { - recordID += int64(step) + recordID += step key := tablecodec.EncodeRecordKey(recordPrefix, recordID) keys = append(keys, key) } - return keys, nil + return keys } // RegionMeta contains a region's peer detail diff --git a/executor/split_test.go b/executor/split_test.go index c090faf20d3c7..45070c0e94f72 100644 --- a/executor/split_test.go +++ b/executor/split_test.go @@ -301,7 +301,7 @@ func (s *testSplitIndex) TestSplitTable(c *C) { }, }, } - defer func(originValue uint64) { + defer func(originValue int64) { minRegionStepValue = originValue }(minRegionStepValue) minRegionStepValue = 10 diff --git a/go.mod b/go.mod index 14a28dfa99a0e..fd8519f5c3f10 100644 --- a/go.mod +++ b/go.mod @@ -75,3 +75,5 @@ require ( ) go 1.13 + +replace github.com/pingcap/parser => github.com/crazycs520/parser v0.0.0-20191205092626-786232a0f1b2 diff --git a/go.sum b/go.sum index 975c41ac51ee8..c22a5063bc596 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,8 @@ github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/crazycs520/parser v0.0.0-20191205092626-786232a0f1b2 h1:XKKHXnmAaxYVLzhwptmrXji7Tt4fUxlG7fZXZyR7pDg= +github.com/crazycs520/parser v0.0.0-20191205092626-786232a0f1b2/go.mod h1:xLjI+gnWYexq011WPMEvCNS8rFM9qe1vdojIEzSKPuc= github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso= github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM= github.com/cznic/sortutil v0.0.0-20150617083342-4c7342852e65 h1:hxuZop6tSoOi0sxFzoGGYdRqNrPubyaIf9KoBG9tPiE= diff --git a/planner/core/common_plans.go b/planner/core/common_plans.go index 1117e6e0232f9..f1b4cfbe8d452 100644 --- a/planner/core/common_plans.go +++ b/planner/core/common_plans.go @@ -514,12 +514,13 @@ type LoadStats struct { type SplitRegion struct { baseSchemaProducer - TableInfo *model.TableInfo - IndexInfo *model.IndexInfo - Lower []types.Datum - Upper []types.Datum - Num int - ValueLists [][]types.Datum + TableInfo *model.TableInfo + PartitionNames []model.CIStr + IndexInfo *model.IndexInfo + Lower []types.Datum + Upper []types.Datum + Num int + ValueLists [][]types.Datum } // SplitRegionStatus represents a split regions status plan. diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 479c1c2c99a61..0db3ff2da6d49 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1834,8 +1834,9 @@ func (b *PlanBuilder) buildSplitIndexRegion(node *ast.SplitRegionStmt) (Plan, er mockTablePlan.SetSchema(schema) p := &SplitRegion{ - TableInfo: tblInfo, - IndexInfo: indexInfo, + TableInfo: tblInfo, + PartitionNames: node.PartitionNames, + IndexInfo: indexInfo, } p.SetSchema(buildSplitRegionsSchema()) // Split index regions by user specified value lists. @@ -1951,7 +1952,8 @@ func (b *PlanBuilder) buildSplitTableRegion(node *ast.SplitRegionStmt) (Plan, er mockTablePlan.SetSchema(schema) p := &SplitRegion{ - TableInfo: tblInfo, + TableInfo: tblInfo, + PartitionNames: node.PartitionNames, } p.SetSchema(buildSplitRegionsSchema()) if len(node.SplitOpt.ValueLists) > 0 { From 491ad7156a7c45a845f36d244b7e55ca54d9d3ba Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Thu, 5 Dec 2019 17:49:40 +0800 Subject: [PATCH 2/2] update parser goo.mod --- go.mod | 4 +--- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index fd8519f5c3f10..ede41f8384076 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20191106014506-c5d88d699a8d github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd - github.com/pingcap/parser v0.0.0-20191120072812-9dc33a611210 + github.com/pingcap/parser v0.0.0-20191205094455-91f36bd4dbcc github.com/pingcap/pd v1.1.0-beta.0.20190912093418-dc03c839debd github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible github.com/pingcap/tipb v0.0.0-20191120045257-1b9900292ab6 @@ -75,5 +75,3 @@ require ( ) go 1.13 - -replace github.com/pingcap/parser => github.com/crazycs520/parser v0.0.0-20191205092626-786232a0f1b2 diff --git a/go.sum b/go.sum index c22a5063bc596..bdb3a430b7d41 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,6 @@ github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/crazycs520/parser v0.0.0-20191205092626-786232a0f1b2 h1:XKKHXnmAaxYVLzhwptmrXji7Tt4fUxlG7fZXZyR7pDg= -github.com/crazycs520/parser v0.0.0-20191205092626-786232a0f1b2/go.mod h1:xLjI+gnWYexq011WPMEvCNS8rFM9qe1vdojIEzSKPuc= github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso= github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM= github.com/cznic/sortutil v0.0.0-20150617083342-4c7342852e65 h1:hxuZop6tSoOi0sxFzoGGYdRqNrPubyaIf9KoBG9tPiE= @@ -156,8 +154,8 @@ github.com/pingcap/kvproto v0.0.0-20191106014506-c5d88d699a8d h1:zTHgLr8+0LTEJmj github.com/pingcap/kvproto v0.0.0-20191106014506-c5d88d699a8d/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY= github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd h1:hWDol43WY5PGhsh3+8794bFHY1bPrmu6bTalpssCrGg= github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= -github.com/pingcap/parser v0.0.0-20191120072812-9dc33a611210 h1:RtNufGeP4yfSgjN0e9TSiNwq1eI4f5YKwNVNqX2OIXM= -github.com/pingcap/parser v0.0.0-20191120072812-9dc33a611210/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20191205094455-91f36bd4dbcc h1:xlLnj8xnQPR84gxR9a1G+7E5T9MSXGk62DQasfBQ1wY= +github.com/pingcap/parser v0.0.0-20191205094455-91f36bd4dbcc/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v1.1.0-beta.0.20190912093418-dc03c839debd h1:bKj6hodu/ro78B0oN2yicdGn0t4yd9XjnyoW95qmWic= github.com/pingcap/pd v1.1.0-beta.0.20190912093418-dc03c839debd/go.mod h1:I7TEby5BHTYIxgHszfsOJSBsk8b2Qt8QrSIgdv5n5QQ= github.com/pingcap/tidb-tools v3.0.6-0.20191119150227-ff0a3c6e5763+incompatible h1:I8HirWsu1MZp6t9G/g8yKCEjJJxtHooKakEgccvdJ4M=