Skip to content

AsSplitQuery + paging with ordering containing duplicates #25260

Closed as not planned

Description

@eh-torkaman

File a bug

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

Activity

  1. 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
  2. smitpatel commented on Jul 14, 2021

    @smitpatel
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions