Test bug: Include_collection_with_cross_apply_with_filter relies on nondeterministic ORDER BY with Take
维护者通常 2 天内回复
@Mohamedadel-prog 已经在做这个了。
开始于 2026年11月29日。
评估
调研方向
阅读 test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs,重点查看 Include_collection_with_cross_apply_with_filter 及相邻的 outer_apply 变体。检查这些测试如何断言已包含的集合,并确定是否可以添加唯一排序,或使断言不受顺序影响。完成标准是测试不再依赖 ORDER BY 的并列结果;运行相关查询测试进行验证。
由索引模型根据 Issue 内容生成。
描述
Description
NorthwindIncludeQueryTestBase.Include_collection_with_cross_apply_with_filter (and the outer_apply variants next to it) builds the query as:
from c in ss.Set<Customer>().Include(c => c.Orders)
from o in ss.Set<Order>().Where(o => o.CustomerID == c.CustomerID)
.OrderBy(o => c.CustomerID).Take(5)
where c.CustomerID.StartsWith("F")
select c
c.CustomerID is constant inside the correlated subquery. Therefore ORDER BY c.CustomerID does not define a unique order of Orders, while Take(5) depends on which five rows the relational provider returns. LINQ-to-Objects uses a stable sort and picks the first five source rows; SQL does not guarantee that.
Why this is not a provider requirement
SQL-92 §13.1, General Rules, item 2:
If an
<order by clause>is not specified, then the table specified by the<cursor specification>is T and the ordering of rows in T is implementation-dependent.
SQL-92, Implementation-defined elements, item 14:
If the
<declare cursor>does not include an<order by clause>, or includes an<order by clause>that does not specify the order of the rows completely, then the rows of the table have an order that is defined only to the extent that the<order by clause>specifies an order and is otherwise implementation-dependent.
PostgreSQL documentation (SELECT, ORDER BY / LIMIT):
If they are equal according to all specified expressions, they are returned in an implementation-dependent order.
It is even possible for repeated executions of the same
LIMITquery to return different subsets of the rows of a table, if there is not anORDER BYto enforce selection of a deterministic subset. Again, this is not a bug; determinism of the results is simply not guaranteed in such a case.
Codd's relational model defines a relation as a set of n-tuples; a set has no intrinsic row order, and Codd explicitly lists ordering dependence as something applications must not rely on.
Observed effect
Against a relational provider whose engine does not guarantee stable ties, the first query can pick an arbitrary set of five OrderIDs. In split-query mode the included Orders collection is then not attached to the expected parent rows, and AssertIncludeCollection fails with e.g. Expected: 5, Actual: 0. The same query can also answer differently between executions.
Suggested fix
Make the test query deterministic by adding a unique tiebreaker:
.OrderBy(o => c.CustomerID).ThenBy(o => o.OrderID).Take(5)
or assert the included collection in an order-insensitive way. The test should not require a relational engine to reproduce LINQ-to-Objects' stable tie ordering.
This is a test-specification issue, not a requirement for providers to emulate LINQ stable sort.
- 主要语言
- C#
- 星标
- 14.8k
- 派生
- 3.5k
- 平均合并
- 2 天 22 小时
- 30 天内合并 PR
- 158
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/efcore 的其他 Issue
-
customer-reported
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
Compiled model: generate a deterministic model ID可能已有人在做 @rgroenewoudt 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 2 天内回复
-
customer-reported
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 2 天内回复
相似的 Issue
-
area-VM-meta-mono untriaged
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
BattletechModders/ModTek#256 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/sqltoolsservice#2851 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
triage/untriaged
难度 2/5 1-3 小时 新手友好度 82/100
unoplatform/uno#26844 ·
维护者通常 1 天内回复