-
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
Query: Simplify case blocks in SQL tree #16092
Comments
Post translation optimization. |
This should not change translation pipeline. It must be done in post translation SQL optimization. |
Out of curiosity, do we ever reduce CASE to COALESCE, ISNULL/IFNULL, or NULLIF? |
We could but we never did. |
Note: simplification of
Also note that the above was done in a preprocessing visitor, but @smitpatel is saying it should be done post-translation. Let's wait for @smitpatel and decide what to do. |
Post-translation. The code added in preprocessing visitor should be removed. |
Can you explain why it's important this happens in postprocessing? Also, these special VB method calls will cause failure during translation because we don't know them.. |
Because translation pipeline should be oblivious to it. Hence the simplification of case block must happen in post processing. This issue is not about VB method calls. VB method calls should be converted to their equivalent representation of C# in pretranslation phase. Though
Should get converted to |
Am trying to understand why, according to what principles... Specifically, the rewriting of |
Yes, for the providers which requires usage of function to do string comparison. It is same as why we cannot rewrite in preprocessor string.compare() > 0 to |
But those providers must take care of string equality without function in any case, since that's the expression the compiler generates for C# On the other hand, AFAIK an expression with NodeType=GreaterThan and string operands is never produced in C# (or even in VB.NET), which is why it makes sense for us not to support it... |
Those providers will take care of it in translation. Why convert to one thing to another which in turn get converted back to main thing again. We already have this issue which required to be fixed either way due to
Incorrect conclusion. string.Compare is a way to write a > b since you cannot write directly. We need to support it. |
My main point here is that the simplification from Re greater/less than, it seems odd to internally transform Maybe a quick call would help clear this up. |
There are many constructs which are not produced in C# but still possible in SQL, we internally transform it because SQL supports it. And we don't do it because it's not possible/universal. Repeat for each provider because each provider supports different things. |
Regardless of the greater-than/less-than question:
The fact that |
Discussed and accepting @smitpatel's argument that we should preserve the LINQ expression tree as much as possible rather than apply optimizing/normalizing transformations in preprocessing. |
@roji Don't want to poke a sleeping lion, but here goes. Surely normalization of VB generated expression trees to what C# would have generated for the same intention is good to have in the core stack, not for each providers? |
That was my original motivation here, I'll let @smitpatel answer (you two can discuss offline too, I've made my peace with either possibility 😄). |
It is in core stack not in provider code. |
To clarify, there are two separate things here... For s1 == s2, VB produces
|
@maumar - check OP to see if this is fixed. |
Adding optimization to during post processing (null semantics) Trying to match CASE block that corresponds to CompareTo translation. If that case block is compared to 0, 1 or -1 we can simplify it to simple comparison. Also added generic CASE block optimization, when constant is compared to CASE block, and that constant is one of the results Fixes #16092
Adding optimization to during post processing (null semantics) Trying to match CASE block that corresponds to CompareTo translation. If that case block is compared to 0, 1 or -1 we can simplify it to simple comparison. Also added generic CASE block optimization, when constant is compared to CASE block, and that constant is one of the results Fixes #16092
Adding optimization to during post processing Trying to match CASE block that corresponds to CompareTo translation. If that case block is compared to 0, 1 or -1 we can simplify it to simple comparison. Also added generic CASE block optimization, when constant is compared to CASE block, and that constant is one of the results Fixes #16092
Adding optimization to during post processing Trying to match CASE block that corresponds to CompareTo translation. If that case block is compared to 0, 1 or -1 we can simplify it to simple comparison. Also added generic CASE block optimization, when constant is compared to CASE block, and that constant is one of the results Fixes #16092
Adding optimization to during post processing Trying to match CASE block that corresponds to CompareTo translation. If that case block is compared to 0, 1 or -1 we can simplify it to simple comparison. Also added generic CASE block optimization, when constant is compared to CASE block, and that constant is one of the results Fixes #16092
Currently we translate CompareTo naively, using case statements with 3 options, however those can be significantly optimized for cases where CompareTo itself is compared to 1, 0 -1
foo.CompareTo(bar) == 0 -> foo == bar
example test:
Double_order_by_on_string_compare
example current sql:
example improved sql:
The text was updated successfully, but these errors were encountered: