I'm using the default DO4 project template, which comes with MyEntity. I simply renamed MyEntity to Customer, and did a session.Query.All<customer>().Count().

Why does DO use subselects?

SELECT COUNT_BIG(*) AS [column] FROM (SELECT [a].[Id], 101 AS [TypeId], [a].[Name] FROM [dbo].[Customer] [a]) [b];

Why not simply SELECT COUNT_BIG(*) FROM Customer?

It does this for non-count queries, too, unless they are projected to DTOs... in which case it uses normal queries (i.e. doesn't use subselects).

asked Mar 05 '11 at 04:53

ara's gravatar image

ara
395828791


One Answer:

Hello Ara,

Actually, this is not a subselect. Subselect is executed for every source record while here is just select from select.

And the answer is: such behavior is by intent, it is the result of generic layered query translation architecture: operations are applied to the result of previous operation execution (here COUNT operation is applied to all records from the Customer set).

In case you are suspicious about the possible performance lack, I could state that the performance of these 2 queries as well as execution plans are identical.

answered Mar 05 '11 at 05:36

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA