-
Notifications
You must be signed in to change notification settings - Fork 927
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
LINQ Query with Any() Operator should maybe use EXISTS instead of TOP 1 (using SQL Server) #3437
Comments
It does. What exact issue do you have? What it the query and what is the sql generated? What version of NHibernate? |
@hazzik following are the details UserClassMap
The code snipped is as follows.
SQL query
|
For "naked" Any:s it does that. Using EXISTS is not necessarily the solution, since some kind of value would have to be returned. In SQL it would perhaps have to be SELECT CASE WHEN EXISTS.... It is, as you say, unnecessary that all columns are fetched. I've fixed that in a project of mine, with an expression rewriter that prepends a "Select(x=>x.Id)" to naked Any:s. I guess it could even be "Select(x=>1)". Maybe such a rewrite could be suitable for the core. |
If the Any returns true, yes. Using an EXISTS would have to fetch/return data in both cases. For SQL Server, if the projected property |
Personally, I wish it just selected the id field for the entity, that would likely always be more performant. But I'd imagine there's reasons why it's not implemented as such. |
Session.Query<TEntity>().Any()
should generate SQL with EXIST statementSELECT ( CASE WHEN EXISTS ( SELECT NULL FROM TABLE T ) THEN 1 ELSE 0END ) AS [Value]
Instead of fetching the full first row in memory with
SELECT TOP(1) COLUMN1...COLUMN(N) From TABLE T
The text was updated successfully, but these errors were encountered: