Skip to content

Commit

Permalink
Merge pull request #6146 from planetscale/at-equals-null
Browse files Browse the repository at this point in the history
Use 'SelectNone' for all equality against null
  • Loading branch information
systay authored May 4, 2020
2 parents ab29699 + 00a8109 commit 648e8c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions go/vt/vtgate/planbuilder/route_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ func (ro *routeOption) computePlan(pb *primitiveBuilder, filter sqlparser.Expr)
func (ro *routeOption) computeEqualPlan(pb *primitiveBuilder, comparison *sqlparser.ComparisonExpr) (opcode engine.RouteOpcode, vindex vindexes.SingleColumn, condition sqlparser.Expr) {
left := comparison.Left
right := comparison.Right

if sqlparser.IsNull(right) {
return engine.SelectNone, nil, nil
}

vindex = ro.FindVindex(pb, left)
if vindex == nil {
left, right = right, left
Expand All @@ -277,9 +282,6 @@ func (ro *routeOption) computeEqualPlan(pb *primitiveBuilder, comparison *sqlpar
return engine.SelectScatter, nil, nil
}
}
if sqlparser.IsNull(right) {
return engine.SelectNone, nil, nil
}
if !ro.exprIsValue(right) {
return engine.SelectScatter, nil, nil
}
Expand Down
18 changes: 18 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/filter_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
}
}

# Query that always return empty
"select id from user where someColumn = null"
{
"QueryType": "SELECT",
"Original": "select id from user where someColumn = null",
"Instructions": {
"OperatorType": "Route",
"Variant": "SelectNone",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select id from user where 1 != 1",
"Query": "select id from user where someColumn = null",
"Table": "user"
}
}

# Single table unique vindex route
"select id from user where user.id = 5"
{
Expand Down

0 comments on commit 648e8c2

Please sign in to comment.