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

executor: push down LIKE patterns for some infoschema readers #55844

Merged
merged 8 commits into from
Sep 23, 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
71 changes: 34 additions & 37 deletions pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ func (e *memtableRetriever) setDataFromPartitions(ctx context.Context, sctx sess
avgRowLength = dataLength / rowCount
}
// If there are any condition on the `PARTITION_NAME` in the extractor, this record should be ignored
if len(ex.ColPredicates["partition_name"]) > 0 {
if ex.HasPartitionPred() {
continue
}
record := types.MakeDatums(
Expand Down Expand Up @@ -3773,50 +3773,47 @@ func (e *memtableRetriever) setDataFromIndexUsage(ctx context.Context, sctx sess
dom := domain.GetDomain(sctx)
rows := make([][]types.Datum, 0, 100)
checker := privilege.GetPrivilegeManager(sctx)
extractor, ok := e.extractor.(*plannercore.InfoSchemaTiDBIndexUsageExtractor)
ex, ok := e.extractor.(*plannercore.InfoSchemaTiDBIndexUsageExtractor)
if !ok {
return errors.Errorf("wrong extractor type: %T, expected InfoSchemaIndexUsageExtractor", e.extractor)
}
if extractor.SkipRequest {
if ex.SkipRequest {
return nil
}

schemas := extractor.ListSchemas(e.is)
for _, schema := range schemas {
tbls, err := extractor.ListTables(ctx, schema, e.is)
if err != nil {
return errors.Trace(err)
schemas, tbls, err := ex.ListSchemasAndTables(ctx, e.is)
if err != nil {
return errors.Trace(err)
}
for i, tbl := range tbls {
schema := schemas[i]
if checker != nil && !checker.RequestVerification(
sctx.GetSessionVars().ActiveRoles,
schema.L, tbl.Name.L, "", mysql.AllPrivMask) {
continue
}

for _, tbl := range tbls {
if checker != nil && !checker.RequestVerification(
sctx.GetSessionVars().ActiveRoles,
schema.L, tbl.Name.L, "", mysql.AllPrivMask) {
continue
}

idxs := extractor.ListIndexes(tbl)
for _, idx := range idxs {
row := make([]types.Datum, 0, 14)
usage := dom.StatsHandle().GetIndexUsage(tbl.ID, idx.ID)
row = append(row, types.NewStringDatum(schema.O))
row = append(row, types.NewStringDatum(tbl.Name.O))
row = append(row, types.NewStringDatum(idx.Name.O))
row = append(row, types.NewIntDatum(int64(usage.QueryTotal)))
row = append(row, types.NewIntDatum(int64(usage.KvReqTotal)))
row = append(row, types.NewIntDatum(int64(usage.RowAccessTotal)))
for _, percentage := range usage.PercentageAccess {
row = append(row, types.NewIntDatum(int64(percentage)))
}
lastUsedAt := types.Datum{}
lastUsedAt.SetNull()
if !usage.LastUsedAt.IsZero() {
t := types.NewTime(types.FromGoTime(usage.LastUsedAt), mysql.TypeTimestamp, 0)
lastUsedAt = types.NewTimeDatum(t)
}
row = append(row, lastUsedAt)
rows = append(rows, row)
}
idxs := ex.ListIndexes(tbl)
for _, idx := range idxs {
row := make([]types.Datum, 0, 14)
usage := dom.StatsHandle().GetIndexUsage(tbl.ID, idx.ID)
row = append(row, types.NewStringDatum(schema.O))
row = append(row, types.NewStringDatum(tbl.Name.O))
row = append(row, types.NewStringDatum(idx.Name.O))
row = append(row, types.NewIntDatum(int64(usage.QueryTotal)))
row = append(row, types.NewIntDatum(int64(usage.KvReqTotal)))
row = append(row, types.NewIntDatum(int64(usage.RowAccessTotal)))
for _, percentage := range usage.PercentageAccess {
row = append(row, types.NewIntDatum(int64(percentage)))
}
lastUsedAt := types.Datum{}
lastUsedAt.SetNull()
if !usage.LastUsedAt.IsZero() {
t := types.NewTime(types.FromGoTime(usage.LastUsedAt), mysql.TypeTimestamp, 0)
lastUsedAt = types.NewTimeDatum(t)
}
row = append(row, lastUsedAt)
rows = append(rows, row)
}
}

Expand Down
Loading