You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AsSplitQuery + paging with ordering containing duplicates #25260
when using .Include to load some child table with .skip(n).take(n) and .AsSplitQuery() the translated query for fetching rows
of child table has a subquery which is assumed to return correct set of result (same set as before) BUT imagine condition where there are more than one plausible sub set for the main query base on the exact same query (after sorting base on some fields and take top 10 rows there might be more than one possible outcome - all of the rows have same rank ) then the subquery in the .Include might return different set of results ( which happened to me - may be because of sql query optimizations ... )
of course its always possible to add order by some unique field to fix the problem but its not obvious
Possible fixes
EF by default adds sort/order by base on primary key of main table
or
may be the subquery in ".Include" uses foreign key of returned set
changed the title [-].AsSplitQuery() plus Include(t=>t...) plus pagging with .skip(n).take(n) assumes wrong assumptions! [/-][+]AsSplitQuery + paging with ordering containing duplicates[/+]on Jul 14, 2021
EF by default cannot add sorting since adding any additional ordering increases the perf. See #19828 The additional term will only be useful iff the ordering + paging combination has duplicates crossing the paging boundary. It is not possible for EF Core to figure out it is the case without looking at data, so we cannot add ordering optionally only when needed either.
Since this is purely manifest due to the query & data combination, user should make sure that their ordering terms at least has one unique term when applying paging or not use split-query.
Activity
[-].AsSplitQuery() plus Include(t=>t...) plus pagging with .skip(n).take(n) assumes wrong assumptions! [/-][+]AsSplitQuery + paging with ordering containing duplicates[/+]smitpatel commentedon Jul 14, 2021
EF by default cannot add sorting since adding any additional ordering increases the perf. See #19828 The additional term will only be useful iff the ordering + paging combination has duplicates crossing the paging boundary. It is not possible for EF Core to figure out it is the case without looking at data, so we cannot add ordering optionally only when needed either.
Since this is purely manifest due to the query & data combination, user should make sure that their ordering terms at least has one unique term when applying paging or not use split-query.