func newSargOr(pred *expression.Or) *sargOr { rv := &sargOr{} rv.sarger = func(expr2 expression.Expression) (plan.Spans, error) { if SubsetOf(pred, expr2) { return _SELF_SPANS, nil } spans := make(plan.Spans, 0, len(pred.Operands())) for _, child := range pred.Operands() { cspans, err := sargFor(child, expr2, rv.MissingHigh()) if err != nil { return nil, err } if len(cspans) == 0 { return nil, nil } if cspans[0] == _FULL_SPANS[0] || len(spans)+len(cspans) > 16 { return _FULL_SPANS, nil } spans = append(spans, cspans...) } return spans, nil } return rv }
/* Apply constant folding. Remove any constant terms. */ func (this *DNF) VisitOr(expr *expression.Or) (interface{}, error) { err := expr.MapChildren(this) if err != nil { return nil, err } // Constant folding var terms expression.Expressions for _, term := range expr.Operands() { val := term.Value() if val == nil { if terms == nil { terms = make(expression.Expressions, 0, len(expr.Operands())) } terms = append(terms, term) continue } if val.Truth() { return expression.TRUE_EXPR, nil } } if len(terms) == 0 { return expression.FALSE_EXPR, nil } if len(terms) < len(expr.Operands()) { expr = expression.NewOr(terms...) } return expr, nil }
func newSubsetOr(expr *expression.Or) *subsetOr { rv := &subsetOr{} rv.test = func(expr2 expression.Expression) (bool, error) { for _, child := range expr.Operands() { if !SubsetOf(child, expr2) { return false, nil } } return true, nil } return rv }
func newSargableOr(pred *expression.Or) *sargableOr { rv := &sargableOr{} rv.test = func(expr2 expression.Expression) (bool, error) { exprs := expression.Expressions{expr2} for _, child := range pred.Operands() { if SargableFor(child, exprs) == 0 { return false, nil } } return true, nil } return rv }
func (this *JSConverter) VisitOr(expr *expression.Or) (interface{}, error) { var buf bytes.Buffer buf.WriteString("(") for i, op := range expr.Operands() { if i > 0 { buf.WriteString(" || ") } buf.WriteString(this.Visit(op)) } buf.WriteString(")") return buf.String(), nil }