Skip to content

Commit

Permalink
plan: move test. (#2569)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 authored Jan 29, 2017
1 parent e68dcf7 commit df6e1b3
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 189 deletions.
189 changes: 0 additions & 189 deletions plan/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package plan

import (
"fmt"
"testing"

. "github.com/pingcap/check"
Expand All @@ -25,7 +24,6 @@ import (
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testleak"
Expand Down Expand Up @@ -1094,193 +1092,6 @@ func (s *testPlanSuite) TestAllocID(c *C) {
c.Assert(pA.id, Equals, pB.id)
}

func (s *testPlanSuite) TestRangeBuilder(c *C) {
defer testleak.AfterTest(c)()
rb := &rangeBuilder{sc: new(variable.StatementContext)}

cases := []struct {
exprStr string
resultStr string
}{
{
exprStr: "a = 1",
resultStr: "[[1 1]]",
},
{
exprStr: "1 = a",
resultStr: "[[1 1]]",
},
{
exprStr: "a != 1",
resultStr: "[[-inf 1) (1 +inf]]",
},
{
exprStr: "1 != a",
resultStr: "[[-inf 1) (1 +inf]]",
},
{
exprStr: "a > 1",
resultStr: "[(1 +inf]]",
},
{
exprStr: "1 < a",
resultStr: "[(1 +inf]]",
},
{
exprStr: "a >= 1",
resultStr: "[[1 +inf]]",
},
{
exprStr: "1 <= a",
resultStr: "[[1 +inf]]",
},
{
exprStr: "a < 1",
resultStr: "[[-inf 1)]",
},
{
exprStr: "1 > a",
resultStr: "[[-inf 1)]",
},
{
exprStr: "a <= 1",
resultStr: "[[-inf 1]]",
},
{
exprStr: "1 >= a",
resultStr: "[[-inf 1]]",
},
{
exprStr: "(a)",
resultStr: "[[-inf 0) (0 +inf]]",
},
{
exprStr: "a in (1, 3, NULL, 2)",
resultStr: "[[<nil> <nil>] [1 1] [2 2] [3 3]]",
},
{
exprStr: `a IN (8,8,81,45)`,
resultStr: `[[8 8] [45 45] [81 81]]`,
},
{
exprStr: "a between 1 and 2",
resultStr: "[[1 2]]",
},
{
exprStr: "a not between 1 and 2",
resultStr: "[[-inf 1) (2 +inf]]",
},
{
exprStr: "a not between null and 0",
resultStr: "[(0 +inf]]",
},
{
exprStr: "a between 2 and 1",
resultStr: "[]",
},
{
exprStr: "a not between 2 and 1",
resultStr: "[[-inf +inf]]",
},
{
exprStr: "a IS NULL",
resultStr: "[[<nil> <nil>]]",
},
{
exprStr: "a IS NOT NULL",
resultStr: "[[-inf +inf]]",
},
{
exprStr: "a IS TRUE",
resultStr: "[[-inf 0) (0 +inf]]",
},
{
exprStr: "a IS NOT TRUE",
resultStr: "[[<nil> <nil>] [0 0]]",
},
{
exprStr: "a IS FALSE",
resultStr: "[[0 0]]",
},
{
exprStr: "a IS NOT FALSE",
resultStr: "[[<nil> 0) (0 +inf]]",
},
{
exprStr: "a LIKE 'abc%'",
resultStr: "[[abc abd)]",
},
{
exprStr: "a LIKE 'abc_'",
resultStr: "[(abc abd)]",
},
{
exprStr: "a LIKE 'abc'",
resultStr: "[[abc abc]]",
},
{
exprStr: `a LIKE "ab\_c"`,
resultStr: "[[ab_c ab_c]]",
},
{
exprStr: "a LIKE '%'",
resultStr: "[[-inf +inf]]",
},
{
exprStr: `a LIKE '\%a'`,
resultStr: `[[%a %a]]`,
},
{
exprStr: `a LIKE "\\"`,
resultStr: `[[\ \]]`,
},
{
exprStr: `a LIKE "\\\\a%"`,
resultStr: `[[\a \b)]`,
},
{
exprStr: `0.4`,
resultStr: `[]`,
},
{
exprStr: `a > NULL`,
resultStr: `[]`,
},
}

for _, ca := range cases {
sql := "select * from t where " + ca.exprStr
stmt, err := s.ParseOneStmt(sql, "", "")
c.Assert(err, IsNil, Commentf("error %v, for expr %s", err, ca.exprStr))
is, err := mockResolve(stmt)
c.Assert(err, IsNil)

builder := &planBuilder{
allocator: new(idAllocator),
ctx: mockContext(),
is: is,
}
p := builder.build(stmt)
c.Assert(err, IsNil, Commentf("error %v, for build plan, expr %s", err, ca.exprStr))
var selection *Selection
for _, child := range p.Children() {
plan, ok := child.(*Selection)
if ok {
selection = plan
break
}
}
c.Assert(selection, NotNil, Commentf("expr:%v", ca.exprStr))
result := fullRange
for _, cond := range selection.Conditions {
result = rb.intersection(result, rb.build(pushDownNot(cond, false, nil)))
}
c.Assert(rb.err, IsNil)
got := fmt.Sprintf("%v", result)
c.Assert(got, Equals, ca.resultStr, Commentf("different for expr %s", ca.exprStr))
}
}

func checkDataSourceCols(p Plan, c *C, ans map[string][]string, comment CommentInterface) {
switch p.(type) {
case *PhysicalTableScan:
Expand Down
Loading

0 comments on commit df6e1b3

Please sign in to comment.