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
*: index refactor for table partition #7062
Changes from all commits
2fe11e2
45af171
8b952bf
225dae7
a076e4f
5484c0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,31 @@ type Partition struct { | |
type PartitionedTable struct { | ||
Table | ||
partitionExpr *PartitionExpr | ||
partitions map[int64]*Partition | ||
} | ||
|
||
func newPartitionedTable(tbl *Table, tblInfo *model.TableInfo) (table.Table, error) { | ||
partitionExpr, err := generatePartitionExpr(tblInfo) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
partitions := make(map[int64]*Partition) | ||
pi := tblInfo.GetPartitionInfo() | ||
for _, p := range pi.Definitions { | ||
var t Partition | ||
err = initTableCommonWithIndices(&t.tableCommon, tblInfo, p.ID, tbl.Columns, tbl.alloc) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
partitions[p.ID] = &t | ||
} | ||
|
||
return &PartitionedTable{ | ||
Table: *tbl, | ||
partitionExpr: partitionExpr, | ||
partitions: partitions, | ||
}, nil | ||
} | ||
|
||
// PartitionExpr is the partition definition expressions. | ||
|
@@ -146,13 +171,7 @@ func (t *PartitionedTable) locatePartition(ctx sessionctx.Context, pi *model.Par | |
|
||
// GetPartition returns a Table, which is actually a Partition. | ||
func (t *PartitionedTable) GetPartition(pid int64) table.Table { | ||
var ret Partition | ||
// Make a shallow copy, change ID to partition ID. | ||
ret.tableCommon = t.tableCommon | ||
ret.partitionID = pid | ||
ret.recordPrefix = tablecodec.GenTableRecordPrefix(pid) | ||
ret.indexPrefix = tablecodec.GenTableIndexPrefix(pid) | ||
return &ret | ||
return t.partitions[pid] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
} | ||
|
||
// AddRecord implements the AddRecord method for the table.Table interface. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about s/IsPartition/GetPartitionID/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
IsPartition
maybe better.It's also flexible when we need the partition id:
GetPartitionID
looks unnatural if we define:If we use
partition id == 0
to represent it's not a partition:This code introduce an implicit assumption with the caller.