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

fixes bugs around expression precedence and LIKE #16934

Merged
merged 15 commits into from
Oct 14, 2024
Merged
Prev Previous commit
Next Next commit
bugfix: don't trust SQLTypes
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Oct 11, 2024
commit ab3d00002cb058d6d1c9fd932a0f44cc47b9ebf7
15 changes: 13 additions & 2 deletions go/vt/vtgate/evalengine/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/olekukonko/tablewriter"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -129,10 +131,19 @@ func TestCompilerReference(t *testing.T) {
return
}

expected, evalErr := env.EvaluateAST(converted)
var expected evalengine.EvalResult
var evalErr error
assert.NotPanics(t, func() {
expected, evalErr = env.EvaluateAST(converted)
})
total++

res, vmErr := env.Evaluate(converted)
var res evalengine.EvalResult
var vmErr error
assert.NotPanics(t, func() {
res, vmErr = env.Evaluate(converted)
})

if vmErr != nil {
switch {
case evalErr == nil:
Expand Down
15 changes: 9 additions & 6 deletions go/vt/vtgate/evalengine/expr_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,17 @@ func (l *LikeExpr) eval(env *ExpressionEnv) (eval, error) {
return nil, err
}

lbytes, lok := left.(*evalBytes)
rbytes, rok := right.(*evalBytes)

var matched bool
switch {
case typeIsTextual(left.SQLType()) && typeIsTextual(right.SQLType()):
matched = l.matchWildcard(left.(*evalBytes).bytes, right.(*evalBytes).bytes, col.Collation)
case typeIsTextual(right.SQLType()):
matched = l.matchWildcard(left.ToRawBytes(), right.(*evalBytes).bytes, col.Collation)
case typeIsTextual(left.SQLType()):
matched = l.matchWildcard(left.(*evalBytes).bytes, right.ToRawBytes(), col.Collation)
case lok && rok:
matched = l.matchWildcard(lbytes.bytes, rbytes.bytes, col.Collation)
case rok:
matched = l.matchWildcard(left.ToRawBytes(), rbytes.bytes, col.Collation)
case lok:
matched = l.matchWildcard(lbytes.bytes, right.ToRawBytes(), col.Collation)
default:
matched = l.matchWildcard(left.ToRawBytes(), right.ToRawBytes(), collations.CollationBinaryID)
}
Expand Down
Loading