Skip to content

Commit

Permalink
*: adapt new api for the executor package (#22644)
Browse files Browse the repository at this point in the history
Signed-off-by: xhe <xw897002528@gmail.com>
  • Loading branch information
xhebox authored Feb 4, 2021
1 parent e62d1d4 commit 4172f47
Show file tree
Hide file tree
Showing 23 changed files with 816 additions and 443 deletions.
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)
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

0 comments on commit 4172f47

Please sign in to comment.