Skip to content

Commit

Permalink
Push down everything but in_keyrange
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Jan 31, 2025
1 parent 1b597ec commit 2eb85e4
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions go/vt/vttablet/tabletserver/vstreamer/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Plan struct {
// Predicates in the Filter query that we can push down to
// MySQL to reduce the returned rows we need to filter.
// This will contain any valid expressions in the Filter's
// WHERE clause with the exception of the in_keyspace()
// WHERE clause with the exception of the in_keyrange()
// function which is a filter that must be applied by the
// vstreamer (it's not a valid MySQL function).
whereExprsToPushDown []sqlparser.Expr
Expand Down Expand Up @@ -613,9 +613,13 @@ func (plan *Plan) analyzeWhere(vschema *localVSchema, where *sqlparser.Where) er
// Add it to the expressions that get pushed down to mysqld.
log.Errorf("DEBUG: adding to list of pushdown expressions: %v", sqlparser.String(expr))
plan.whereExprsToPushDown = append(plan.whereExprsToPushDown, expr)
// StrVal is varbinary, we do not support varchar since we would have to implement all collation types
if val.Type != sqlparser.IntVal && val.Type != sqlparser.StrVal {
return fmt.Errorf("unexpected: %v", sqlparser.String(expr))
// StrVal is varbinary, we do not support varchar filtering in
// vstreamer since we would have to do so using the correct
// collation. So we ONLY push it down to mysqld.
// TODO: now that we have MySQL compatible collation support
// we could add this support to vstreamer as well.
continue
}
pv, err := evalengine.Translate(val, &evalengine.Config{
Collation: plan.env.CollationEnv().DefaultConnectionCharset(),
Expand All @@ -635,11 +639,14 @@ func (plan *Plan) analyzeWhere(vschema *localVSchema, where *sqlparser.Where) er
Value: resolved.Value(plan.env.CollationEnv().DefaultConnectionCharset()),
})
case *sqlparser.FuncExpr:
if !expr.Name.EqualString("in_keyrange") {
return fmt.Errorf("unsupported constraint: %v", sqlparser.String(expr))
}
if err := plan.analyzeInKeyRange(vschema, expr.Exprs); err != nil {
return err
if expr.Name.EqualString("in_keyrange") {
if err := plan.analyzeInKeyRange(vschema, expr.Exprs); err != nil {
return err
}
} else {
log.Errorf("DEBUG: adding to list of pushdown expressions: %v", sqlparser.String(expr))
// Add it to the expressions that get pushed down to mysqld.
plan.whereExprsToPushDown = append(plan.whereExprsToPushDown, expr)
}
case *sqlparser.IsExpr: // Needed for CreateLookupVindex with ignore_nulls
if expr.Right != sqlparser.IsNotNullOp {
Expand All @@ -660,6 +667,7 @@ func (plan *Plan) analyzeWhere(vschema *localVSchema, where *sqlparser.Where) er
Opcode: IsNotNull,
ColNum: colnum,
})
log.Errorf("DEBUG: adding to list of pushdown expressions: %v", sqlparser.String(expr))
// Add it to the expressions that get pushed down to mysqld.
plan.whereExprsToPushDown = append(plan.whereExprsToPushDown, expr)
default:
Expand Down

0 comments on commit 2eb85e4

Please sign in to comment.