Skip to content

Commit

Permalink
*: move hint and block hint processor to util directory (#15897) (#15900
Browse files Browse the repository at this point in the history
)

Co-authored-by: Kenan Yao <cauchy1992@gmail.com>
  • Loading branch information
sre-bot and eurekaka authored Mar 31, 2020
1 parent ba4de0c commit 52bf81d
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 344 deletions.
145 changes: 0 additions & 145 deletions bindinfo/bind.go

This file was deleted.

5 changes: 3 additions & 2 deletions bindinfo/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/hint"
)

const (
Expand Down Expand Up @@ -49,7 +50,7 @@ type Binding struct {
Charset string
Collation string
// Hint is the parsed hints, it is used to bind hints to stmt node.
Hint *HintsSet
Hint *hint.HintsSet
// ID is the string form of Hint. It would be non-empty only when the status is `Using` or `PendingVerify`.
ID string
}
Expand Down Expand Up @@ -116,7 +117,7 @@ func (br *BindRecord) prepareHints(sctx sessionctx.Context) error {
return err
}
}
hintsSet, err := ParseHintsSet(p, bind.BindSQL, bind.Charset, bind.Collation)
hintsSet, err := hint.ParseHintsSet(p, bind.BindSQL, bind.Charset, bind.Collation)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/tidb/types"
driver "github.com/pingcap/tidb/types/parser_driver"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/hint"
"github.com/pingcap/tidb/util/logutil"
utilparser "github.com/pingcap/tidb/util/parser"
"github.com/pingcap/tidb/util/sqlexec"
Expand Down Expand Up @@ -665,7 +666,7 @@ func GenerateBindSQL(ctx context.Context, stmtNode ast.StmtNode, planHint string
}
// We need to evolve plan based on the current sql, not the original sql which may have different parameters.
// So here we would remove the hint and inject the current best plan hint.
BindHint(stmtNode, &HintsSet{})
hint.BindHint(stmtNode, &hint.HintsSet{})
var sb strings.Builder
restoreCtx := format.NewRestoreCtx(format.DefaultRestoreFlags, &sb)
err := stmtNode.Restore(restoreCtx)
Expand Down
3 changes: 2 additions & 1 deletion executor/prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
driver "github.com/pingcap/tidb/types/parser_driver"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/hint"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/stringutil"
"go.uber.org/zap"
Expand Down Expand Up @@ -188,7 +189,7 @@ func (e *PrepareExec) Next(ctx context.Context, req *chunk.Chunk) error {
var p plannercore.Plan
e.ctx.GetSessionVars().PlanID = 0
e.ctx.GetSessionVars().PlanColumnID = 0
destBuilder := plannercore.NewPlanBuilder(e.ctx, e.is, &plannercore.BlockHintProcessor{})
destBuilder := plannercore.NewPlanBuilder(e.ctx, e.is, &hint.BlockHintProcessor{})
p, err = destBuilder.Build(ctx, stmt)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/format"
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/hint"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/stringutil"
)
Expand Down Expand Up @@ -448,7 +449,7 @@ func (e *ShowExec) fetchShowColumns(ctx context.Context) error {
if tb.Meta().IsView() {
// Because view's undertable's column could change or recreate, so view's column type may change overtime.
// To avoid this situation we need to generate a logical plan and extract current column types from Schema.
planBuilder := plannercore.NewPlanBuilder(e.ctx, e.is, &plannercore.BlockHintProcessor{})
planBuilder := plannercore.NewPlanBuilder(e.ctx, e.is, &hint.BlockHintProcessor{})
viewLogicalPlan, err := planBuilder.BuildDataSourceFromView(ctx, e.DBName, tb.Meta())
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
driver "github.com/pingcap/tidb/types/parser_driver"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/hint"
"github.com/pingcap/tidb/util/stringutil"
)

Expand All @@ -49,7 +50,7 @@ func evalAstExpr(sctx sessionctx.Context, expr ast.ExprNode) (types.Datum, error
if sctx.GetSessionVars().TxnCtx.InfoSchema != nil {
is = sctx.GetSessionVars().TxnCtx.InfoSchema.(infoschema.InfoSchema)
}
b := NewPlanBuilder(sctx, is, &BlockHintProcessor{})
b := NewPlanBuilder(sctx, is, &hint.BlockHintProcessor{})
fakePlan := LogicalTableDual{}.Init(sctx, 0)
newExpr, _, err := b.rewrite(context.TODO(), expr, fakePlan, nil, true)
if err != nil {
Expand Down
Loading

0 comments on commit 52bf81d

Please sign in to comment.