-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL Server: Use XOR to translate more == and != expressions #34168
Conversation
When the parent expression is not a predicate, translate `x != y` to: ```sql CAST(x ^ y AS BIT) ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql CAST(x ^ y AS BIT) ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001.
This extends #34124 to all integer types. |
src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
Thanks again! |
Any reason not to use the simpler bitwise NOT operator here, i.e. |
You're right, it should be used both for efcore/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs Lines 370 to 375 in 349f4bd
efcore/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs Lines 413 to 418 in 349f4bd
It requires some changes that are not 100% trivial (currently "not" on boolean is always translated as |
Just to be sure, all this is for SQL Server only right? Do you want to open another issue to track using bitwise not? |
At least in the context of the efcore repo, yes (and in general I guess there are few providers which have a distinct notion of boolean-in-predicates vs boolean-in-values, but maybe I am wrong). Filed #34213. |
When the parent expression is not a predicate, translate
x != y
to:instead of
Similarly, translate
x == y
to:instead of
Contributes to #34001.