Skip to content

Commit

Permalink
Renamed partInfo to partDef/partition where it was actually a partDef
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss committed Jan 2, 2024
1 parent 5757002 commit 93c3a6f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
12 changes: 6 additions & 6 deletions pkg/executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type PointGetExecutor struct {
tblInfo *model.TableInfo
handle kv.Handle
idxInfo *model.IndexInfo
partInfo *model.PartitionDefinition
partition *model.PartitionDefinition
idxKey kv.Key
handleVal []byte
idxVals []types.Datum
Expand Down Expand Up @@ -162,7 +162,7 @@ func (e *PointGetExecutor) Init(p *plannercore.PointGetPlan) {
e.lockWaitTime = 0
}
e.rowDecoder = decoder
e.partInfo = p.PartitionInfo
e.partition = p.Partition
e.columns = p.Columns
e.buildVirtualColumnInfo()
}
Expand Down Expand Up @@ -221,8 +221,8 @@ func (e *PointGetExecutor) Next(ctx context.Context, req *chunk.Chunk) error {

var tblID int64
var err error
if e.partInfo != nil {
tblID = e.partInfo.ID
if e.partition != nil {
tblID = e.partition.ID
} else {
tblID = e.tblInfo.ID
}
Expand Down Expand Up @@ -510,8 +510,8 @@ func (e *PointGetExecutor) verifyTxnScope() error {
var tblName string
var partName string
is := e.Ctx().GetInfoSchema().(infoschema.InfoSchema)
if e.partInfo != nil {
tblID = e.partInfo.ID
if e.partition != nil {
tblID = e.partition.ID
tblInfo, _, partInfo := is.FindTableByPartitionID(tblID)
tblName = tblInfo.Meta().Name.String()
partName = partInfo.Name.String()
Expand Down
14 changes: 7 additions & 7 deletions pkg/planner/core/access_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ func (p *PointGetPlan) AccessObject() AccessObject {
Database: p.dbName,
Table: p.TblInfo.Name.O,
}
if p.PartitionInfo != nil {
res.Partitions = []string{p.PartitionInfo.Name.O}
if p.Partition != nil {
res.Partitions = []string{p.Partition.Name.O}
}
if p.IndexInfo != nil {
index := IndexAccess{
Expand All @@ -333,8 +333,8 @@ func (p *BatchPointGetPlan) AccessObject() AccessObject {
Database: p.dbName,
Table: p.TblInfo.Name.O,
}
for _, partitionInfo := range p.PartitionInfos {
res.Partitions = append(res.Partitions, partitionInfo.Name.O)
for _, partitionDef := range p.PartitionDefs {
res.Partitions = append(res.Partitions, partitionDef.Name.O)
}
if p.IndexInfo != nil {
index := IndexAccess{
Expand Down Expand Up @@ -414,13 +414,13 @@ func (p *PhysicalTableReader) accessObject(sctx sessionctx.Context) AccessObject
return DynamicPartitionAccessObjects{res}
}
if len(p.TableScanAndPartitionInfos) == 1 {
ts := p.TableScanAndPartitionInfos[0].tableScan
partInfo := p.TableScanAndPartitionInfos[0].physPlanPartInfo
tp := p.TableScanAndPartitionInfos[0]
ts := tp.tableScan
asName := ""
if ts.TableAsName != nil && len(ts.TableAsName.O) > 0 {
asName = ts.TableAsName.O
}
res := getDynamicAccessPartition(sctx, ts.Table, &partInfo, asName)
res := getDynamicAccessPartition(sctx, ts.Table, &tp.physPlanPartInfo, asName)
if res == nil {
return DynamicPartitionAccessObjects(nil)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2298,20 +2298,20 @@ func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candida
LockWaitTime: ds.SCtx().GetSessionVars().LockWaitTimeout,
Columns: ds.Columns,
}.Init(ds.SCtx(), ds.tableStats.ScaleByExpectCnt(accessCnt), ds.QueryBlockOffset())
var partitionInfo *model.PartitionDefinition
var partitionDef *model.PartitionDefinition
pi := ds.tableInfo.GetPartitionInfo()
if ds.isPartition {
// static prune
if pi != nil {
for i := range pi.Definitions {
def := pi.Definitions[i]
if def.ID == ds.physicalTableID {
partitionInfo = &def
partitionDef = &def
break
}
}
}
if partitionInfo == nil {
if partitionDef == nil {
return invalidTask
}
} else if pi != nil {
Expand All @@ -2324,9 +2324,9 @@ func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candida
if len(pi.Definitions) != 1 {
return invalidTask
}
partitionInfo = &pi.Definitions[0]
partitionDef = &pi.Definitions[0]
} else if len(idxs) == 1 {
partitionInfo = &pi.Definitions[idxs[0]]
partitionDef = &pi.Definitions[idxs[0]]
} else {
return invalidTask
}
Expand All @@ -2335,7 +2335,7 @@ func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candida
if candidate.path.IsIntHandlePath {
pointGetPlan.Handle = kv.IntHandle(candidate.path.Ranges[0].LowVal[0].GetInt64())
pointGetPlan.UnsignedHandle = mysql.HasUnsignedFlag(ds.handleCols.GetCol(0).RetType.GetFlag())
pointGetPlan.PartitionInfo = partitionInfo
pointGetPlan.Partition = partitionDef
pointGetPlan.accessCols = ds.TblCols
// Add filter condition to table plan now.
if len(candidate.path.TableFilters) > 0 {
Expand All @@ -2350,7 +2350,7 @@ func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candida
pointGetPlan.IdxCols = candidate.path.IdxCols
pointGetPlan.IdxColLens = candidate.path.IdxColLens
pointGetPlan.IndexValues = candidate.path.Ranges[0].LowVal
pointGetPlan.PartitionInfo = partitionInfo
pointGetPlan.Partition = partitionDef
if candidate.path.IsSingleScan {
pointGetPlan.accessCols = candidate.path.IdxCols
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/plan_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func rebuildRange(p Plan) error {
}
// The code should never run here as long as we're not using point get for partition table.
// And if we change the logic one day, here work as defensive programming to cache the error.
if x.PartitionInfo != nil {
if x.Partition != nil {
// TODO: relocate the partition after rebuilding range to make PlanCache support PointGet
return errors.New("point get for partition table can not use plan cache")
}
Expand Down
56 changes: 28 additions & 28 deletions pkg/planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type PointGetPlan struct {
schema *expression.Schema
TblInfo *model.TableInfo
IndexInfo *model.IndexInfo
PartitionInfo *model.PartitionDefinition
Partition *model.PartitionDefinition
Handle kv.Handle
HandleConstant *expression.Constant
handleFieldType *types.FieldType
Expand Down Expand Up @@ -272,8 +272,8 @@ func (p *PointGetPlan) MemoryUsage() (sum int64) {
if p.schema != nil {
sum += p.schema.MemoryUsage()
}
if p.PartitionInfo != nil {
sum += p.PartitionInfo.MemoryUsage()
if p.Partition != nil {
sum += p.Partition.MemoryUsage()
}
if p.HandleConstant != nil {
sum += p.HandleConstant.MemoryUsage()
Expand Down Expand Up @@ -315,7 +315,7 @@ type BatchPointGetPlan struct {
dbName string
TblInfo *model.TableInfo
IndexInfo *model.IndexInfo
PartitionInfos []*model.PartitionDefinition
PartitionDefs []*model.PartitionDefinition
Handles []kv.Handle
HandleType *types.FieldType
HandleParams []*expression.Constant // record all Parameters for Plan-Cache
Expand Down Expand Up @@ -493,7 +493,7 @@ func (p *BatchPointGetPlan) MemoryUsage() (sum int64) {

sum = emptyBatchPointGetPlanSize + p.baseSchemaProducer.MemoryUsage() + int64(len(p.dbName)) +
int64(cap(p.IdxColLens))*size.SizeOfInt + int64(cap(p.Handles))*size.SizeOfInterface +
int64(cap(p.PartitionInfos)+cap(p.HandleParams)+cap(p.IndexColTypes)+cap(p.IdxCols)+cap(p.Columns)+cap(p.accessCols))*size.SizeOfPointer
int64(cap(p.PartitionDefs)+cap(p.HandleParams)+cap(p.IndexColTypes)+cap(p.IdxCols)+cap(p.Columns)+cap(p.accessCols))*size.SizeOfPointer
if p.HandleType != nil {
sum += p.HandleType.MemoryUsage()
}
Expand Down Expand Up @@ -693,7 +693,7 @@ func newBatchPointGetPlan(
handleParams[i] = con
pairs := []nameValuePair{{colName: handleCol.Name.L, colFieldType: item.GetType(), value: *intDatum, con: con}}
if tbl.GetPartitionInfo() != nil {
tmpPartitionDefinition, _, pos, isTableDual := getPartitionInfo(ctx, tbl, pairs)
tmpPartitionDefinition, _, pos, isTableDual := getPartitionDef(ctx, tbl, pairs)
if isTableDual {
return nil
}
Expand All @@ -717,12 +717,12 @@ func newBatchPointGetPlan(
partitionInfos = nil
}
p := &BatchPointGetPlan{
TblInfo: tbl,
Handles: handles,
HandleParams: handleParams,
HandleType: &handleCol.FieldType,
PartitionExpr: partitionExpr,
PartitionInfos: partitionInfos,
TblInfo: tbl,
Handles: handles,
HandleParams: handleParams,
HandleType: &handleCol.FieldType,
PartitionExpr: partitionExpr,
PartitionDefs: partitionInfos,
}

return p.Init(ctx, statsInfo, schema, names, 0)
Expand Down Expand Up @@ -779,7 +779,7 @@ func newBatchPointGetPlan(

indexValues := make([][]types.Datum, len(patternInExpr.List))
indexValueParams := make([][]*expression.Constant, len(patternInExpr.List))
partitionInfos := make([]*model.PartitionDefinition, 0, len(patternInExpr.List))
partitionDefs := make([]*model.PartitionDefinition, 0, len(patternInExpr.List))
var pos2PartitionDefinition = make(map[int]*model.PartitionDefinition)

var indexTypes []*types.FieldType
Expand Down Expand Up @@ -881,7 +881,7 @@ func newBatchPointGetPlan(
indexValues[i] = values
indexValueParams[i] = valuesParams
if tbl.GetPartitionInfo() != nil {
tmpPartitionDefinition, _, pos, isTableDual := getPartitionInfo(ctx, tbl, pairs)
tmpPartitionDefinition, _, pos, isTableDual := getPartitionDef(ctx, tbl, pairs)
if isTableDual {
return nil
}
Expand All @@ -899,10 +899,10 @@ func newBatchPointGetPlan(
}
sort.Ints(posArr)
for _, pos := range posArr {
partitionInfos = append(partitionInfos, pos2PartitionDefinition[pos])
partitionDefs = append(partitionDefs, pos2PartitionDefinition[pos])
}
if len(partitionInfos) == 0 {
partitionInfos = nil
if len(partitionDefs) == 0 {
partitionDefs = nil
}
p := &BatchPointGetPlan{
TblInfo: tbl,
Expand All @@ -912,7 +912,7 @@ func newBatchPointGetPlan(
IndexColTypes: indexTypes,
PartitionColPos: pos,
PartitionExpr: partitionExpr,
PartitionInfos: partitionInfos,
PartitionDefs: partitionDefs,
}

return p.Init(ctx, statsInfo, schema, names, 0)
Expand Down Expand Up @@ -1062,21 +1062,21 @@ func tryPointGetPlan(ctx sessionctx.Context, selStmt *ast.SelectStmt, check bool
return nil
}

var partitionInfo *model.PartitionDefinition
var partitionDef *model.PartitionDefinition
var pos int
if pi != nil {
partitionInfo, pos, _, isTableDual = getPartitionInfo(ctx, tbl, pairs)
partitionDef, pos, _, isTableDual = getPartitionDef(ctx, tbl, pairs)
if isTableDual {
p := newPointGetPlan(ctx, tblName.Schema.O, schema, tbl, names)
p.IsTableDual = true
return p
}
if partitionInfo == nil {
if partitionDef == nil {
return checkTblIndexForPointPlan(ctx, tblName, schema, names, pairs, nil, pos, true, isTableDual, check)
}
// Take partition selection into consideration.
if len(tblName.PartitionNames) > 0 {
if !partitionNameInSet(partitionInfo.Name, tblName.PartitionNames) {
if !partitionNameInSet(partitionDef.Name, tblName.PartitionNames) {
p := newPointGetPlan(ctx, tblName.Schema.O, schema, tbl, names)
p.IsTableDual = true
return p
Expand All @@ -1097,17 +1097,17 @@ func tryPointGetPlan(ctx sessionctx.Context, selStmt *ast.SelectStmt, check bool
p.UnsignedHandle = mysql.HasUnsignedFlag(fieldType.GetFlag())
p.handleFieldType = fieldType
p.HandleConstant = handlePair.con
p.PartitionInfo = partitionInfo
p.Partition = partitionDef
return p
} else if handlePair.value.Kind() != types.KindNull {
return nil
}

return checkTblIndexForPointPlan(ctx, tblName, schema, names, pairs, partitionInfo, pos, false, isTableDual, check)
return checkTblIndexForPointPlan(ctx, tblName, schema, names, pairs, partitionDef, pos, false, isTableDual, check)
}

func checkTblIndexForPointPlan(ctx sessionctx.Context, tblName *ast.TableName, schema *expression.Schema,
names []*types.FieldName, pairs []nameValuePair, partitionInfo *model.PartitionDefinition,
names []*types.FieldName, pairs []nameValuePair, partitionDef *model.PartitionDefinition,
pos int, globalIndexCheck, isTableDual, check bool) *PointGetPlan {
if globalIndexCheck {
// when partitions are specified or some partition is in ddl, not use point get plan for global index.
Expand Down Expand Up @@ -1180,8 +1180,8 @@ func checkTblIndexForPointPlan(ctx sessionctx.Context, tblName *ast.TableName, s
p.IndexValues = idxValues
p.IndexConstants = idxConstant
p.ColsFieldType = colsFieldType
p.PartitionInfo = partitionInfo
if p.PartitionInfo != nil {
p.Partition = partitionDef
if p.Partition != nil {
p.partitionColumnPos = findPartitionIdx(idxInfo, pos, pairs)
}
return p
Expand Down Expand Up @@ -1875,7 +1875,7 @@ func buildHandleCols(ctx sessionctx.Context, tbl *model.TableInfo, schema *expre
return &IntHandleCols{col: handleCol}
}

func getPartitionInfo(ctx sessionctx.Context, tbl *model.TableInfo, pairs []nameValuePair) (*model.PartitionDefinition, int, int, bool) {
func getPartitionDef(ctx sessionctx.Context, tbl *model.TableInfo, pairs []nameValuePair) (*model.PartitionDefinition, int, int, bool) {
partitionExpr := getPartitionExpr(ctx, tbl)
if partitionExpr == nil {
return nil, 0, 0, false
Expand Down
8 changes: 4 additions & 4 deletions pkg/server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,8 @@ func (cc *clientConn) prefetchPointPlanKeys(ctx context.Context, stmts []ast.Stm
var tableID int64
switch v := p.(type) {
case *plannercore.PointGetPlan:
if v.PartitionInfo != nil {
tableID = v.PartitionInfo.ID
if v.Partition != nil {
tableID = v.Partition.ID
} else {
tableID = v.TblInfo.ID
}
Expand All @@ -1836,12 +1836,12 @@ func (cc *clientConn) prefetchPointPlanKeys(ctx context.Context, stmts []ast.Stm
rowKeys = append(rowKeys, tablecodec.EncodeRowKeyWithHandle(tableID, v.Handle))
}
case *plannercore.BatchPointGetPlan:
if v.PartitionInfos != nil && len(v.PartitionIDs) == 0 {
if v.PartitionDefs != nil && len(v.PartitionIDs) == 0 {
// skip when PartitionIDs is not initialized.
return nil
}
getPhysID := func(i int) int64 {
if v.PartitionInfos == nil {
if v.PartitionDefs == nil {
return v.TblInfo.ID
}
return v.PartitionIDs[i]
Expand Down
6 changes: 3 additions & 3 deletions pkg/statistics/handle/ddl/exchange_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func getCountsAndModifyCounts(
func exchangePartitionLogFields(
globalTableSchemaName string,
globalTableInfo *model.TableInfo,
originalPartInfo model.PartitionDefinition,
originalPartDef model.PartitionDefinition,
originalTableInfo *model.TableInfo,
countDelta, modifyCountDelta,
partCount, partModifyCount,
Expand All @@ -135,8 +135,8 @@ func exchangePartitionLogFields(
zap.String("globalTableName", globalTableInfo.Name.O),
zap.Int64("countDelta", countDelta),
zap.Int64("modifyCountDelta", modifyCountDelta),
zap.Int64("partitionID", originalPartInfo.ID),
zap.String("partitionName", originalPartInfo.Name.O),
zap.Int64("partitionID", originalPartDef.ID),
zap.String("partitionName", originalPartDef.Name.O),
zap.Int64("partitionCount", partCount),
zap.Int64("partitionModifyCount", partModifyCount),
zap.Int64("tableID", originalTableInfo.ID),
Expand Down

0 comments on commit 93c3a6f

Please sign in to comment.