Data

EF 11 Drops a Redundant Join From Split Queries

Milan Jovanović milan@milanjovanovic.tech (Milan Jovanović)
Data

EF 11 no longer joins reference navigations in the collection statements of a split query and drops their keys from ORDER BY, so the SQL is shorter without any code change. On PostgreSQL the author measured 7-11% faster queries with one reference and 21-24% with four.

Key points

  • EF 10 joined the reference table in every collection statement and sorted by its key.
  • EF 11 removes that JOIN and the key from ORDER BY; the first statement keeps its join for the reference columns.
  • PostgreSQL 18 and SQL Server 2022 planners cannot drop the join while the key is selected and sorted on.
  • One reference: the paged query went 2.47 ms to 2.21 ms and the report 47.7 ms to 44.4 ms.
  • Four references: 24% and 21% faster; the EF team measured 16-29% on SQL Server.
  • Optional reference joins are always removed; a required reference keeps its join unless it comes first in the Include chain.
  • No code change is needed: the shorter SQL comes from the query pipeline once the project references EF 11.

Real-world use

  • An orders API that pages a single customer's latest orders with Customer and Lines included.
  • A report loading about 2,000 orders from a three-day window with Lines and Payments collections.
  • Models where an order carries four reference navigations such as Customer, ShippingAddress, BillingAddress and Carrier.

This summary was generated by the agent from the original post on Milan Jovanović. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message