-
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 Perf: Selecting entire table for navigation properties in projections #5738
Comments
Related to #4007 |
Is this a bug or work in progress? |
Closing as a dupe |
Reopening as we are going to track the lack of filtering issue separately from the n+1 optimization. |
cc @maumar |
Don't get me wrong, I really appreciate the team's hard work and all. Many things have changed to the best in Microsoft in the last couple of years, including the open source and multi platform change, but "version 1 isn't reliable - wait for SP1" hasn't. |
@gdoron your feedback is fair, LINQ providers take time and EF Core is no exception. There are definitely some significant limitations in the initial RTM, but we are working to address these and I think it will mature quickly from this point on. Most of what we are doing is bug fixing now, though there are some notable things still to be implemented (such as GroupBy transalation). We've tried to be very transparent about what to expect when using EF Core https://docs.efproject.net/en/latest/efcore-vs-ef6/index.html. I do think that v1 software in general tend to be less mature - not just from Microsoft. Historically this was amplified by our slow release cadence, think back to .NET being >1 year between releases. I'm hopeful that folks that are adopting new technology will be able to keep up-to-date as we get some releases out quickly that address the top issues folks are hitting. |
@rowanmiller I have no complains about EF core not being as good as EF 6, it's obvious that a rewritten software, specially in EF's size will have many bugs in its early development, it's a temporary condition and I believe everyone is aware of this and accept it. I was arguing that EF core was rushed and released too early, before it's ready. It seems that the only reason EF core is being released now is to follow the same schedule as the rest of .NET Core and ASP.NET Core. Each brick should be independent, just like WebSockets and SignalR that were left behind for future releases. As a side note, as a consumer of the library, it's by far more important for us that EF Core's core features will work as they should, with good performance and reliability than having another nice to have feature (like scaffolding for instance). With great appreciation to you and your team, |
…erties in projections TODO: description
…erties in projections TODO: description
…erties in projections Fix is to allow more queries to be translated to SQL, specifically subqueries that are correlated with outer query, e.g. customers.Select(c => c.Orders.FirstOrDefault()) would get translated to: customers.Select(c => orders.Where(o => o.CustomerId == c.Id).FirstOrDefault()) This would produce outer query to fetch all the customers and for each customer another query, fetching ALL the orders each time filtering out the orders for each customer and returning only the first one on the client (because we didn't know how to handle o.CustomerId in this case) With this change we will convert o.CustomerId into a SQL parameter, whose value is set for each iteration of the outer query - this can be easily translated to SQL and produce much more efficient queries: SELECT [t].[CustomerID] FROM [Customers] AS [c] @_outer_CustomerID: ALFKI (Size = 450) SELECT TOP(1) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Orders] AS [o] WHERE @_outer_CustomerID = [o].[CustomerID] We achieve this by introducing a new query method that executes a delegate before enumerating it's source, and then executing another delegate after all elements have been enumerated or the enumerator has been disposed. Those functions set and remove the necessary parameters just before/after the inner query is accessed.
@gdoron I have to fundamentally disagree with you. Rowan is on point. Yes, it's ideal if enough people use your betas that v1.0.0 is flawless, but that may not be realistic. It's far worse if you get paralyzed into needing it to be perfect before you ship. Version 1 Sucks, But Ship It Anyway is a great read by the co-founder of Stack Exchange. Also, If you aren't embarrassed by v1.0 you didn't release it early enough. |
@jnm2 I read Jeff's blog post briefly but I believe I got the general idea. There's no reason to ship version 1 when you are already fully aware of the huge issues your software has. If your version 1 will take servers and applications down because of N+1 queries and full tables(with a capital S) retrieval in a single query (as I painfully experienced), and you're aware of it, DO NOT SHIP IT. There's a huge difference between being perfect and being reliable. I guess you wouldn't want your bank's R&D department to read that blog and say, awesome idea! so lets go live with "version 1 sucks" and see what the feedback will be. I am very disappointed with EF Core and will move our company to use Dapper or EF 6.1 if things won't get fixed very soon. I think EF somewhere on the road made a huge mistake at prioritizing the features (maybe because of someone else making a terrible decision and changing the schedule and roadmap midway, as I believe happened).
but off top of my head, issues that we suffer from:
So there are many issues, but there isn't even a way of overcome them with The team, as you can see in the issues and the pull requests, are working hard and being transparent with the community. But they must prioritize the basic features of ORM first. |
But that's your list. I'd never use views and SPs directly with EF. I think many to many without a join entity is a bad idea personally. Shadow properties are just as much a basic feature of an ORM as view and SP support, if not more fundamentally so. I can hardly believe we're finally getting them! The only bugs that would affect my company are the perf ones which is why I'm holding out for 1.0.1. EF Core is not broken. For some people, EF Core is working perfectly. The EF team made it clear that EF Core will not be at parity with EF 6 for a long time, so everything is up for grabs. I experimentally moved our stuff to EF Core so I could provide feedback, but ultimately the onus is on you to verify whether taking the dive in production is a good idea. Every RTM release will have bugs and if servers went down because you didn't spend enough time testing your use cases before going to production that is your responsibility. This is the case with every library. If EF Core's feature priorities don't match your priorities and you need your EF6-ish features, that is why they clearly say that you should remain on EF6. All the information that you needed to make a good judgment call was available. |
Realocating to 1.1.0 as the fix for this was pretty high risk. |
@rowanmiller Thanks for the fix and the update! |
I used 1.1.0-alpha1-22107 and see no change in the query. |
@ruchanb I just run the following code:
on our nightly build and got this (expected) sql:
Is there any difference between the code you have and the one above? |
Hmm, I tried your code and the sql seems to be as you said. What about the no of queries on |
Steps to reproduce
Mapping on Country
Mapping on State
Now the Query
The issue
When I run SQL Profiler on this query I get following
and
I understand the two queries are not combined as in previous versions of EntityFramework. However, here the query on
State
is just select all without any where condition from theCountry
it is looking for. It does gives meStates
from'USA'
but it is doing so in the memory, not the SQL server.Now make the query to include about 5 countries, it gives me 5 of these queries without any condition for
Country
Further technical details
EF Core version: 1.0.0-rc2-final
Operating system: Windows 10
SQL Server 2008
Visual Studio version: VS 2015 update 2
Framework Target: net461
The text was updated successfully, but these errors were encountered: