Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <disxiaofei@163.com>
  • Loading branch information
Yisaer committed Dec 13, 2021
1 parent df3965a commit 0668001
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 3 deletions.
12 changes: 12 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,18 @@ func (s *testIntegrationSuite3) TestCreateTableWithKeyPartition(c *C) {
tk.MustExec(`create table tm2 (a char(5), unique key(a(5))) partition by key() partitions 5;`)
}

func (s *testIntegrationSuite5) TestTry(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("create table t (x int) partition by hash(x) partitions 4;")
ctx := tk.Se.(sessionctx.Context)
is := domain.GetDomain(ctx).InfoSchema()
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
c.Assert(err, IsNil)
p := tbl.Meta().Partition
fmt.Println(p)
}

func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
Expand Down
3 changes: 2 additions & 1 deletion planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ type testPlanSuite struct {
}

func (s *testPlanSuite) SetUpSuite(c *C) {
s.is = infoschema.MockInfoSchema([]*model.TableInfo{MockSignedTable(), MockUnsignedTable(), MockView(), MockNoPKTable(), MockPartitionTable()})
s.is = infoschema.MockInfoSchema([]*model.TableInfo{MockSignedTable(), MockUnsignedTable(), MockView(), MockNoPKTable(),
MockRangePartitionTable(), MockHashPartitionTable(), MockListPartitionTable()})
s.ctx = MockContext()
domain.GetDomain(s.ctx).MockInfoCacheAndLoadInfoSchema(s.is)
s.ctx.GetSessionVars().EnableWindowFunction = true
Expand Down
44 changes: 44 additions & 0 deletions planner/core/logical_plan_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,50 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) {
assertRuleName string
assertRuleSteps []assertTraceStep
}{
{
sql: "select * from pt3 where ptn > 3;",
flags: []uint64{flagPartitionProcessor, flagPredicatePushDown, flagBuildKeyInfo, flagPrunColumns},
assertRuleName: "partition_processor",
assertRuleSteps: []assertTraceStep{
{
assertReason: "Datasource[1] have multi available partition tables[p1,p2] after partition pruning",
assertAction: "Datasource[1] becomes PartitionUnion[6] with children[TableScan[1],TableScan[1]]",
},
},
},
{
sql: "select * from pt3 where ptn = 1;",
flags: []uint64{flagPartitionProcessor, flagPredicatePushDown, flagBuildKeyInfo, flagPrunColumns},
assertRuleName: "partition_processor",
assertRuleSteps: []assertTraceStep{
{
assertReason: "Datasource[1] has one available partiton table[p1] after partition pruning",
assertAction: "Datasource[1] becomes TableScan[1]",
},
},
},
{
sql: "select * from pt2 where ptn in (1,2,3);",
flags: []uint64{flagPartitionProcessor, flagPredicatePushDown, flagBuildKeyInfo, flagPrunColumns},
assertRuleName: "partition_processor",
assertRuleSteps: []assertTraceStep{
{
assertReason: "Datasource[1] have multi available partition tables[p1,p2] after partition pruning",
assertAction: "Datasource[1] becomes PartitionUnion[7] with children[TableScan[1],TableScan[1]]",
},
},
},
{
sql: "select * from pt2 where ptn = 1;",
flags: []uint64{flagPartitionProcessor, flagPredicatePushDown, flagBuildKeyInfo, flagPrunColumns},
assertRuleName: "partition_processor",
assertRuleSteps: []assertTraceStep{
{
assertReason: "Datasource[1] has one available partiton table[p2] after partition pruning",
assertAction: "Datasource[1] becomes TableScan[1]",
},
},
},
{
sql: "select * from pt1 where ptn > 100;",
flags: []uint64{flagPartitionProcessor, flagPredicatePushDown, flagBuildKeyInfo, flagPrunColumns},
Expand Down
84 changes: 82 additions & 2 deletions planner/core/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ func MockPartitionInfoSchema(definitions []model.PartitionDefinition) infoschema
return is
}

// MockPartitionTable mocks a partition table for test
func MockPartitionTable() *model.TableInfo {
// MockRangePartitionTable mocks a range partition table for test
func MockRangePartitionTable() *model.TableInfo {
definitions := []model.PartitionDefinition{
{
ID: 41,
Expand Down Expand Up @@ -469,3 +469,83 @@ func MockPartitionTable() *model.TableInfo {
tableInfo.Partition = partition
return tableInfo
}

func MockHashPartitionTable() *model.TableInfo {
definitions := []model.PartitionDefinition{
{
ID: 51,
Name: model.NewCIStr("p1"),
},
{
ID: 52,
Name: model.NewCIStr("p2"),
},
}
tableInfo := MockSignedTable()
tableInfo.Name = model.NewCIStr("pt2")
cols := make([]*model.ColumnInfo, 0, len(tableInfo.Columns))
cols = append(cols, tableInfo.Columns...)
last := tableInfo.Columns[len(tableInfo.Columns)-1]
cols = append(cols, &model.ColumnInfo{
State: model.StatePublic,
Offset: last.Offset + 1,
Name: model.NewCIStr("ptn"),
FieldType: newLongType(),
ID: last.ID + 1,
})
partition := &model.PartitionInfo{
Type: model.PartitionTypeHash,
Expr: "ptn",
Enable: true,
Definitions: definitions,
Num: 2,
}
tableInfo.Columns = cols
tableInfo.Partition = partition
return tableInfo
}

func MockListPartitionTable() *model.TableInfo {
definitions := []model.PartitionDefinition{
{
ID: 61,
Name: model.NewCIStr("p1"),
InValues: [][]string{
{
"1",
},
},
},
{
ID: 62,
Name: model.NewCIStr("p2"),
InValues: [][]string{
{
"2",
},
},
},
}
tableInfo := MockSignedTable()
tableInfo.Name = model.NewCIStr("pt3")
cols := make([]*model.ColumnInfo, 0, len(tableInfo.Columns))
cols = append(cols, tableInfo.Columns...)
last := tableInfo.Columns[len(tableInfo.Columns)-1]
cols = append(cols, &model.ColumnInfo{
State: model.StatePublic,
Offset: last.Offset + 1,
Name: model.NewCIStr("ptn"),
FieldType: newLongType(),
ID: last.ID + 1,
})
partition := &model.PartitionInfo{
Type: model.PartitionTypeList,
Expr: "ptn",
Enable: true,
Definitions: definitions,
Num: 2,
}
tableInfo.Columns = cols
tableInfo.Partition = partition
return tableInfo
}

0 comments on commit 0668001

Please sign in to comment.