Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 31, 2025
1 parent 3632c05 commit c192bc5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
7 changes: 2 additions & 5 deletions go/vt/vttablet/tabletserver/vstreamer/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,7 @@ func (plan *Plan) analyzeWhere(vschema *localVSchema, where *sqlparser.Where) er
if !ok {
return fmt.Errorf("unexpected: %v", sqlparser.String(expr))
}
// Add it to the column expressions so that it's passed down to mysqld.
if plan.whereExprsToPushDown == nil {
plan.whereExprsToPushDown = make([]sqlparser.Expr, 0)
}
// 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
Expand Down Expand Up @@ -659,7 +656,7 @@ func (plan *Plan) analyzeWhere(vschema *localVSchema, where *sqlparser.Where) er
Opcode: IsNotNull,
ColNum: colnum,
})
// Add it to the column expressions so that it's passed down to mysqld.
// Add it to the expressions that get pushed down to mysqld.
plan.whereExprsToPushDown = append(plan.whereExprsToPushDown, expr)
default:
return fmt.Errorf("unsupported constraint: %v", sqlparser.String(expr))
Expand Down
51 changes: 49 additions & 2 deletions go/vt/vttablet/tabletserver/vstreamer/planbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"
"vitess.io/vitess/go/vt/proto/topodata"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtenv"
Expand Down Expand Up @@ -451,6 +450,54 @@ func TestPlanBuilder(t *testing.T) {
VindexColumns: nil,
KeyRange: nil,
}},
whereExprsToPushDown: []sqlparser.Expr{
sqlparser.NewComparisonExpr(sqlparser.EqualOp, sqlparser.Expr(sqlparser.NewColName("id")), sqlparser.Expr(sqlparser.NewIntLiteral("1")), nil),
},
env: vtenv.NewTestEnv(),
},
}, {
inTable: t1,
inRule: &binlogdatapb.Rule{Match: "t1", Filter: "select val, id from t1 where id > 1 and id < 10"},
outPlan: &Plan{
ColExprs: []ColExpr{{
ColNum: 1,
Field: &querypb.Field{
Name: "val",
Type: sqltypes.VarBinary,
Charset: collations.CollationBinaryID,
Flags: uint32(querypb.MySqlFlag_BINARY_FLAG),
},
}, {
ColNum: 0,
Field: &querypb.Field{
Name: "id",
Type: sqltypes.Int64,
Charset: collations.CollationBinaryID,
Flags: uint32(querypb.MySqlFlag_NUM_FLAG),
},
}},
Filters: []Filter{
{
Opcode: GreaterThan,
ColNum: 0,
Value: sqltypes.NewInt64(1),
Vindex: nil,
VindexColumns: nil,
KeyRange: nil,
},
{
Opcode: LessThan,
ColNum: 0,
Value: sqltypes.NewInt64(10),
Vindex: nil,
VindexColumns: nil,
KeyRange: nil,
},
},
whereExprsToPushDown: []sqlparser.Expr{
sqlparser.NewComparisonExpr(sqlparser.GreaterThanOp, sqlparser.Expr(sqlparser.NewColName("id")), sqlparser.Expr(sqlparser.NewIntLiteral("1")), nil),
sqlparser.NewComparisonExpr(sqlparser.LessThanOp, sqlparser.Expr(sqlparser.NewColName("id")), sqlparser.Expr(sqlparser.NewIntLiteral("10")), nil),
},
env: vtenv.NewTestEnv(),
},
}, {
Expand Down Expand Up @@ -661,7 +708,7 @@ func TestPlanBuilder(t *testing.T) {
plan.Filters[ind].Vindex = nil
plan.Filters[ind].Vindex = nil
}
utils.MustMatch(t, tcase.outPlan, plan)
require.EqualValues(t, tcase.outPlan, plan)
})
}
}
Expand Down

0 comments on commit c192bc5

Please sign in to comment.