Skip to content

Commit

Permalink
planner: forbid generate PointGet plan with partition table + `_tid…
Browse files Browse the repository at this point in the history
…b_rowid` (#54592) (#54772)

close #54583
  • Loading branch information
ti-chi-bot authored Jul 19, 2024
1 parent ae394c6 commit 5299985
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 178 deletions.
5 changes: 5 additions & 0 deletions pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter
if canConvertPointGet && ds.table.Meta().GetPartitionInfo() != nil {
// partition table with dynamic prune not support batchPointGet
// Due to sorting?
// Please make sure handle `where _tidb_rowid in (xx, xx)` correctly when delete this if statements.
if canConvertPointGet && len(path.Ranges) > 1 && ds.SCtx().GetSessionVars().StmtCtx.UseDynamicPartitionPrune() {
canConvertPointGet = false
}
Expand All @@ -1468,6 +1469,10 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter
canConvertPointGet = false
}
}
// Partition table can't use `_tidb_rowid` to generate PointGet Plan unless one partition is explicitly specified.
if canConvertPointGet && path.IsIntHandlePath && !ds.table.Meta().PKIsHandle && len(ds.partitionNames) != 1 {
canConvertPointGet = false
}
if canConvertPointGet {
// If the schema contains ExtraPidColID, do not convert to point get.
// Because the point get executor can not handle the extra partition ID column now.
Expand Down
17 changes: 16 additions & 1 deletion pkg/planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ func (p *PointGetPlan) PrunePartitions(sctx sessionctx.Context) bool {
// reading for the Global Index / table id
return false
}
// _tidb_rowid + specify a partition
if p.IndexInfo == nil && !p.TblInfo.HasClusteredIndex() && len(p.PartitionNames) == 1 {
for i, def := range pi.Definitions {
if def.Name.L == p.PartitionNames[0].L {
idx := i
p.PartitionIdx = &idx
break
}
}
return false
}
// If tryPointGetPlan did generate the plan,
// then PartitionIdx is not set and needs to be set here!
// There are two ways to get here from static mode partition pruning:
Expand Down Expand Up @@ -1696,7 +1707,11 @@ func getNameValuePairs(ctx PlanContext, tbl *model.TableInfo, tblName model.CISt
return nil, false
}
col := model.FindColumnInfo(tbl.Cols(), colName.Name.Name.L)
if col == nil { // Handling the case when the column is _tidb_rowid.
if col == nil {
// Partition table can't use `_tidb_rowid` to generate PointGet Plan.
if tbl.GetPartitionInfo() != nil && colName.Name.Name.L == model.ExtraHandleName.L {
return nil, false
}
return append(nvPairs, nameValuePair{colName: colName.Name.Name.L, colFieldType: types.NewFieldType(mysql.TypeLonglong), value: d, con: con}), false
}

Expand Down
Loading

0 comments on commit 5299985

Please sign in to comment.