Skip to content
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

planner: forbid generate PointGet plan with partition table + _tidb_rowid #54592

Merged
merged 8 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1401,6 +1401,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 @@ -1418,6 +1419,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 path != nil && path.Index != nil && path.Index.Global {
// Don't convert to point get during ddl
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 @@ -339,6 +339,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 @@ -1709,7 +1720,11 @@ func getNameValuePairs(ctx base.PlanContext, tbl *model.TableInfo, tblName model
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