what is the best way to resolve AsSplitQuery perf warning vs transactionally consistent data?
See original GitHub issueI 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:
- Created 2 years ago
- Comments:6 (3 by maintainers)
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?
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.