Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: manually created GroupJoin with order by key descending generates invalid SQL #8754

Closed
maumar opened this issue Jun 6, 2017 · 1 comment
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Jun 6, 2017

query:

from c in ctx.Customers
join o in ctx.Orders on c.CustomerID equals o.CustomerID into grouping
where c.CustomerID.StartsWith("A")
orderby c.CustomerID descending
select grouping.Count();

sql:

SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Customers] AS [c]
LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID]
WHERE [c].[CustomerID] LIKE N'A' + N'%' AND (LEFT([c].[CustomerID], LEN(N'A')) = N'A')
ORDER BY [c].[CustomerID] DESC, [c].[CustomerID]

exception:

A column has been specified more than once in the order by list. Columns in the order by list must be unique.

For client GJs we add ordering by key so that we can materialize elements correctly, it doesn't matter if we do asc or desc, so we should re-use customer generated order if one was specified.

@ajcvickers ajcvickers added this to the 2.0.0 milestone Jun 12, 2017
maumar added a commit that referenced this issue Jun 16, 2017
…scending generates invalid SQL

Problem was that ordering by the same column twice, but with different direction is invalid. This would usually be user error, however in some cases we introduce order by ourselves (e.g. in case of group join).
If then customer provides their own ordering with opposite direction, we would generate invalid query. We already have logic to catch duplicate ordering (if they are the same).

Fix is to expand the logic that catches "duplicate" ordering to match ordering with different direction and being the same.
maumar added a commit that referenced this issue Jun 19, 2017
…scending generates invalid SQL

Problem was that ordering by the same column twice, but with different direction is invalid. This would usually be user error, however in some cases we introduce order by ourselves (e.g. in case of group join).
If then customer provides their own ordering with opposite direction, we would generate invalid query. We already have logic to catch duplicate ordering (if they are the same).

Fix is to expand the logic that catches "duplicate" ordering to match ordering with different direction and being the same.
@maumar
Copy link
Contributor Author

maumar commented Jun 19, 2017

fixed in b825435

@maumar maumar closed this as completed Jun 19, 2017
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants