Skip to content
Open
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
6 changes: 0 additions & 6 deletions pkg/executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,6 @@ func (b *executorBuilder) buildCheckTable(v *plannercore.CheckTable) exec.Execut
noMVIndexOrPrefixIndexOrColumnarIndex = false
break
}
for _, col := range idx.Columns {
if col.Length != types.UnspecifiedLength {
noMVIndexOrPrefixIndexOrColumnarIndex = false
break
}
}
if !noMVIndexOrPrefixIndexOrColumnarIndex {
break
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/executor/check_table_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ func (w *checkIndexWorker) HandleTask(task checkIndexTask, _ func(workerpool.Non
indexColNames := make([]string, len(idxInfo.Columns))
for i, col := range idxInfo.Columns {
tblCol := tblMeta.Columns[col.Offset]
if tblCol.IsVirtualGenerated() && tblCol.Hidden {
indexColNames[i] = tblCol.GeneratedExprString
if col.Length == types.UnspecifiedLength {
indexColNames[i] = ColumnName(tblCol.Name.O)
} else {
indexColNames[i] = ColumnName(col.Name.O)
indexColNames[i] = fmt.Sprintf("CAST(%s AS CHAR(%d))", ColumnName(col.Name.O), col.Length)
}
}
indexColumns := strings.Join(indexColNames, ",")
Expand Down
45 changes: 45 additions & 0 deletions pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/pingcap/tidb/pkg/expression/exprctx"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta/autoid"
"github.com/pingcap/tidb/pkg/meta/metadef"
"github.com/pingcap/tidb/pkg/meta/model"
"github.com/pingcap/tidb/pkg/parser"
Expand Down Expand Up @@ -4431,6 +4432,44 @@ func (b *PlanBuilder) buildDataSourceFromCTEMerge(ctx context.Context, cte *ast.
return p, nil
}

// buildTableForAdminCheckSQL make a copy of table info if necessary.
// Since we want to utilize MVIndex/prefix index/virtual column to read the data in FAST ADMIN CHECK,
// to prevent from adding many hacky code in planner, we create a mock table info without these meta.
// So we can guarantee to use index only scan for index SQL in FAST ADMIN CHECK.
func buildTableForAdminCheckSQL(tbl table.Table) (table.Table, error) {
tblInfo := tbl.Meta()

// If table contains any index column with prefix length/hidden column/MVIndex, ,
needRebuildInfo := false
for _, idx := range tblInfo.Indices {
if idx.MVIndex {
needRebuildInfo = true
}
for _, col := range idx.Columns {
if col.Length != types.UnspecifiedLength || tblInfo.Columns[col.Offset].Hidden {
needRebuildInfo = true
}
}
}

if !needRebuildInfo {
return tbl, nil
}

mockInfo := tbl.Meta().Clone()
for _, idx := range mockInfo.Indices {
idx.MVIndex = false
for _, col := range idx.Columns {
col.Length = types.UnspecifiedLength
tblCol := mockInfo.Columns[col.Offset]
tblCol.FieldType.SetArray(false)
tblCol.Hidden = false
}
}

return tables.TableFromMeta(autoid.NewAllocators(false, nil), mockInfo)
}

func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, asName *ast.CIStr) (base.LogicalPlan, error) {
b.optFlag |= rule.FlagPredicateSimplification
dbName := tn.Schema
Expand Down Expand Up @@ -4458,6 +4497,12 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
return nil, err
}

// if kv.GetInternalSourceType(ctx) == kv.InternalTxnAdmin {
if tbl, err = buildTableForAdminCheckSQL(tbl); err != nil {
return nil, err
}
// }

tbl, err = tryLockMDLAndUpdateSchemaIfNecessary(ctx, b.ctx, dbName, tbl, b.is)
if err != nil {
return nil, err
Expand Down