From 70f368b1fe3f26547eff8afbb7c463485b5e2cc5 Mon Sep 17 00:00:00 2001 From: Maximilian Hoffman Date: Tue, 2 Aug 2022 15:32:15 -0700 Subject: [PATCH] fix inverted index IN filter error (#1146) * fix inverted index IN filter error * delete stale error --- enginetest/queries/queries.go | 4 ++++ sql/analyzer/indexes.go | 13 ++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/enginetest/queries/queries.go b/enginetest/queries/queries.go index 76be51312e..b5bb817511 100644 --- a/enginetest/queries/queries.go +++ b/enginetest/queries/queries.go @@ -6766,6 +6766,10 @@ var QueryTests = []QueryTest{ Query: `select * from mytable where 1 = 0 order by i asc`, Expected: []sql.Row{}, }, + { + Query: `select * from mytable where i not in (1)`, + Expected: []sql.Row{{2, "second row"}, {3, "third row"}}, + }, } var KeylessQueries = []QueryTest{ diff --git a/sql/analyzer/indexes.go b/sql/analyzer/indexes.go index d8bf148234..193f8a2109 100644 --- a/sql/analyzer/indexes.go +++ b/sql/analyzer/indexes.go @@ -15,15 +15,11 @@ package analyzer import ( - errors "gopkg.in/src-d/go-errors.v1" - "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/expression" "github.com/dolthub/go-mysql-server/sql/plan" ) -var errInvalidInRightEvaluation = errors.NewKind("expecting evaluation of IN expression right hand side to be a tuple, but it is %T") - // indexLookup contains an sql.IndexLookup and all sql.Index that are involved // in it. type indexLookup struct { @@ -449,9 +445,12 @@ func getNegatedIndexes( return nil, err } - values, ok := value.([]interface{}) - if !ok { - return nil, errInvalidInRightEvaluation.New(value) + var values []interface{} + switch v := value.(type) { + case []interface{}: + values = v + default: + values = []interface{}{v} } idxBuilder := sql.NewIndexBuilder(ctx, idx)