diff --git a/pkg/sql/plan/base_binder.go b/pkg/sql/plan/base_binder.go index 520c2520e961..42c0cd6234e1 100644 --- a/pkg/sql/plan/base_binder.go +++ b/pkg/sql/plan/base_binder.go @@ -963,7 +963,7 @@ func bindFuncExprImplByPlanExpr(name string, args []*Expr) (*plan.Expr, error) { // rewrite some cast rule: expr: int32Col > 10, // old rule: cast(int32Col as int64) >10 , new rule: int32Col > (cast 10 as int32) switch name { - case "=", "<", "<=", ">", ">=", "<>": + case "=", "<", "<=", ">", ">=", "<>", "like": // if constant's type higher than column's type // and constant's value in range of column's type, then no cast was needed switch leftExpr := args[0].Expr.(type) { diff --git a/pkg/sql/plan/function/operator/compare.go b/pkg/sql/plan/function/operator/compare.go index e8779a058302..57ce8ec64675 100644 --- a/pkg/sql/plan/function/operator/compare.go +++ b/pkg/sql/plan/function/operator/compare.go @@ -198,7 +198,7 @@ func CompareString(vs []*vector.Vector, fn compStringFn, proc *process.Process) length := vector.Length(v2) vec := allocateBoolVector(length, proc) veccol := vec.Col.([]bool) - if v2.Typ.Width <= types.VarlenaInlineSize { + if v2.GetArea() == nil { for i := range veccol { veccol[i] = fn(col1[0], (&col2[i]).ByteSlice(), v1.Typ.Width, v2.Typ.Width) } @@ -217,7 +217,7 @@ func CompareString(vs []*vector.Vector, fn compStringFn, proc *process.Process) length := vector.Length(v1) vec := allocateBoolVector(length, proc) veccol := vec.Col.([]bool) - if v1.Typ.Width <= types.VarlenaInlineSize { + if v1.GetArea() == nil { for i := range veccol { veccol[i] = fn((&col1[i]).ByteSlice(), col2[0], v1.Typ.Width, v2.Typ.Width) } @@ -236,15 +236,15 @@ func CompareString(vs []*vector.Vector, fn compStringFn, proc *process.Process) length := vector.Length(v1) vec := allocateBoolVector(length, proc) veccol := vec.Col.([]bool) - if v1.Typ.Width <= types.VarlenaInlineSize && v2.Typ.Width <= types.VarlenaInlineSize { + if v1.GetArea() == nil && v2.GetArea() == nil { for i := range veccol { veccol[i] = fn((&col1[i]).ByteSlice(), (&col2[i]).ByteSlice(), v1.Typ.Width, v2.Typ.Width) } - } else if v1.Typ.Width <= types.VarlenaInlineSize { + } else if v1.GetArea() == nil { for i := range veccol { veccol[i] = fn((&col1[i]).ByteSlice(), (&col2[i]).GetByteSlice(area2), v1.Typ.Width, v2.Typ.Width) } - } else if v2.Typ.Width <= types.VarlenaInlineSize { + } else if v2.GetArea() == nil { for i := range veccol { veccol[i] = fn((&col1[i]).GetByteSlice(area1), (&col2[i]).ByteSlice(), v1.Typ.Width, v2.Typ.Width) } diff --git a/pkg/sql/plan/function/operators.go b/pkg/sql/plan/function/operators.go index 716107323ba6..116a80685e1e 100644 --- a/pkg/sql/plan/function/operators.go +++ b/pkg/sql/plan/function/operators.go @@ -1869,8 +1869,8 @@ var operators = map[int]Functions{ { Index: 2, Args: []types.T{ - types.T_char, - types.T_char, + types.T_text, + types.T_text, }, ReturnTyp: types.T_bool, Fn: operator.Like, diff --git a/pkg/sql/plan/utils.go b/pkg/sql/plan/utils.go index b484f64ee5c8..499c80a32828 100644 --- a/pkg/sql/plan/utils.go +++ b/pkg/sql/plan/utils.go @@ -15,9 +15,10 @@ package plan import ( - "github.com/matrixorigin/matrixone/pkg/vm/process" "math" + "github.com/matrixorigin/matrixone/pkg/vm/process" + "github.com/matrixorigin/matrixone/pkg/common/moerr" "github.com/matrixorigin/matrixone/pkg/container/batch" "github.com/matrixorigin/matrixone/pkg/container/nulls" @@ -1109,12 +1110,14 @@ func checkNoNeedCast(constT, columnT types.Type, constExpr *plan.Expr_C) bool { switch constT.Oid { case types.T_char, types.T_varchar, types.T_text: switch columnT.Oid { - case types.T_char, types.T_varchar, types.T_text: + case types.T_char, types.T_varchar: if constT.Width <= columnT.Width { return true } else { return false } + case types.T_text: + return true default: return false } diff --git a/test/distributed/cases/operator/like_operator.result b/test/distributed/cases/operator/like_operator.result index adbb14bdd714..955866d0ca25 100644 --- a/test/distributed/cases/operator/like_operator.result +++ b/test/distributed/cases/operator/like_operator.result @@ -392,3 +392,9 @@ insert into t1 values(121, 121, 121, 121); select * from t1 where (a like '%2%' and b like '%2%' and c like '%2%' and d like '%2%'); a b c d 121 121 121 121 +drop table t1; + +create table t1(a text); +insert into t1 values(rpad('1',50000,'1') + rpad('1',50000,'1')); +select * from t1 where a like "."; +a \ No newline at end of file diff --git a/test/distributed/cases/operator/like_operator.sql b/test/distributed/cases/operator/like_operator.sql index 8c40a7cfb14e..ac39c25fc6cb 100644 --- a/test/distributed/cases/operator/like_operator.sql +++ b/test/distributed/cases/operator/like_operator.sql @@ -209,3 +209,8 @@ drop table t1; create table t1(a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned); insert into t1 values(121, 121, 121, 121); select * from t1 where (a like '%2%' and b like '%2%' and c like '%2%' and d like '%2%'); + +drop table t1; +create table t1(a text); +insert into t1 values(rpad('1',50000,'1') + rpad('1',50000,'1')); +select * from t1 where a like "."; \ No newline at end of file