-
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
Having inheritance creates excessive query #15374
Comments
@smitpatel is this a duplicate? |
No. |
Note from triage: We will see if we can optimize this in 3.0 or otherwise will punt. |
In new pipeline, we will at least not cause subqueries. We still generated joins which we can optimize easier. |
@smitpatel Are you sure this is not a duplicate of #3419? |
This and #3419 both are them are not capturing the join elimination we are going to do. That is remove join for the cases when the table is same in database. I would suggest filing new issue and close both of them. |
Using 5.0 preview7 SELECT TOP(1) [r].[Id], [r].[VO1_MyInt], [r].[VO1_MyString], [r].[VO2_MyInt], [r].[VO2_MyString], [r].[VO3_MyInt], [r].[VO3_MyString], [r].[VO4_MyInt], [r].[VO4_MyString], [r].[VO5_MyInt], [r].[VO5_MyString]
FROM [RegularClasses] AS [r]
WHERE [r].[Id] = @__p_0
SELECT TOP(1) [b].[Id], [b].[MyType], [b].[MyColA], [b].[VO1_MyInt], [b].[VO1_MyString], [b].[VO2_MyInt], [b].[VO2_MyString], [b].[VO3_MyInt], [b].[VO3_MyString], [b].[VO4_MyInt], [b].[VO4_MyString], [b].[VO5_MyInt], [b].[VO5_MyString]
FROM [BaseClasses] AS [b]
WHERE [b].[Id] = @__p_0 |
Great news, thank you! |
I had a simple class with some value objects, but decided to extend it by using inheritance and having discriminator. It started to generate some excessive queries. I replicated this with sample below:
Calling
api/values/RegularClass
generates normal query:while calling
api/values/ChildClass
generates this monster query:If I compare the execution plans I get this:
My query now runs 6 times slower because of what seems to be simple design upgrade. Any thoughts on this?
Further technical details
EF Core version: 2.2.3
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio Code 1.33.1
The text was updated successfully, but these errors were encountered: