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

*: adapt new api for the executor package #22644

Merged
merged 17 commits into from
Feb 4, 2021
23 changes: 13 additions & 10 deletions executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ package executor
import (
"bytes"
"context"
"fmt"
"math"
"math/rand"
"runtime"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -720,9 +720,14 @@ type AnalyzeFastExec struct {
}

func (e *AnalyzeFastExec) calculateEstimateSampleStep() (err error) {
sql := fmt.Sprintf("select flag from mysql.stats_histograms where table_id = %d;", e.tableID.GetStatisticsID())
exec := e.ctx.(sqlexec.RestrictedSQLExecutor)
var stmt ast.StmtNode
stmt, err = exec.ParseWithParams(context.TODO(), "select flag from mysql.stats_histograms where table_id = %?", e.tableID.GetStatisticsID())
if err != nil {
return
}
var rows []chunk.Row
rows, _, err = e.ctx.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(sql)
rows, _, err = exec.ExecRestrictedStmt(context.TODO(), stmt)
if err != nil {
return
}
Expand All @@ -746,22 +751,20 @@ func (e *AnalyzeFastExec) calculateEstimateSampleStep() (err error) {
err = rollbackFn()
}
}()
sql := new(strings.Builder)
sqlexec.MustFormatSQL(sql, "select count(*) from %n.%n", dbInfo.Name.L, e.tblInfo.Name.L)

pruneMode := variable.PartitionPruneMode(e.ctx.GetSessionVars().PartitionPruneMode.Load())
var partition string
if pruneMode != variable.DynamicOnly && e.tblInfo.ID != e.tableID.GetStatisticsID() {
for _, definition := range e.tblInfo.Partition.Definitions {
if definition.ID == e.tableID.GetStatisticsID() {
partition = fmt.Sprintf(" partition(%s)", definition.Name.L)
sqlexec.MustFormatSQL(sql, " partition(%n)", definition.Name.L)
break
}
}
}
sql := fmt.Sprintf("select count(*) from %s.%s", dbInfo.Name.L, e.tblInfo.Name.L)
if len(partition) > 0 {
sql += partition
}
var rs sqlexec.RecordSet
rs, err = e.ctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), sql)
rs, err = e.ctx.(sqlexec.SQLExecutor).ExecuteInternal(context.TODO(), sql.String())
if err != nil {
return
}
Expand Down
1 change: 1 addition & 0 deletions executor/brie.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func (gs *tidbGlueSession) CreateSession(store kv.Storage) (glue.Session, error)

// Execute implements glue.Session
func (gs *tidbGlueSession) Execute(ctx context.Context, sql string) error {
// FIXME: br relies on a deprecated API, it may be unsafe
_, err := gs.se.(sqlexec.SQLExecutor).Execute(ctx, sql)
morgo marked this conversation as resolved.
Show resolved Hide resolved
return err
}
Expand Down
8 changes: 6 additions & 2 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,12 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx
zap.String("database", fullti.Schema.O),
zap.String("table", fullti.Name.O),
)
sql := fmt.Sprintf("admin check table `%s`.`%s`", fullti.Schema.O, fullti.Name.O)
_, _, err = e.ctx.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(sql)
exec := e.ctx.(sqlexec.RestrictedSQLExecutor)
stmt, err := exec.ParseWithParams(context.TODO(), "admin check table %n.%n", fullti.Schema.O, fullti.Name.O)
if err != nil {
return err
}
_, _, err = exec.ExecRestrictedStmt(context.TODO(), stmt)
if err != nil {
return err
}
Expand Down
Loading