var query = Query.All<MyEntity>()
  .Where(i => i.IsFtIndexUpToDate == false)
  .Select(i => i.Key)
  .Take(100);
query.ToList();

generates the SQL:

SELECT TOP 100 [a].[Id] 
FROM [dbo].[MyEntity] [a] 
WHERE ([a].[IsFtIndexUpToDate] = 0) 
ORDER BY [a].[Id] ASC;

which takes 30s on our database, due to the order by.

Why this LINQ query does not generate this SQL (without order by) ?

SELECT TOP 100 [a].[Id] 
FROM [dbo].[MyEntity] [a] 
WHERE ([a].[IsFtIndexUpToDate] = 0);

That takes less than one second to execute.

In that case we do not want the result in a particular order : we do not care if we get an unordered result set. Actually the performance hit of the order by is so important that it causes timeouts.

I understand the idea behind the automatically added OrderBy but this is into relevant to our case. How can we write this query in LINQ without an order by in SQL?

If you keep this behavior, it should be documented in manual.

asked Dec 13 '10 at 12:24

olorin's gravatar image

olorin
358878792

edited Dec 13 '10 at 12:25


One Answer:

After some investigation we've started the bug fixing process, the first results are expected to be at the end of the current week. Stay tuned.

answered Dec 15 '10 at 06:09

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Thanks! It will help in the cases where we need optimization.

(Dec 16 '10 at 10:42) olorin olorin's gravatar image

The issue is fixed in 4.3 branch. Binaries will be updated shortly.

(Jan 14 '11 at 07:15) Dmitri Maximov Dmitri%20Maximov's gravatar image

DataObjects.Net 4.3.7 & 4.4 beta 2 is released

(Jan 29 '11 at 04:24) Dmitri Maximov Dmitri%20Maximov's gravatar image
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