Skip to content
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

Fix to #16092 - Query: Simplify case blocks in SQL tree #20966

Merged
merged 1 commit into from
May 19, 2020
Merged

Conversation

maumar
Copy link
Contributor

@maumar maumar commented May 15, 2020

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

@maumar maumar requested review from smitpatel and roji May 15, 2020 07:29
Copy link
Member

@smitpatel smitpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this is part of null semantics? What is specific nullability information you need to apply this optimization?

@maumar
Copy link
Contributor Author

maumar commented May 15, 2020

@smitpatel it's not rly part of null semantics. it needs to happen before null semantics. I can put it in a separate visitor, as mentioned in a comment

@smitpatel
Copy link
Member

Does it need to know parameter values?

@maumar
Copy link
Contributor Author

maumar commented May 15, 2020

updated

@maumar maumar force-pushed the fix16092 branch 2 times, most recently from c643051 to b134660 Compare May 15, 2020 22:24
@maumar
Copy link
Contributor Author

maumar commented May 15, 2020

updated

@maumar
Copy link
Contributor Author

maumar commented May 19, 2020

ping

var matchingCaseBlock = caseComponent.WhenClauses.FirstOrDefault(wc => sqlConstantComponent.Equals(wc.Result));
if (matchingCaseBlock != null)
{
return matchingCaseBlock.Test;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly visit recursively. Also write a regression test for it.

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
@maumar
Copy link
Contributor Author

maumar commented May 19, 2020

@smitpatel updated

@maumar maumar merged commit f7d5168 into master May 19, 2020
@maumar maumar deleted the fix16092 branch May 19, 2020 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query: Simplify case blocks in SQL tree
2 participants