Skip to content

Commit

Permalink
*: change package name from plan to planner (pingcap#7760)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored and eurekaka committed Sep 25, 2018
1 parent 0001d2a commit e79bd94
Show file tree
Hide file tree
Showing 81 changed files with 461 additions and 461 deletions.
2 changes: 1 addition & 1 deletion cmd/importer/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/parser"
_ "github.com/pingcap/tidb/plan"
_ "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/mock"
"github.com/pkg/errors"
Expand Down
40 changes: 20 additions & 20 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/plan"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/terror"
Expand Down Expand Up @@ -123,12 +123,12 @@ func (a *recordSet) Close() error {
return errors.Trace(err)
}

// ExecStmt implements the ast.Statement interface, it builds a plan.Plan to an ast.Statement.
// ExecStmt implements the ast.Statement interface, it builds a planner.Plan to an ast.Statement.
type ExecStmt struct {
// InfoSchema stores a reference to the schema information.
InfoSchema infoschema.InfoSchema
// Plan stores a reference to the final physical plan.
Plan plan.Plan
Plan plannercore.Plan
// Expensive represents whether this query is an expensive one.
Expensive bool
// Cacheable represents whether the physical plan can be cached.
Expand All @@ -155,11 +155,11 @@ func (a *ExecStmt) IsPrepared() bool {

// IsReadOnly returns true if a statement is read only.
// It will update readOnlyCheckStmt if current ExecStmt can be conveted to
// a plan.Execute. Last step is using ast.IsReadOnly function to determine
// a plannercore.Execute. Last step is using ast.IsReadOnly function to determine
// a statement is read only or not.
func (a *ExecStmt) IsReadOnly() bool {
readOnlyCheckStmt := a.StmtNode
if checkPlan, ok := a.Plan.(*plan.Execute); ok {
if checkPlan, ok := a.Plan.(*plannercore.Execute); ok {
readOnlyCheckStmt = checkPlan.Stmt
}
return ast.IsReadOnly(readOnlyCheckStmt)
Expand All @@ -170,10 +170,10 @@ func (a *ExecStmt) IsReadOnly() bool {
func (a *ExecStmt) RebuildPlan() (int64, error) {
is := GetInfoSchema(a.Ctx)
a.InfoSchema = is
if err := plan.Preprocess(a.Ctx, a.StmtNode, is, false); err != nil {
if err := plannercore.Preprocess(a.Ctx, a.StmtNode, is, false); err != nil {
return 0, errors.Trace(err)
}
p, err := plan.Optimize(a.Ctx, a.StmtNode, is)
p, err := plannercore.Optimize(a.Ctx, a.StmtNode, is)
if err != nil {
return 0, errors.Trace(err)
}
Expand All @@ -187,7 +187,7 @@ func (a *ExecStmt) RebuildPlan() (int64, error) {
func (a *ExecStmt) Exec(ctx context.Context) (ast.RecordSet, error) {
a.startTime = time.Now()
sctx := a.Ctx
if _, ok := a.Plan.(*plan.Analyze); ok && sctx.GetSessionVars().InRestrictedSQL {
if _, ok := a.Plan.(*plannercore.Analyze); ok && sctx.GetSessionVars().InRestrictedSQL {
oriStats, _ := sctx.GetSessionVars().GetSystemVar(variable.TiDBBuildStatsConcurrency)
oriScan := sctx.GetSessionVars().DistSQLScanConcurrency
oriIndex := sctx.GetSessionVars().IndexSerialScanConcurrency
Expand Down Expand Up @@ -218,7 +218,7 @@ func (a *ExecStmt) Exec(ctx context.Context) (ast.RecordSet, error) {
if raw, ok := sctx.(processinfoSetter); ok {
pi = raw
sql := a.OriginText()
if simple, ok := a.Plan.(*plan.Simple); ok && simple.Statement != nil {
if simple, ok := a.Plan.(*plannercore.Simple); ok && simple.Statement != nil {
if ss, ok := simple.Statement.(ast.SensitiveStmtNode); ok {
// Use SecureText to avoid leak password information.
sql = ss.SecureText()
Expand Down Expand Up @@ -279,7 +279,7 @@ func (a *ExecStmt) handleNoDelayExecutor(ctx context.Context, sctx sessionctx.Co

// buildExecutor build a executor from plan, prepared statement may need additional procedure.
func (a *ExecStmt) buildExecutor(ctx sessionctx.Context) (Executor, error) {
if _, ok := a.Plan.(*plan.Execute); !ok {
if _, ok := a.Plan.(*plannercore.Execute); !ok {
// Do not sync transaction for Execute statement, because the real optimization work is done in
// "ExecuteExec.Build".
var err error
Expand All @@ -305,7 +305,7 @@ func (a *ExecStmt) buildExecutor(ctx sessionctx.Context) (Executor, error) {
}
}
}
if _, ok := a.Plan.(*plan.Analyze); ok && ctx.GetSessionVars().InRestrictedSQL {
if _, ok := a.Plan.(*plannercore.Analyze); ok && ctx.GetSessionVars().InRestrictedSQL {
ctx.GetSessionVars().StmtCtx.Priority = kv.PriorityLow
}

Expand Down Expand Up @@ -397,7 +397,7 @@ func (a *ExecStmt) logSlowQuery(txnTS uint64, succ bool) {
// 1. ctx is auto commit tagged
// 2. txn is nil
// 2. plan is point get by pk or unique key
func IsPointGetWithPKOrUniqueKeyByAutoCommit(ctx sessionctx.Context, p plan.Plan) bool {
func IsPointGetWithPKOrUniqueKeyByAutoCommit(ctx sessionctx.Context, p plannercore.Plan) bool {
// check auto commit
if !ctx.GetSessionVars().IsAutocommit() {
return false
Expand All @@ -409,24 +409,24 @@ func IsPointGetWithPKOrUniqueKeyByAutoCommit(ctx sessionctx.Context, p plan.Plan
}

// check plan
if proj, ok := p.(*plan.PhysicalProjection); ok {
if proj, ok := p.(*plannercore.PhysicalProjection); ok {
if len(proj.Children()) != 1 {
return false
}
p = proj.Children()[0]
}

switch v := p.(type) {
case *plan.PhysicalIndexReader:
indexScan := v.IndexPlans[0].(*plan.PhysicalIndexScan)
case *plannercore.PhysicalIndexReader:
indexScan := v.IndexPlans[0].(*plannercore.PhysicalIndexScan)
return indexScan.IsPointGetByUniqueKey(ctx.GetSessionVars().StmtCtx)
case *plan.PhysicalIndexLookUpReader:
indexScan := v.IndexPlans[0].(*plan.PhysicalIndexScan)
case *plannercore.PhysicalIndexLookUpReader:
indexScan := v.IndexPlans[0].(*plannercore.PhysicalIndexScan)
return indexScan.IsPointGetByUniqueKey(ctx.GetSessionVars().StmtCtx)
case *plan.PhysicalTableReader:
tableScan := v.TablePlans[0].(*plan.PhysicalTableScan)
case *plannercore.PhysicalTableReader:
tableScan := v.TablePlans[0].(*plannercore.PhysicalTableScan)
return len(tableScan.Ranges) == 1 && tableScan.Ranges[0].IsPoint(ctx.GetSessionVars().StmtCtx)
case *plan.PointGetPlan:
case *plannercore.PointGetPlan:
return true
default:
return false
Expand Down
8 changes: 4 additions & 4 deletions executor/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/plan"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
Expand Down Expand Up @@ -135,7 +135,7 @@ func (e *CheckIndexRangeExec) buildDAGPB() (*tipb.DAGRequest, error) {
execPB := e.constructIndexScanPB()
dagReq.Executors = append(dagReq.Executors, execPB)

err := plan.SetPBColumnsDefaultValue(e.ctx, dagReq.Executors[0].IdxScan.Columns, e.cols)
err := plannercore.SetPBColumnsDefaultValue(e.ctx, dagReq.Executors[0].IdxScan.Columns, e.cols)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func (e *RecoverIndexExec) buildDAGPB(txn kv.Transaction, limitCnt uint64) (*tip

tblInfo := e.table.Meta()
pbColumnInfos := model.ColumnsToProto(e.columns, tblInfo.PKIsHandle)
err := plan.SetPBColumnsDefaultValue(e.ctx, pbColumnInfos, e.columns)
err := plannercore.SetPBColumnsDefaultValue(e.ctx, pbColumnInfos, e.columns)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down Expand Up @@ -661,7 +661,7 @@ func (e *CleanupIndexExec) buildIdxDAGPB(txn kv.Transaction) (*tipb.DAGRequest,

execPB := e.constructIndexScanPB()
dagReq.Executors = append(dagReq.Executors, execPB)
err := plan.SetPBColumnsDefaultValue(e.ctx, dagReq.Executors[0].IdxScan.Columns, e.idxCols)
err := plannercore.SetPBColumnsDefaultValue(e.ctx, dagReq.Executors[0].IdxScan.Columns, e.idxCols)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down
50 changes: 25 additions & 25 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package executor_test

import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/plan"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/testkit"
)
Expand Down Expand Up @@ -446,39 +446,39 @@ func (s *testSuite) TestOnlyFullGroupBy(c *C) {
// test incompatible with sql_mode = ONLY_FULL_GROUP_BY
var err error
_, err = tk.Exec("select * from t group by d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select b-c from t group by b+c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select (b-c)*(b+c), min(a) from t group by b+c, b-c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select b between c and d from t group by b,c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select case b when 1 then c when 2 then d else d end from t group by b,c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select c > (select b from t) from t group by b")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select c is null from t group by b")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select c is true from t group by b")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select (c+b)*d from t group by c,d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select b in (c,d) from t group by b,c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select b like '%a' from t group by c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select c REGEXP '1.*' from t group by b")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select -b from t group by c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select a, max(b) from t")
c.Assert(terror.ErrorEqual(err, plan.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select sum(a)+b from t")
c.Assert(terror.ErrorEqual(err, plan.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select count(b), c from t")
c.Assert(terror.ErrorEqual(err, plan.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select distinct a, b, count(a) from t")
c.Assert(terror.ErrorEqual(err, plan.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrMixOfGroupFuncAndFields), IsTrue, Commentf("err %v", err))
// test compatible with sql_mode = ONLY_FULL_GROUP_BY
tk.MustQuery("select a from t group by a,b,c")
tk.MustQuery("select b from t group by b")
Expand Down Expand Up @@ -507,15 +507,15 @@ func (s *testSuite) TestOnlyFullGroupBy(c *C) {
tk.MustQuery("select * from t group by b,d")
// test functional depend on a unique null column
_, err = tk.Exec("select * from t group by b,c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
// test functional dependency derived from keys in where condition
tk.MustQuery("select * from t where c = d group by b, c")
tk.MustQuery("select t.*, x.* from t, x where t.a = x.a group by t.a")
tk.MustQuery("select t.*, x.* from t, x where t.b = x.b and t.d = x.d group by t.b, t.d")
tk.MustQuery("select t.*, x.* from t, x where t.b = x.a group by t.b, t.d")
tk.MustQuery("select t.b, x.* from t, x where t.b = x.a group by t.b")
_, err = tk.Exec("select t.*, x.* from t, x where t.c = x.a group by t.b, t.c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
// test functional dependency derived from keys in join
tk.MustQuery("select t.*, x.* from t inner join x on t.a = x.a group by t.a")
tk.MustQuery("select t.*, x.* from t inner join x on (t.b = x.b and t.d = x.d) group by t.b, x.d")
Expand All @@ -525,23 +525,23 @@ func (s *testSuite) TestOnlyFullGroupBy(c *C) {
tk.MustQuery("select x.b, t.* from t right join x on x.b = t.b group by x.b, t.d")
tk.MustQuery("select x.b, t.* from t right join x on t.b = x.b group by x.b, t.d")
_, err = tk.Exec("select t.b, x.* from t right join x on t.b = x.b group by t.b, x.d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("select t.b, x.* from t right join x on t.b = x.b group by t.b, x.d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))

// FixMe: test functional dependency of derived table
//tk.MustQuery("select * from (select * from t) as e group by a")
//tk.MustQuery("select * from (select * from t) as e group by b,d")
//_, err = tk.Exec("select * from (select * from t) as e group by b,c")
//c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
//c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue)

// test order by
tk.MustQuery("select c from t group by c,d order by d")
_, err = tk.Exec("select c from t group by c order by d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrFieldNotInGroupBy), IsTrue, Commentf("err %v", err))
// test ambiguous column
_, err = tk.Exec("select c from t,x group by t.c")
c.Assert(terror.ErrorEqual(err, plan.ErrAmbiguous), IsTrue, Commentf("err %v", err))
c.Assert(terror.ErrorEqual(err, plannercore.ErrAmbiguous), IsTrue, Commentf("err %v", err))
}

func (s *testSuite) TestHaving(c *C) {
Expand Down
Loading

0 comments on commit e79bd94

Please sign in to comment.