-
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: Apply CompositePredicateExpressionVisitor to join predicates #9395
Comments
Also add more optimizations, e.g. ( |
…in predicates Some optimizations that are applied to predicates can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the comparison, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
…in predicates Some optimizations that are applied to predicates can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the comparison, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
…in predicates Some optimizations that are applied to predicates in SelectExpression can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the comparison, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
…in predicates Some optimizations that are applied to predicates in SelectExpression can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the comparison, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
@maumar @smitpatel Please update description with more details and investigate for 2.1. |
Derived Include generates join condition using ternary to appropriately cast to derived type. SELECT [l].[Name], [l].[Discriminator], [l].[LocustHordeId], [l].[ThreatLevel], [l].[DefeatedByNickname], [l].[DefeatedBySquadId], [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOrBirthName], [t].[Discriminator], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank]
FROM [LocustLeaders] AS [l]
LEFT JOIN (
SELECT [l.DefeatedBy].*
FROM [Gears] AS [l.DefeatedBy]
WHERE [l.DefeatedBy].[Discriminator] IN (N'Officer', N'Gear')
) AS [t] ON (CASE
WHEN [l].[Discriminator] = N'LocustCommander'
THEN [l].[DefeatedByNickname] ELSE NULL
END = [t].[Nickname]) AND (CASE
WHEN [l].[Discriminator] = N'LocustCommander'
THEN [l].[DefeatedBySquadId] ELSE NULL
END = [t].[SquadId])
WHERE [l].[Discriminator] IN (N'LocustCommander', N'LocustLeader') Here using Case block on join condition means join cannot use any index and no longer sargable. |
…in predicates Some optimizations that are applied to predicates in SelectExpression can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the conditional expression, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
…in predicates Some optimizations that are applied to predicates in SelectExpression can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the conditional expression, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
…in predicates Some optimizations that are applied to predicates in SelectExpression can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the conditional expression, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
…in predicates Some optimizations that are applied to predicates in SelectExpression can be safely applied to join predicates as well. Fix modifies CompositePredicateExpressionVisitor to also look into JoinExpression predicates and not only SelectExpression predicates. Also changes the way we build join predicates themselves, when inheritance is concerned - now the discriminator predicate will be extracted out of the conditional expression, so that the comparisons are sargable. Before: ((a is Derived) ? a.DerivedFK : null) == b.PK - which translated to CASE block (not sargable) After: a is Derived && a.DerivedFK == b.PK
fixed in 9355f64 |
At present it is applied to
SelectExpression.Predicate
onlyThe text was updated successfully, but these errors were encountered: