SQL Server 2005
I have 10 million rows in the database and run select (with lots of "where" and joints .. pretty complicated). The results are presented in a grid (I think goolge results), and because of this, the user cannot use more than 1000 results.
So, I am limiting my SQL TOP 1000.
Problem . The user still wants to know that 5432 results were found for his search.
Can I get this information without paying the price (or, in other words, still getting the speed advantages that the "top 1000" gives?)
Assumptions
- Suppose that TOP 1000 contains 1000 rows of 100K . Thus, even a network travel cost of 100K can be a problem.
Conclusions
No free lunch! you can get an elegant way (accepted answer), but it still takes longer than a more expensive operation (i.e. counting all the results). In real life, I will go using two SQL approaches, one of which will return 1000 rows for display, and the other - ASYNC and update some AJAX panel with the results of count (*), which will take much more time on the computer.
csmba source
share