Composed query with groupBy clause in subquery fails
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu bằng cách theo dõi quá trình SQLProvider dịch các truy vấn F# kết hợp có mệnh đề groupBy và kiểm tra truy vấn con được tạo cho trường hợp tái hiện. Hoàn tất khi truy vấn con IN chỉ chọn cột aggregate được yêu cầu, trong khi việc chọn tường minh khóa nhóm vẫn bao gồm khóa đó; thêm hoặc chạy một regression test bao quát cả hai trường hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- F#
- Star
- 627
- Fork
- 147
- Merge trung bình
- 2 giờ 2 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của fsprojects/SQLProvider
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
fsprojects/SQLProvider#872 · 2 bình luận ·
-
Repo Assist? Đang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
fsprojects/SQLProvider#870 · 1 bình luận ·
-
postgresql
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
fsprojects/SQLProvider#869 · 2 bình luận ·
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 42/100
fsprojects/SQLProvider#868 · 2 bình luận ·
-
sql server
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
fsprojects/SQLProvider#851 · 1 bình luận ·
Tất cả issue của fsprojects/SQLProvider
Issue tương tự
-
Edit: CW+ Đang mởchannels:edit check:passed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
[6.x]: "Cannot use object of type stdClass as array" loading Users index (regression of #19182) Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
[InvoiceShelf] No database info Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
community-scripts/ProxmoxVE#17396 · 1 bình luận ·
-
bug possible-duplicate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
AOSSIE-Org/PictoPy#1553 · 4 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BasedHardware/omi#15274 · 3 bình luận ·