Skip to content

Batch split queries #10878

Open

Description

@roji

In some scenarios, EF Core internally generates more than one read in order to execute a single query. This is notably the case when executing (some?) joins when using a non-MARS provider. Performance could be (greatly!) improved by batching those multiple reads into a single batch internally. Unless I'm mistaken, in the case you generate multiple queries, the results for the earlier queries have to be buffered anyway, so there's no additional penalty in the buffering implied in the batching.

Note: this issue isn't about exposing a batching read API to the user (that's what #10879 is about).

NOTE: batching becomes impossible if we decide to go in the direction of #12776 (fetching dependents by foreign keys instead of reevaluating the principal query).

Activity

  1. added this to the Backlog milestone on Feb 7, 2018
  2. ajcvickers commented on Feb 8, 2018

    @ajcvickers
    Contributor

    Note: see also #10465, which is very similar but comes from a slightly different angle.

  3. divega commented on Feb 8, 2018

    @divega
    Contributor

    See also #5952

  4. roji commented on Sep 25, 2019

    @roji
    MemberAuthor

    Unless I'm mistaken, this is no longer relevant as we generate one SQL query per LINQ query since 3.0. Closing.

  5. removed this from the Backlog milestone on Nov 12, 2019
  6. roji commented on Apr 21, 2020

    @roji
    MemberAuthor

    Reopening and assigning to @smitpatel at his request, could be done as part of the workaround for #18022.

  7. reopened this on Apr 21, 2020
  8. 14 remaining items

  9. roji commented on Mar 4, 2024

    @roji
    MemberAuthor

    Note: batching becomes impossible if we decide to go in the direction of #12776 (fetching dependents by foreign keys instead of reevaluating the principal query).

  10. added theissue type on Jun 15, 2025
  11. bachratyg commented on Jul 17, 2025

    @bachratyg

    I've checked what command batching does to isolation/consistency in SQL Server and PostgreSQL, and the results are negative: merely batching statements into the same DbCommand doesn't have any impact on isolation.

    If it is possible to batch split queries (i.e. no #12776) then it is possible to combine them into a single query, see #22435 (comment).

    Some perf may be lost on transferring large chunks of nulls though.

  12. roji commented on Jul 29, 2025

    @roji
    MemberAuthor

    @bachratyg makes sense. We definitely have to at some point think about the best strategy going forward - allowing the user to select from multiple possible ones may also be the way.

  13. PeterDraex commented on Oct 26, 2025

    @PeterDraex
  14. roji commented on Oct 26, 2025

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

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions