@@ -359,20 +359,32 @@ func (c *indexConstraintCalc) intersectSpanSet(a *LogicalSpan, spanSet LogicalSp
359359 return res
360360}
361361
362- // makeSpansForExpr creates spans for index columns starting at <depth>
363- // from the given expression.
364- func (c * indexConstraintCalc ) makeSpansForExpr (depth int , e * expr ) (LogicalSpans , bool ) {
365- // Check if the operator is supported.
366- switch e .op {
367- case eqOp , ltOp , gtOp , leOp , geOp , neOp :
368- // We support comparisons when the left-hand side is an indexed var for the
369- // current column and the right-hand side is a constant.
370- if ! isIndexedVar (e .children [0 ], depth ) || e .children [1 ].op != constOp {
371- return nil , false
362+ // makeSpansForSingleColumn creates spans for a single index column from a
363+ // simple comparison expression. The arguments are the operator and right
364+ // operand.
365+ func (c * indexConstraintCalc ) makeSpansForSingleColumn (
366+ op operator , val * expr ,
367+ ) (LogicalSpans , bool ) {
368+ if op == inOp && isTupleOfConstants (val ) {
369+ // We assume that the values of the tuple are already ordered and distinct.
370+ spans := make (LogicalSpans , len (val .children ))
371+ for i , v := range val .children {
372+ datum := v .private .(tree.Datum )
373+ spans [i ].Start = LogicalKey {Vals : tree.Datums {datum }, Inclusive : true }
374+ spans [i ].End = spans [i ].Start
372375 }
373- datum := e .children [1 ].private .(tree.Datum )
376+ return spans , true
377+ }
378+ // The rest of the supported expressions must have a constant scalar on the
379+ // right-hand side.
380+ if val .op != constOp {
381+ return nil , false
382+ }
383+ datum := val .private .(tree.Datum )
384+ switch op {
385+ case eqOp , ltOp , gtOp , leOp , geOp :
374386 sp := MakeFullSpan ()
375- switch e . op {
387+ switch op {
376388 case eqOp :
377389 sp .Start = LogicalKey {Vals : tree.Datums {datum }, Inclusive : true }
378390 sp .End = LogicalKey {Vals : tree.Datums {datum }, Inclusive : true }
@@ -386,19 +398,31 @@ func (c *indexConstraintCalc) makeSpansForExpr(depth int, e *expr) (LogicalSpans
386398 sp .End = LogicalKey {Vals : tree.Datums {datum }, Inclusive : true }
387399 case geOp :
388400 sp .Start = LogicalKey {Vals : tree.Datums {datum }, Inclusive : true }
389- case neOp :
390- sp .End = LogicalKey {Vals : tree.Datums {datum }, Inclusive : false }
391- sp2 := MakeFullSpan ()
392- sp2 .Start = LogicalKey {Vals : tree.Datums {datum }, Inclusive : false }
393- return LogicalSpans {sp , sp2 }, true
394401 }
395402 return LogicalSpans {sp }, true
396403
404+ case neOp :
405+ spans := LogicalSpans {MakeFullSpan (), MakeFullSpan ()}
406+ spans [0 ].End = LogicalKey {Vals : tree.Datums {datum }, Inclusive : false }
407+ spans [1 ].Start = LogicalKey {Vals : tree.Datums {datum }, Inclusive : false }
408+ return spans , true
409+
397410 default :
398411 return nil , false
399412 }
400413}
401414
415+ // makeSpansForExpr creates spans for index columns starting at <depth>
416+ // from the given expression.
417+ func (c * indexConstraintCalc ) makeSpansForExpr (depth int , e * expr ) (LogicalSpans , bool ) {
418+ // Check for an operation where the left-hand side is an
419+ // indexed var for this column.
420+ if isIndexedVar (e .children [0 ], depth ) {
421+ return c .makeSpansForSingleColumn (e .op , e .children [1 ])
422+ }
423+ return nil , false
424+ }
425+
402426// calcDepth calculates constraints for the sequence of index columns starting
403427// at <depth> (i.e. the <depth>-th index column, <depth+1>-th index column, etc.).
404428//
0 commit comments