func newSargableLike(expr expression.BinaryFunction, re *regexp.Regexp) *sargableLike { rv := &sargableLike{} rv.test = func(expr2 expression.Expression) (bool, error) { return expr.EquivalentTo(expr2) || expr.First().EquivalentTo(expr2), nil } return rv }
func newSargLike(expr expression.BinaryFunction, re *regexp.Regexp) expression.Visitor { prefix := "" if re != nil { prefix, complete := re.LiteralPrefix() if complete { eq := expression.NewEq(expr.First(), expression.NewConstant(prefix)) return newSargEq(eq.(*expression.Eq)) } } rv := &sargLike{} rv.sarg = func(expr2 expression.Expression) (Spans, error) { if expr.EquivalentTo(expr2) { return _SELF_SPANS, nil } if !expr.First().EquivalentTo(expr2) { return nil, nil } span := &Span{} span.Range.Low = expression.Expressions{expression.NewConstant(prefix)} last := len(prefix) - 1 if last >= 0 && prefix[last] < math.MaxUint8 { bytes := []byte(prefix) bytes[last]++ span.Range.High = expression.Expressions{expression.NewConstant(string(bytes))} } else { span.Range.High = _EMPTY_ARRAY } span.Range.Inclusion = datastore.LOW return Spans{span}, nil } return rv }