-
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 execution is very slow compared to SQL due to DataReader taking a long time to read results #35480
Comments
I've tried using a SqlCommand directly to check the slow queries and apparently the DbDataReader's ReadAsync takes a long time for some rows.
|
Ur issue I believe is how you have written your linq... And therefor your sql... My suggestion is write the raw sql which gives you the performance you want ie it has nothing to do with ef.. Then convert that sql into the linq equalivent. I have seen this so many times... First start with the sql and then it will help you think about modeling the linq Take the raw sql that linq gives you and you will get the same bad performance from sql running directly , ruling out everything else aka its the sql which is generated by you. |
@Seabizkit The issue in that case would be that EF is reporting incorrect query times (or I'm interpretting the log incorrectly). |
This isn't something that has anything to do with EF - it would be something to investigate at the SqlClient level. SqlClient unfortunately indeed has various known issues around async . I'm also confused, because afterwards you write: "It's reporting a time of ~200ms to execute the query and taking ~5 seconds to actually read it to C# objects.". So I'm still not sure what exactly performance problem you're describing here. If you want us to investigate anything, you'll have to submit a minimal, runnable repro (a partial screenshot as above does not count). |
U are mistaking compiling the query 200 ms for it executing it. Like I said, take the raw sql and execute directly with out ef you will find it will take just as long to run +- Your problem is ur linq and therefor the sql... |
I guess I'm confused about what times EF is actually logging/reporting. |
|
I basically have the same issue (I think) like a lot of the other people where my query is "fast" to execute, but where the conversion to C# objects is taking way longer than expected.
I stumbled upon the following issues which were similar:
#23900
#24194
I believe these issues are similar because the view I'm using is outputting JSON columns, which are potentially very long.
These issues were apparently fixed by swapping
.ToListAsync()
for.ToList()
, but that did not resolve my issue.I've also bumped into #34939 where the solution was to reference the latest Microsoft.Data.SqlClient (5.2.2), but that also did not resolve my issue.
I've tried to use versions 7.0.20, 8.0.11, 8.0.12 and 9.0.0 of Microsoft.EntityFrameworkCore but the issue persists in all of them.
As you can tell from the screenshot, my issue is based around the
.Where(x=>...)
clauses.For some queries, the datareader manages to read everything very fast and for others it's just slow for some reason.
It's always returning the same 11 rows, so I'd guess the length of the strings (all nvarchar) is not the culprit here.
This is the console output I'm getting:
The text was updated successfully, but these errors were encountered: