Composed query with groupBy clause in subquery fails
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
調査の方向性
まず、groupBy句を含む合成F#クエリのSQLProviderによる変換を追跡し、再現用に生成されたサブクエリを調べます。INサブクエリが要求された集約列だけを選択し、グループキーを明示的に選択した場合は引き続きそれも含まれることを確認できれば完了です。両方のケースをカバーする回帰テストを追加するか実行してください。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
SqlException "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS." returned when using a composed query when the subquery has a groupBy clause. This is because SQLProvider includes the groupBy key in the select clause even if you haven't asked for it.
To Reproduce
Steps to reproduce the behavior:
- Take a query that uses a subquery with a groupBy clause, e.g.:
let test =
let lastAddresses =
query {
for a in dbContext.Address do
where (a.Deleted.IsNone)
groupBy a.UserId into g
select (g.Max(fun a -> a.Id))
}
let result =
query {
for a in dbContext.Address do
where (lastAddresses.Contains(a.Id))
select a
}
result
- Run the query, and you get the SqlException described above.
- Inspecting the SQL produced, you can see the problem:
SELECT *
FROM [address] as [a]
WHERE (([a].[Id] IN (
SELECT [a].[UserId] as '[a].[UserId]', MAX([a].[Id]) as '[a].[MAX_Id]'
FROM [address] as [a]
WHERE (([a].[Deleted] IS NOT NULL))
GROUP BY [a].[UserId]))
)
- Basically SQLProvider is including
[a].[UserId] as '[a].[UserId]'in the select clause of the subquery. TheINclause is only expecting a single column in the subquery so fails.
Expected behavior
SQLProvider should only return the columns requested in the query. The SQL produced should be:
SELECT *
FROM [address] as [a]
WHERE (([a].[Id] IN (
SELECT MAX([a].[Id]) as '[a].[MAX_Id]'
FROM [address] as [a]
WHERE (([a].[Deleted] IS NOT NULL))
GROUP BY [a].[UserId]))
)
Additional context
If we wanted the groupBy key included in the select statement, we could do so by requesting it explicitly, so there is no reason why SQLProvider should do this for us unsolicitedly:
let test =
let lastAddresses =
query {
for a in dbContext.Address do
where (a.Deleted.IsNone)
groupBy a.UserId into g
select (g.Key, g.Max(fun a -> a.Id))
}
let result =
query {
for a in dbContext.Address do
where (lastAddresses.Contains(a.Id))
select a
}
result
- 主要言語
- F#
- スター
- 627
- フォーク
- 147
- 平均マージ
- 2時間 2分
- マージ済み PR(30日)
- 1
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fsprojects/SQLProvider のほかの issue
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
fsprojects/SQLProvider#872 · コメント 2 件 ·
-
Repo Assist? オープンenhancement
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
fsprojects/SQLProvider#870 · コメント 1 件 ·
-
postgresql
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
fsprojects/SQLProvider#869 · コメント 2 件 ·
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 42/100
fsprojects/SQLProvider#868 · コメント 2 件 ·
-
sql server
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
fsprojects/SQLProvider#851 · コメント 1 件 ·
fsprojects/SQLProvider の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
AstrBotDevs/AstrBot#10205 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
OHDSI/Data2Evidence#3394 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100