Skip to content

Commit

Permalink
planner: reject invalid conversion from like to =
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 committed Jul 23, 2019
1 parent c3d195c commit ce119fe
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d/go.mo
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
Expand Down
2 changes: 1 addition & 1 deletion planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ func (er *expressionRewriter) patternLikeToExpression(v *ast.PatternLikeExpr) {
}
if !isNull {
patValue, patTypes := stringutil.CompilePattern(patString, v.Escape)
if stringutil.IsExactMatch(patTypes) && er.ctxStack[l-2].GetType().EvalType().IsStringKind() {
if stringutil.IsExactMatch(patTypes) && er.ctxStack[l-2].GetType().EvalType() == types.ETString {
op := ast.EQ
if v.Not {
op = ast.NE
Expand Down
1 change: 1 addition & 0 deletions planner/core/expression_rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (s *testExpressionRewriterSuite) TestPatternLikeToExpression(c *C) {
tk.MustQuery("select 0 like 'a string';").Check(testkit.Rows("0"))
tk.MustQuery("select 0.0 like 'a string';").Check(testkit.Rows("0"))
tk.MustQuery("select 0 like '0.00';").Check(testkit.Rows("0"))
tk.MustQuery("select cast(\"2011-5-3\" as datetime) like \"2011-05-03\";").Check(testkit.Rows("0"))
tk.MustQuery("select 1 like '1';").Check(testkit.Rows("1"))
tk.MustQuery("select 0 like '0';").Check(testkit.Rows("1"))
tk.MustQuery("select 0.00 like '0.00';").Check(testkit.Rows("1"))
Expand Down
5 changes: 0 additions & 5 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,11 +1170,6 @@ func (s *testPlanSuite) TestRefine(c *C) {
sql: `select a from t where c_str like 123`,
best: "IndexReader(Index(t.c_d_e_str)[[\"123\",\"123\"]])->Projection",
},
// c is type int which will be added cast to specified type when building function signature, no index can be used.
{
sql: `select a from t where c like '1'`,
best: "TableReader(Table(t))->Sel([like(cast(test.t.c), 1, 92)])->Projection",
},
{
sql: `select a from t where c = 1.9 and d > 3`,
best: "Dual",
Expand Down

0 comments on commit ce119fe

Please sign in to comment.