Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with side case in relation to text type. #7201

Merged
merged 12 commits into from
Dec 15, 2022
2 changes: 1 addition & 1 deletion pkg/sql/plan/base_binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/plan/function/operator/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/plan/function/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions pkg/sql/plan/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions test/distributed/cases/operator/like_operator.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/distributed/cases/operator/like_operator.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 ".";