question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

what is the best way to resolve AsSplitQuery perf warning vs transactionally consistent data?

See original GitHub issue

I have a context used throughout a blazor project, conveniently it warns when someone creates a perf issue by .include 'ing too many child tables:

Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'

That link mostly seems to be there so you can find the link to this page: https://docs.microsoft.com/en-us/ef/core/querying/single-split-queries which has some warnings about how splitqueries are not guarenteed to be transactional ly consistant and some notes about turning the settings on and off globally.

As best as I can follow you can only configure the warnings on an injected context at the point you are configuring it. It seems that I should be able to use splitqueries with DbContext.Database.BeginTransaction but manually creating a read-isolated transaction on a bunch of very busy tables when the query the EF warning is triggering on is already running pretty efficiently seems like the wrong answer.

Am I missing an option somewhere to suppress the warning on a specific query? I can change the splitting behaviour with .AsSplitQuery but I do not see anything like that for warnings

Am I underestimating how bad the non-split version actually is and even though it is fast it would be safer to split it and wrap it in a longer lasting (and to my understanding of sql internals probably more expensive) manual transaction?

Ideally i would like to leave this warning on then specifically suppress it on queries that have a high likelihood of a dirty read, but perhaps I am misunderstanding something here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
direthingcommented, May 1, 2021

Apologies to @roji - dyslexic reading has had exactly the result @stevendarby assumed was happening here.

This does suppress the error.

Am I missing somewhere that this is explained in the documentation? or is it just too new since I get less than a full page of google results for the RelationalQueryableExtensions version of AsSingleQuery?

0reactions
direthingcommented, May 1, 2021

thank you, I definitely was not looking at the section about turning off consistency globally after I first ran into these warnings and tried the suggested .AsSplitQuery with undesirable results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework Core : LINQ advise needed on better ...
The first step to optimising the query is probably to work out how you would best accomplish the same result in SQL. ·...
Read more >
Single vs. Split Queries - EF Core
While most databases guarantee data consistency for single queries, no such guarantees exist for multiple queries. If the database is updated ...
Read more >
Entity Framework AsSplitQuery() single join before and ...
One possible resolution for the 'cartesian explosion' problem is to split the queries up when serving them against the DB and join the...
Read more >
Split Queries in EF. Problem | by Cosmin Vladutu - Medium
Solution · 1. If you are using pagination (skip and take), be sure you are making your LINQ unique, from the ordering perspective....
Read more >
Document behavior of AsSplitQuery() when subquery has ...
This sure breaks the logic of your "AsSplitQuery()" so that I needed to remove it completely and live with the performance decrease.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found