From 00a810940a81b335c24068a9e5831b87bfb1ddbb Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Mon, 4 May 2020 20:25:46 +0200 Subject: [PATCH] Use 'SelectNone' for all equality against null Signed-off-by: Andres Taylor --- go/vt/vtgate/planbuilder/route_option.go | 8 +++++--- .../planbuilder/testdata/filter_cases.txt | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/go/vt/vtgate/planbuilder/route_option.go b/go/vt/vtgate/planbuilder/route_option.go index e374e03ad6b..c38c163231e 100644 --- a/go/vt/vtgate/planbuilder/route_option.go +++ b/go/vt/vtgate/planbuilder/route_option.go @@ -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 @@ -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 } diff --git a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt index 8bb634c68e1..74a3c7fa9a2 100644 --- a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt @@ -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" {