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 newSargableBinary(expr expression.BinaryFunction) *sargableBinary { rv := &sargableBinary{} rv.test = func(expr2 expression.Expression) (bool, error) { return expr.First().EquivalentTo(expr2) || expr.Second().EquivalentTo(expr2), nil } return rv }
func newSubsetLike(expr expression.BinaryFunction, re *regexp.Regexp) expression.Visitor { if re == nil { // Pattern is not a constant return newSubsetDefault(expr) } prefix, complete := re.LiteralPrefix() if complete { eq := expression.NewEq(expr.First(), expression.NewConstant(prefix)) return newSubsetEq(eq.(*expression.Eq)) } if prefix == "" { return newSubsetDefault(expr) } var and expression.Expression le := expression.NewLE(expression.NewConstant(prefix), expr.First()) last := len(prefix) - 1 if prefix[last] < math.MaxUint8 { bytes := []byte(prefix) bytes[last]++ and = expression.NewAnd(le, expression.NewLT( expr.First(), expression.NewConstant(string(bytes)))) } else { and = expression.NewAnd(le, expression.NewLT( expr.First(), expression.EMPTY_ARRAY_EXPR)) } return newSubsetAnd(and.(*expression.And)) }
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 }