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 #20003 - Convert multiple equality/in-equality on same column joined by Or/Else into SQL IN expression #21477

Merged
merged 1 commit into from
Jul 8, 2020

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Jul 1, 2020

Various optimizations to queries with IN:

  • a == X || a == Y -> a IN (X, Y)
  • a != X && a != Y -> a NOT IN (X, Y)
  • a IN (X) -> a == X
  • a IN (X, Y) || a IN (Z, W) -> a IN (X, Y, Z, W)
  • a IN (X, Y, Z) && a IN (Y, Z, W) -> a IN (Y, Z)

Fixes #20003

@maumar maumar requested review from smitpatel and roji July 1, 2020 04:24
caseComponent);
}

var left = (SqlExpression)Visit(sqlBinaryExpression.Left);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the part that was added

@maumar maumar force-pushed the fix20003 branch 2 times, most recently from 138277b to cc8e0b5 Compare July 1, 2020 09:02
List<object> result;
if (collection is List<object> list)
{
result = list;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be ok to do this, but could always create new instance, just to be safe - thoughts?

…joined by Or/Else into SQL IN expression

Various optimizations to queries with IN:

- a == X || a == Y -> a IN (X, Y)
- a != X && a != Y -> a NOT IN (X, Y)
- a IN (X) -> a == X
- a IN (X, Y) || a IN (Z, W) -> a IN (X, Y, Z, W)
- a IN (X, Y, Z) && a IN (Y, Z, W) -> a IN (Y, Z)

Fixes #20003
@maumar
Copy link
Contributor Author

maumar commented Jul 8, 2020

@smitpatel updated

@maumar maumar merged commit 585a09d into master Jul 8, 2020
@maumar maumar deleted the fix20003 branch July 8, 2020 20:56
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.

Convert multiple equality/in-equality on same column joined by Or/Else into SQL IN expression
2 participants