-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: OrderBy constant generates incorrect query for integer/boolean #6145
Comments
I think the cases of ORDER BY with a non-numeric and non-Boolean constants and ORDER BY with variables/parameters could also be interesting. Assuming we are using the same naive translation we use for numeric and Boolean constants, SQL Server will throw:
It seems that the general approach could be to swallow any elements in the It is true if there are paging operations and we remove all elements of the (BTW if anyone finds anything other than |
@divega Have you considered |
@kunnis actually no. Great tip! @smitpatel @anpete this seems to works. I think we should consider doing it here as well as when we need an arbitrary ORDER BY for paging. Thoughts? |
Won't work with SQL ce.., |
@divega Yes. I recently also discovered this trick when working on the improved GroupJoin prototype. |
@ErikEJ does SQL CE have all the dame issues? E.g.is it already broken for these scenarios? |
@divega I think it currently has the same problem. https://github.com/ErikEJ/EntityFramework.SqlServerCompact/blob/master/src/Provider40/Query/Sql/Internal/SqlCeQuerySqlGenerator.cs#L76 Uses CE doesn't allow for a scalar_subquery (which is what I setup SqlCE earlier today and ran a statement ending in |
The same issue persists in SQLite too. Fixing it for relational provider in general. |
At present in query,
OrderBy(c => true)
translates toORDER BY 1
OrderBy(c => 3)
translates toORDER BY 3
In SqlServer,
ORDER BY
integer means order by that column number from projection which introduces unintended ordering and gives different results compared to what linq gives.We are also using creating Order by when we do group join with default if empty using the left side of join condition which also faces above issue based on the join condition.
See tests
QuerySqlServerTest.OrderBy_true
,QuerySqlServerTest.OrderBy_integer
&GearsOfWarQuerySqlServerTest.Left_join_predicate_value_equals_condition
Possible work-arounds:
We can remove the order by clause if it is using constant. Results would match this way with linq but for paging cases, order by clause is necessary.
We can introduce dummy order by as follows:
Order by @@ROWCOUNT
Order by @parameter + 1
where @parameter is passed. Value doesn't matter.@divega
The text was updated successfully, but these errors were encountered: