Beispiel #1
0
// VisitBinaryOperation swaps the right side identifier to left side if left side expression is static.
// So it can be used in index plan.
func (iev *IdentEvalVisitor) VisitBinaryOperation(binop *expression.BinaryOperation) (expression.Expression, error) {
	var err error
	binop.L, err = binop.L.Accept(iev)
	if err != nil {
		return binop, errors.Trace(err)
	}
	binop.R, err = binop.R.Accept(iev)
	if err != nil {
		return binop, errors.Trace(err)
	}

	if binop.L.IsStatic() {
		if _, ok := binop.R.(*expression.Ident); ok {
			switch binop.Op {
			case opcode.EQ:
			case opcode.NE:
			case opcode.NullEQ:
			case opcode.LT:
				binop.Op = opcode.GE
			case opcode.LE:
				binop.Op = opcode.GT
			case opcode.GE:
				binop.Op = opcode.LT
			case opcode.GT:
				binop.Op = opcode.LE
			default:
				// unsupported opcode
				return binop, nil
			}
			binop.L, binop.R = binop.R, binop.L
		}
	}
	return binop, nil
}