Skip to content

Query: Relational: Eliminate LeftJoins from SQL if no reference outside #21774

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
smitpatel opened this issue Jul 24, 2020 · 1 comment
Open

Comments

@smitpatel
Copy link
Contributor

A simple case would be SQL like this

SELECT a.Id, a.Name
From Aninals AS a
LEFT JOIN Birds AS b

LEFT JOIN would not affect the result set size. (Whereas INNER JOIN will do filter if no matching rows hence cannot be removed).
This would prune all the derived table joins from TPT if not used. Some overlap with #21773
But this enhancement can be applicable outside of TPT also
e.g.

from c in customers
join o in orders on c.CustomerID equals o.CustomerID into grouping
from o in grouping.DefaultIfEmpty()
select c.CustomerID
@smitpatel
Copy link
Contributor Author

Note: This is not possible in all cases. It is possible only when LeftJoin has cardinality of 0..1 Otherwise inner even though null can duplicate outers. An example outside of TPT for this would be Principal to dependent reference navigation which is not marked as required. Ideally we should have a flag and appropriately update LeftJoinExpression in Sql so that we can remove them later if not reference outside. We could also do it in LINQ but that would require traversing whole tree and inspecting which breaks natural cut down flow.

We need to do similar for SQL anyway for TPT.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants