Exemple #1
0
func newSargAnd(pred *expression.And) *sargAnd {
	rv := &sargAnd{}
	rv.sarger = func(expr2 expression.Expression) (spans plan.Spans, err error) {
		if SubsetOf(pred, expr2) {
			return _SELF_SPANS, nil
		}

		var s plan.Spans
		for _, op := range pred.Operands() {
			s, err = sargFor(op, expr2, rv.MissingHigh())
			if err != nil {
				return nil, err
			}

			if len(s) == 0 {
				continue
			}

			if len(spans) == 0 {
				spans = s.Copy()
			} else {
				spans = constrainSpans(spans, s)
			}
		}

		return
	}

	return rv
}
Exemple #2
0
func constrainSpans(spans1, spans2 plan.Spans) plan.Spans {
	if len(spans2) != 1 {
		if len(spans1) == 1 {
			spans1, spans2 = spans2.Copy(), spans1
		} else {
			return spans1
		}
	}

	span2 := spans2[0]
	for _, span1 := range spans1 {
		constrainSpan(span1, span2)
	}

	return spans1
}