-
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
Simple count timing out #17743
Comments
Just wanted to add in that I'm seeing the same kind of slowdowns, also in 3.0. Analyzing the queries involved it seems for my case that the SQL Server was doing a pretty bad guesswork, perhaps due to queries from EF Core running through sp_executesql. Updating statistics using sp_updatestats helped the query planner a lot. That said, a like %x% query will always be hard to guess for the server. |
@jcemoller what query exactly did you execute directly against the database? LIKE with |
@divega yeah, I don't use like % in any of my queries I just wrote that as a general advice. I'm still experiencing similar issues with severe performance issues migrating to 3.0. Complex queries that used to take <1 sec is now over 1 minute. Investigating and opening up a separate issue, did not mean to take over @Menighin |
Ah, I guess my intent was to ask @Menighin: what query exactly did you execute directly against the database? LIKE with a pattern that starts with a wildcard cannot take advantage of any index, but LIKE with a pattern that starts with a character can. |
@divega I executed exactly the same |
@Menighin Did you try the workaround @jcemoller suggested?
|
@Menighin jumping in here again since I had a similar issue. What you probably are experiencing is problems with parameter sniffing (google this). When you run the query directly in SQL Server Management Studio it will recompile the execution plan. When you run through EF Core, the SQL Server will try to pick a previously cached plan based on the parameter values. If it chooses a bad plan (using wrong estimations for row count etc) it can cause bad performance. Running sp_updatestats might help as @AndriySvyryd pointed out. If not, you could try WITH RECOMPILE to ensure a new plan is always generated. |
@AndriySvyryd when #6717 gets implemented I guess it would be quite easy to add option(recompile) to queries 😉 |
@Menighin - I am closing this issue because there is nothing specific EF Core does under the hood (apart from sending sql as sp_executesql). Let us know if updating statistics works for you. |
Guys sorry for the delay repling it. I have then tried running the query with
Any other ides or should I try get the permission to run those guys? |
I have made kind of an API for my app.
Basically when the user access some page I run two basic querys:
getAll
that returns the data paginated and filteredcount
that returns the total of records with the given filter.In the backend I simply have the following structure:
My logs table is a huge table with a lot of records (1kk+ and growing).
The
GetAll
method executes fine but theCount
gives me a timeout.Analyzing the query EF generates, it is simple:
When I execute it on database directly, it runs fast enough. Like 1 or 2 secods.
When EF executes it, it takes like 20 seconds and throws a timeout exception.
Playing around, I can see the
LIKE
part of the query seems to be what drags down the performance. But the only query I see being generated in the output is the one above, which runs fast in SQL Server Management Studio. So, is EF maybe executing a select under the hood or something like that? Any ideas how to make this work?Im using EFCore 2.2.
Thanks
The text was updated successfully, but these errors were encountered: