Test bug: Include_collection_with_cross_apply_with_filter relies on nondeterministic ORDER BY with Take
メンテナーはふだん 2 日以内に返信
@Mohamedadel-prog がすでに取り組んでいます。
2026年11月29日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 66/100
調査の方向性
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時間
- マージ済み PR(30日)
- 158
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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時間 初心者へのやさしさ 82/100
microsoft/sqltoolsservice#2851 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
elsa-workflows/elsa-foundation#6322 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
mohebifar/made-in-iran#273 ·