-
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
Optimize Find/Single operations with includes #22579
Comments
The warning is logged because doing |
This particular query just picks the current user by primary key, hence no Where/OrderBy.
Meaning I want the single user by Id, but I want exceptions thrown if:
I don't see why I should add Where/OrderBy in this case? |
Error on my part that it should not logged with |
Sure
|
Additional queries for |
Still trying to wrap my head around this. From a user perspective, something feels wrong since I expect to get the single user with all included navigation properties without warnings or having to add I also don't really understand why the But technical reasons aside, what is the recommended way to retrieve a single tracked item from the database by primary key having additional navigation properties eagerly loaded? |
It does predicate match but it needs to figure out which items from parent it needs to match in the predicate joining to Children. If only 1 (or limited number of parents) are selected then we have to restrict the set of parents to same amount in additional queries so that predicate only matches related data for that limited set rather than generating join for everything. We will discuss in the meeting "recommended way". |
Thanks. I'll try to suppress it for now, don't want any possible overhead of |
Actually there will be OrderBy always because of Include so that we get records in a deterministic order to create proper buckets. It can be optimized for Single case but currently that is not happening. |
Did a bit of debugging this morning and it adds an extra query.OrderBy(u => u.Id).SingleAsync(u => u.Id == currentUserId)(no warning)
query.SingleAsync(u => u.Id == currentUserId)(warning)
I'll keep the OrderBy for now until your meeting to see if there's a better way. At least I do not get any runtime warnings now anymore. |
Moving to the backlog to attempt to not generate this warning when it is not needed. |
For your info - I also did some basic StopWatch-benchmarking of the An optimized |
I just want to add that aside from having a warning where it's preferable to see none, this also makes it harder/near impossible to track down actual cases where non-deterministic results are possible because of, e.g., |
@ajcvickers friendly bump - would this be considered a candidate to move from backlog anytime soon? as you see in previous comment from 2021, there's at least 22 other souls looking for this. |
@joakimriedel This issue is currently at position 131 in the list of most voted issues. Not sure why people are doing 👍 on the comment without voting for the issue, but even if it had 23 votes, it would still only be at around position 62. |
Ok thanks, did not know it was such a strict popularity vote to get out of backlog. I'll see what I can do to promote it 😊 |
@joakimriedel It's not a strict popularity vote at all--see the planning process. But cases made on popularity need to be pretty high up the list. |
In 5.0 RC1 a warning log message is thrown for
.SingleAsync()
queries:I guess this has something to do with the fact that the actual SQL generated includes an automatic TOP(2) clause to determine if there are more than 1 item matching the query.
In 3.1 there were no warnings logged. I prefer no warnings logged.
The text was updated successfully, but these errors were encountered: