@@ -169,46 +169,46 @@ func (t *DoltTable) LookupForExpressions(ctx *sql.Context, exprs ...sql.Expressi
169169 dbState .SessionCache ().CacheStrictLookup (schKey , lookups )
170170 }
171171
172+ cols := schCols .GetColumns ()
172173 for _ , lookup := range lookups {
173- if lookup .Cols .Intersection (colset ).Len () == lookup .Cols .Len () {
174- // (1) assign lookup columns to range expressions in the appropriate
175- // order for the given lookup.
176- // (2) aggregate the unused expressions into the return filter.
177- rb := sql .NewEqualityIndexBuilder (lookup .Idx )
178- for _ , c2 := range lookupCols {
179- var matched bool
180- var matchIdx int
181- for i , ord := range lookup .Ordinals {
182- // the ordinals redirection accounts for index
183- // columns not in schema order
184- idx := ord - 1
185- c := schCols .GetColumns ()[idx ]
186- if strings .EqualFold (c2 .Col , c .Name ) {
187- matched = true
188- matchIdx = i
189- break
190- }
191- }
192- if matched {
193- if err := rb .AddEquality (ctx , matchIdx , c2 .Lit .Value ()); err != nil {
194- return sql.IndexLookup {}, nil , nil , false , nil
195- }
174+ // Every column must be specified in search
175+ if lookup .Cols .Intersection (colset ).Len () != lookup .Cols .Len () {
176+ continue
177+ }
178+ // (1) assign lookup columns to range expressions in the appropriate order for the given lookup.
179+ // (2) aggregate the unused expressions into the return filter.
180+ rb := sql .NewEqualityIndexBuilder (lookup .Idx )
181+ for _ , c2 := range lookupCols {
182+ matchIdx := - 1
183+ for i , ord := range lookup .Ordinals {
184+ // the ordinals redirection accounts for index
185+ // columns not in schema order
186+ idx := ord - 1
187+ c := cols [idx ]
188+ if strings .EqualFold (c2 .Col , c .Name ) {
189+ matchIdx = i
190+ break
196191 }
197- if ! matched || ! expression .PreciseComparison (c2 .Eq ) {
198- if leftoverExpr == nil {
199- leftoverExpr = c2 .Eq
200- } else {
201- leftoverExpr = expression .NewAnd (leftoverExpr , c2 .Eq )
202- }
192+ }
193+ if matchIdx != - 1 {
194+ if err = rb .AddEquality (ctx , matchIdx , c2 .Lit .Value ()); err != nil {
195+ return sql.IndexLookup {}, nil , nil , false , nil
203196 }
197+ continue
204198 }
205- ret , err := rb .Build (ctx )
206- if err != nil {
207- return sql.IndexLookup {}, nil , nil , false , err
199+ if leftoverExpr == nil {
200+ leftoverExpr = c2 .Eq
201+ } else {
202+ leftoverExpr = expression .NewAnd (leftoverExpr , c2 .Eq )
208203 }
204+ }
209205
210- return ret , lookup .Fds , leftoverExpr , true , nil
206+ var ret sql.IndexLookup
207+ ret , err = rb .Build (ctx )
208+ if err != nil {
209+ return sql.IndexLookup {}, nil , nil , false , err
211210 }
211+ return ret , lookup .Fds , leftoverExpr , true , nil
212212 }
213213
214214 return sql.IndexLookup {}, nil , nil , false , nil
0 commit comments