Skip to content

Commit

Permalink
planner: add table info into context in fast plan case (#11446) (#11457)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored and zz-jason committed Jul 30, 2019
1 parent b96aa43 commit a93a97a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2461,3 +2461,45 @@ func (s *testPlanSuite) TestSkylinePruning(c *C) {
c.Assert(pathsName(paths), Equals, tt.result)
}
}

func (s *testPlanSuite) TestFastPlanContextTables(c *C) {
defer testleak.AfterTest(c)()
tests := []struct {
sql string
fastPlan bool
}{
{
"select * from t where a=1",
true,
},
{

"update t set f=0 where a=43215",
true,
},
{
"delete from t where a =43215",
true,
},
{
"select * from t where a>1",
false,
},
}
for _, tt := range tests {
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil)
Preprocess(s.ctx, stmt, s.is)
s.ctx.GetSessionVars().StmtCtx.Tables = nil
p := TryFastPlan(s.ctx, stmt)
if tt.fastPlan {
c.Assert(p, NotNil)
c.Assert(len(s.ctx.GetSessionVars().StmtCtx.Tables), Equals, 1)
c.Assert(s.ctx.GetSessionVars().StmtCtx.Tables[0].Table, Equals, "t")
c.Assert(s.ctx.GetSessionVars().StmtCtx.Tables[0].DB, Equals, "test")
} else {
c.Assert(p, IsNil)
c.Assert(len(s.ctx.GetSessionVars().StmtCtx.Tables), Equals, 0)
}
}
}
2 changes: 2 additions & 0 deletions planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/planner/property"
"github.com/pingcap/tidb/privilege"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/parser_driver"
"github.com/pingcap/tipb/go-tipb"
Expand Down Expand Up @@ -267,6 +268,7 @@ func newPointGetPlan(ctx sessionctx.Context, schema *expression.Schema, tbl *mod
schema: schema,
TblInfo: tbl,
}
ctx.GetSessionVars().StmtCtx.Tables = []stmtctx.TableEntry{{DB: ctx.GetSessionVars().CurrentDB, Table: tbl.Name.L}}
return p
}

Expand Down

0 comments on commit a93a97a

Please sign in to comment.