Esempio n. 1
0
func newSargableLike(pred expression.BinaryFunction, re *regexp.Regexp) *sargableLike {
	rv := &sargableLike{}
	rv.test = func(expr2 expression.Expression) (bool, error) {
		return SubsetOf(pred, expr2) ||
			pred.First().EquivalentTo(expr2), nil
	}

	return rv
}
Esempio n. 2
0
func newSargableBinary(pred expression.BinaryFunction) *sargableBinary {
	rv := &sargableBinary{}
	rv.test = func(expr2 expression.Expression) (bool, error) {
		return SubsetOf(pred, expr2) ||
			pred.First().EquivalentTo(expr2) ||
			pred.Second().EquivalentTo(expr2), nil
	}

	return rv
}
Esempio n. 3
0
func newSargLike(pred expression.BinaryFunction, re *regexp.Regexp) expression.Visitor {
	prefix := ""

	if re != nil {
		var complete bool
		prefix, complete = re.LiteralPrefix()
		if complete {
			eq := expression.NewEq(pred.First(), expression.NewConstant(prefix))
			return newSargEq(eq.(*expression.Eq))
		}
	}

	rv := &sargLike{}
	rv.sarger = func(expr2 expression.Expression) (plan.Spans, error) {
		if SubsetOf(pred, expr2) {
			return _SELF_SPANS, nil
		}

		if !pred.First().EquivalentTo(expr2) {
			return nil, nil
		}

		span := &plan.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 plan.Spans{span}, nil
	}

	return rv
}
Esempio n. 4
0
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))
	}

	sand := newSubsetAnd(and.(*expression.And))
	rv := &subsetLike{}
	rv.test = func(expr2 expression.Expression) (bool, error) {
		if expr.EquivalentTo(expr2) {
			return true, nil
		}

		return sand.test(expr2)
	}

	return rv
}