Skip to content

Commit

Permalink
fix cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 committed Apr 22, 2020
1 parent 5b3fcb7 commit d0abe3e
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 1 deletion.
12 changes: 12 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6102,3 +6102,15 @@ func (s *testIntegrationSuite) TestIssue15992(c *C) {
tk.MustQuery("SELECT t0.c0 FROM t0 UNION ALL SELECT 0 FROM t0;").Check(testkit.Rows())
tk.MustExec("drop table t0;")
}

func (s *testIntegrationSuite) TestIssue16505(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("CREATE TABLE t(c varchar(100), index idx(c(100)));")
tk.MustExec("INSERT INTO t VALUES (NULL),('1'),('0'),(''),('aaabbb'),('0abc'),('123e456'),('0.0001deadsfeww');")
tk.MustQuery("select * from t where c;").Sort().Check(testkit.Rows("0.0001deadsfeww", "1", "123e456"))
tk.MustQuery("select /*+ USE_INDEX(t, idx) */ * from t where c;").Sort().Check(testkit.Rows("0.0001deadsfeww", "1", "123e456"))
tk.MustQuery("select /*+ IGNORE_INDEX(t, idx) */* from t where c;").Sort().Check(testkit.Rows("0.0001deadsfeww", "1", "123e456"))
tk.MustExec("drop table t;")
}
13 changes: 12 additions & 1 deletion util/ranger/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (c *conditionChecker) check(condition expression.Expression) bool {
case *expression.ScalarFunction:
return c.checkScalarFunction(x)
case *expression.Column:
s, _ := condition.(*expression.Column)
if s.RetType.EvalType() == types.ETString {
return false
}
return c.checkColumn(x)
case *expression.Constant:
return true
Expand Down Expand Up @@ -63,7 +67,14 @@ func (c *conditionChecker) checkScalarFunction(scalar *expression.ScalarFunction
return scalar.FuncName.L != ast.NE || c.length == types.UnspecifiedLength
}
}
case ast.IsNull, ast.IsTruth, ast.IsFalsity:
case ast.IsNull:
return c.checkColumn(scalar.GetArgs()[0])
case ast.IsTruth, ast.IsFalsity:
if s, ok := scalar.GetArgs()[0].(*expression.Column); ok {
if s.RetType.EvalType() == types.ETString {
return false
}
}
return c.checkColumn(scalar.GetArgs()[0])
case ast.UnaryNot:
// TODO: support "not like" convert to access conditions.
Expand Down
31 changes: 31 additions & 0 deletions util/ranger/ranger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,3 +1161,34 @@ func (s *testRangerSuite) TestCompIndexInExprCorrCol(c *C) {
testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...))
}
}

func (s *testRangerSuite) TestIndexStringIsTrueRange(c *C) {
defer testleak.AfterTest(c)()
dom, store, err := newDomainStoreWithBootstrap(c)
defer func() {
dom.Close()
store.Close()
}()
c.Assert(err, IsNil)
testKit := testkit.NewTestKit(c, store)
testKit.MustExec("use test")
testKit.MustExec("drop table if exists t0")
testKit.MustExec("CREATE TABLE t0(c0 TEXT(10));")
testKit.MustExec("INSERT INTO t0(c0) VALUES (1);")
testKit.MustExec("CREATE INDEX i0 ON t0(c0(10));")
testKit.MustExec("analyze table t0;")

var input []string
var output []struct {
SQL string
Result []string
}
s.testData.GetTestCases(c, &input, &output)
for i, tt := range input {
s.testData.OnRecord(func() {
output[i].SQL = tt
output[i].Result = s.testData.ConvertRowsToStrings(testKit.MustQuery(tt).Rows())
})
testKit.MustQuery(tt).Check(testkit.Rows(output[i].Result...))
}
}
12 changes: 12 additions & 0 deletions util/ranger/testdata/ranger_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@
"explain select t.e in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c in (1, 2) and s.d = t.a and s.a = t1.a) from t",
"select t.e in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c in (1, 2) and s.d = t.a and s.a = t1.a) from t"
]
},
{
"name": "TestIndexStringIsTrueRange",
"cases": [
"explain select * from t0 where c0",
"explain select * from t0 where c0 and c0 > '123'",
"explain select * from t0 where c0 and c0 <> '123'",
"explain select * from t0 where c0 is true",
"explain select * from t0 where c0 is false",
"explain select * from t0 where c0 and c0 in ('123','456','789')",
"explain SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0;"
]
}
]
61 changes: 61 additions & 0 deletions util/ranger/testdata/ranger_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,66 @@
]
}
]
},
{
"Name": "TestIndexStringIsTrueRange",
"Cases": [
{
"SQL": "explain select * from t0 where c0",
"Result": [
"TableReader_7 0.80 root data:Selection_6",
"└─Selection_6 0.80 cop[tikv] test.t0.c0",
" └─TableFullScan_5 1.00 cop[tikv] table:t0 keep order:false"
]
},
{
"SQL": "explain select * from t0 where c0 and c0 > '123'",
"Result": [
"IndexReader_7 1.00 root index:Selection_6",
"└─Selection_6 1.00 cop[tikv] test.t0.c0",
" └─IndexRangeScan_5 1.00 cop[tikv] table:t0, index:i0(c0) range:(\"123\",+inf], keep order:false"
]
},
{
"SQL": "explain select * from t0 where c0 and c0 <> '123'",
"Result": [
"IndexReader_7 1.00 root index:Selection_6",
"└─Selection_6 1.00 cop[tikv] test.t0.c0",
" └─IndexRangeScan_5 1.00 cop[tikv] table:t0, index:i0(c0) range:[-inf,\"123\"), (\"123\",+inf], keep order:false"
]
},
{
"SQL": "explain select * from t0 where c0 is true",
"Result": [
"TableReader_7 0.80 root data:Selection_6",
"└─Selection_6 0.80 cop[tikv] istrue(cast(test.t0.c0))",
" └─TableFullScan_5 1.00 cop[tikv] table:t0 keep order:false"
]
},
{
"SQL": "explain select * from t0 where c0 is false",
"Result": [
"TableReader_7 0.80 root data:Selection_6",
"└─Selection_6 0.80 cop[tikv] isfalse(cast(test.t0.c0))",
" └─TableFullScan_5 1.00 cop[tikv] table:t0 keep order:false"
]
},
{
"SQL": "explain select * from t0 where c0 and c0 in ('123','456','789')",
"Result": [
"IndexReader_7 1.00 root index:Selection_6",
"└─Selection_6 1.00 cop[tikv] test.t0.c0",
" └─IndexRangeScan_5 1.00 cop[tikv] table:t0, index:i0(c0) range:[\"123\",\"123\"], [\"456\",\"456\"], [\"789\",\"789\"], keep order:false"
]
},
{
"SQL": "explain SELECT * FROM t0 WHERE ('a' != t0.c0) AND t0.c0;",
"Result": [
"IndexReader_7 1.00 root index:Selection_6",
"└─Selection_6 1.00 cop[tikv] test.t0.c0",
" └─IndexRangeScan_5 1.00 cop[tikv] table:t0, index:i0(c0) range:[-inf,\"a\"), (\"a\",+inf], keep order:false"
]
}
]
}
]

0 comments on commit d0abe3e

Please sign in to comment.