-
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: Issue warning for queries with paging operations (First, Take, Skip) without OrderBy #6576
Comments
We don't want to add ordering for the user as it's sometimes not clear what the orderby column(s) should be. However we should issue a warning in the logger if we encounter a query (or subquery) with Take or Skip and no orderby |
btw, we now produce more efficient queries for this scenario:
and
|
…s (First, Take, Skip) without OrderBy Performing paging operations without OrderBy may lead to unpredictable results and could be hard to track down. Fix is to issue a warning in the logger if such situation happens.
…s (First, Take, Skip) without OrderBy Performing paging operations without OrderBy may lead to unpredictable results and could be hard to track down. Fix is to issue a warning in the logger if such situation happens. Also added some refactoring to query model and expression printers
…s (First, Take, Skip) without OrderBy Performing paging operations without OrderBy may lead to unpredictable results and could be hard to track down. Fix is to issue a warning in the logger if such situation happens. Also added some refactoring to query model and expression printers - added option to remove formatting from the output string as well as limit the output to certain number of characters.
…s (First, Take, Skip) without OrderBy Performing paging operations without OrderBy may lead to unpredictable results and could be hard to track down. Fix is to issue a warning in the logger if such situation happens. Also added some refactoring to query model and expression printers - added option to remove formatting from the output string as well as limit the output to certain number of characters.
…s (First, Take, Skip) without OrderBy Performing paging operations without OrderBy may lead to unpredictable results and could be hard to track down. Fix is to issue a warning in the logger if such situation happens. Also added some refactoring to query model and expression printers - added option to remove formatting from the output string as well as limit the output to certain number of characters.
…s (First, Take, Skip) without OrderBy Performing paging operations without OrderBy may lead to unpredictable results and could be hard to track down. Fix is to issue a warning in the logger if such situation happens. Also added some refactoring to query model and expression printers - added option to remove formatting from the output string as well as limit the output to certain number of characters.
Fixed in 527a55f |
…s (First, Take, Skip) without OrderBy Performing paging operations without OrderBy may lead to unpredictable results and could be hard to track down. Fix is to issue a warning in the logger if such situation happens. Also added some refactoring to query model and expression printers - added option to remove formatting from the output string as well as limit the output to certain number of characters.
This is not working correctly with FromSQL. I do have an order by but still incorrectly get the warning : =-=-=-=- My end users are going to consistently see a pointless warning message in my application's log, how can I disable this warning? |
@WhatFreshHellIsThis - The order by needs to be in LINQ query. Your ORDER BY is inside SQL. We don't parse SQL. |
Yes exactly which is why this functionality that was added is a broken feature. It is going to freak out my end users who will see that completely incorrect error inside the application log. This needs to be fixed, it's not implemented correctly. |
Or, is there a way to disable this warning if it can't be implemented correctly? |
It is not broken feature. It follows design principle for us that we don't try to analyze user provided SQL. With that in mind it is implemented correctly. If you want to avoid warning then instead of putting order by inside your SQL, you can put it in your LINQ. |
OrderBy is part of a dynamic feature where a user selects which column they want to order a grid by, hence it's required to be in the dynamic sql. How is it not a broken feature if it doesn't work correctly and reports incorrect facts? |
Strictly no. Parsing user provided SQL is hard and prone to errors. It is a warning not an error. You may see it as an error if you turn on warnings as errors. That being said, the whole purpose of it being warning is, if it is fine for you to run the query then go for it. We just warned you but it may be still correct results. The feature is not broken because it does report warning accurately in the cases, we should. It may report warning in some cases inaccurately but we cannot identify those cases any way. So there is nothing actionable. |
Steps to reproduce
Download the source from the Automapper project (https://github.com/AutoMapper/AutoMapper).
Take the unittest ExpandCollections.cs from the project IntegrationTests.Net4. It is working with EF 6.
See the expressions and the sql generated.
Add the project IntegrationTests.NetCore from the attachment zip. It is the same project, but now for EF core.
IntegrationTests.NetCore.zip
I sligthly adapted the original unit test.
ExpandCollectionsEric.zip
The issue
For EF 6 we see one generated SQL query.
For EF core we see 3 generated SQL queries:
We can discuss about why 3 queries, but because we have yet basic LINQ support in this version of EF core, I hope that this will be just a starting situation (why a select top1 and a full table scan for the Category table?)
My point of concern is here the SELECT TOP(1) without an ORDER BY.
Normally that is always a bug, very difficult to find if there is always only one record expected.
There exists no default order in ANSI SQL standard or in SQL Server.
A SELECT TOP 1 without an ORDER BY will give a random row from the set. Which one is depending from the resource use of the sql server at that moment.
Probably it is a check to verify if there is one record, but it is still a bug...
The text was updated successfully, but these errors were encountered: