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

planner: some cleanup #11164

Merged
merged 5 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 3 additions & 5 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ func evalAstExpr(ctx sessionctx.Context, expr ast.ExprNode) (types.Datum, error)
if val, ok := expr.(*driver.ValueExpr); ok {
return val.Datum, nil
}
b := &PlanBuilder{
ctx: ctx,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
var is infoschema.InfoSchema
if ctx.GetSessionVars().TxnCtx.InfoSchema != nil {
b.is = ctx.GetSessionVars().TxnCtx.InfoSchema.(infoschema.InfoSchema)
is = ctx.GetSessionVars().TxnCtx.InfoSchema.(infoschema.InfoSchema)
}
b := NewPlanBuilder(ctx, is)
fakePlan := LogicalTableDual{}.Init(ctx)
newExpr, _, err := b.rewrite(expr, fakePlan, nil, true)
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions planner/core/indexmerge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package core
import (
. "github.com/pingcap/check"
"github.com/pingcap/parser"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/sessionctx"
Expand Down Expand Up @@ -108,11 +107,7 @@ func (s *testIndexMergeSuite) TestIndexMergePathGenerateion(c *C) {
stmt, err := s.ParseOneStmt(tc.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
ctx: MockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(MockContext(), s.is)
p, err := builder.Build(stmt)
if err != nil {
c.Assert(err.Error(), Equals, tc.idxMergeDigest, comment)
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ func (b *PlanBuilder) buildDataSource(tn *ast.TableName) (LogicalPlan, error) {
if err != nil {
return nil, err
}
if txn.Valid() && !txn.IsReadOnly() {
if txn.Valid() && !txn.IsReadOnly() && !isMemDB {
us := LogicalUnionScan{}.Init(b.ctx)
us.SetChildren(ds)
result = us
Expand Down
43 changes: 7 additions & 36 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/parser"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
Expand Down Expand Up @@ -1714,11 +1713,7 @@ func (s *testPlanSuite) TestVisitInfo(c *C) {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
colMapper: make(map[*ast.ColumnNameExpr]int),
ctx: MockContext(),
is: s.is,
}
builder := NewPlanBuilder(MockContext(), s.is)
builder.ctx.GetSessionVars().HashJoinConcurrency = 1
_, err = builder.Build(stmt)
c.Assert(err, IsNil, comment)
Expand Down Expand Up @@ -1832,11 +1827,7 @@ func (s *testPlanSuite) TestUnion(c *C) {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
ctx: MockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(MockContext(), s.is)
plan, err := builder.Build(stmt)
if tt.err {
c.Assert(err, NotNil)
Expand Down Expand Up @@ -1964,11 +1955,7 @@ func (s *testPlanSuite) TestTopNPushDown(c *C) {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
ctx: MockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(MockContext(), s.is)
p, err := builder.Build(stmt)
c.Assert(err, IsNil)
p, err = logicalOptimize(builder.optFlag, p.(LogicalPlan))
Expand Down Expand Up @@ -2075,11 +2062,7 @@ func (s *testPlanSuite) TestOuterJoinEliminator(c *C) {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
ctx: MockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(MockContext(), s.is)
p, err := builder.Build(stmt)
c.Assert(err, IsNil)
p, err = logicalOptimize(builder.optFlag, p.(LogicalPlan))
Expand All @@ -2106,11 +2089,7 @@ func (s *testPlanSuite) TestSelectView(c *C) {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
ctx: MockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(MockContext(), s.is)
p, err := builder.Build(stmt)
c.Assert(err, IsNil)
p, err = logicalOptimize(builder.optFlag, p.(LogicalPlan))
Expand Down Expand Up @@ -2333,11 +2312,7 @@ func (s *testPlanSuite) TestWindowFunction(c *C) {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
ctx: MockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(MockContext(), s.is)
p, err := builder.Build(stmt)
if err != nil {
c.Assert(err.Error(), Equals, tt.result, comment)
Expand Down Expand Up @@ -2418,11 +2393,7 @@ func (s *testPlanSuite) TestSkylinePruning(c *C) {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
Preprocess(s.ctx, stmt, s.is)
builder := &PlanBuilder{
ctx: MockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(MockContext(), s.is)
p, err := builder.Build(stmt)
if err != nil {
c.Assert(err.Error(), Equals, tt.result, comment)
Expand Down
6 changes: 1 addition & 5 deletions planner/core/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ type logicalOptRule interface {
func BuildLogicalPlan(ctx sessionctx.Context, node ast.Node, is infoschema.InfoSchema) (Plan, error) {
ctx.GetSessionVars().PlanID = 0
ctx.GetSessionVars().PlanColumnID = 0
builder := &PlanBuilder{
ctx: ctx,
is: is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
builder := NewPlanBuilder(ctx, is)
p, err := builder.Build(node)
if err != nil {
return nil, err
Expand Down
6 changes: 2 additions & 4 deletions planner/core/planbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ func (s *testPlanBuilderSuite) TestGetPathByIndexName(c *C) {
}

func (s *testPlanBuilderSuite) TestRewriterPool(c *C) {
builder := &PlanBuilder{
ctx: MockContext(),
}
builder := NewPlanBuilder(MockContext(), nil)

// Make sure PlanBuilder.getExpressionRewriter() provides clean rewriter from pool.
// First, pick one rewriter from the pool and make it dirty.
Expand Down Expand Up @@ -149,7 +147,7 @@ func (s *testPlanBuilderSuite) TestDisableFold(c *C) {
stmt := st.(*ast.SelectStmt)
expr := stmt.Fields.Fields[0].Expr

builder := &PlanBuilder{ctx: ctx}
builder := NewPlanBuilder(ctx, nil)
builder.rewriterCounter++
rewriter := builder.getExpressionRewriter(nil)
c.Assert(rewriter, NotNil)
Expand Down
13 changes: 6 additions & 7 deletions planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ func (s *partitionProcessor) optimize(lp LogicalPlan) (LogicalPlan, error) {

func (s *partitionProcessor) rewriteDataSource(lp LogicalPlan) (LogicalPlan, error) {
// Assert there will not be sel -> sel in the ast.
switch lp.(type) {
switch p := lp.(type) {
case *DataSource:
return s.prune(lp.(*DataSource))
return s.prune(p)
case *LogicalUnionScan:
us := lp.(*LogicalUnionScan)
ds := us.Children()[0]
ds := p.Children()[0]
ds, err := s.prune(ds.(*DataSource))
if err != nil {
return nil, err
Expand All @@ -60,16 +59,16 @@ func (s *partitionProcessor) rewriteDataSource(lp LogicalPlan) (LogicalPlan, err
// Union->(UnionScan->DataSource1), (UnionScan->DataSource2)
children := make([]LogicalPlan, 0, len(ua.Children()))
for _, child := range ua.Children() {
us := LogicalUnionScan{}.Init(ua.ctx)
us := LogicalUnionScan{conditions: p.conditions}.Init(ua.ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line a bugfix? can we figure out a test case to cover it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, another separate PR #11187 is working on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged master branch

us.SetChildren(child)
children = append(children, us)
}
ua.SetChildren(children...)
return ua, nil
}
// Only one partition, no union all.
us.SetChildren(ds)
return us, nil
p.SetChildren(ds)
return p, nil
default:
children := lp.Children()
for i, child := range children {
Expand Down