efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Use XOR to translate some == and != expressions

Open ranma42 opened this issue 1 year ago • 1 comments

When the parent expression is not a predicate, translate x != y to:

x ^ y

instead of

CASE
    WHEN x <> y THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END

Similarly, translate x == y to:

x ^ y ^ CAST(1 AS bit)

instead of

CASE
    WHEN x == y THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END

Contributes to #34001 for simple cases (comparison of BIT expressions).

ranma42 avatar Jun 30 '24 15:06 ranma42

This is a continuation of #34080.

Conceptually it also reduces the number of expressions that hit #34001, but in practice (because of the null rewriting) the expressions that it affects are only those that compare non-nullable BIT expressions.

This would change if there was some optimization like #34126.

ranma42 avatar Jun 30 '24 15:06 ranma42

Thanks again @ranma42 !

maumar avatar Jul 03 '24 08:07 maumar