Bart wrote:
What is the meaning of the smiley Otis...
If i understand your smiley correct than you mean that my previous post with the disadvantage explains why LLBL uses method 1.
That's indeed the reason
btw, LLBLGen Pro uses a slightly different CTE nowadays, it doesn't place the ordering in the ROW_COUNT function anymore as that can lead to wrong results sometimes.
BUT... all though all records return the total rowcount i could still prefer using that methods because of their performance benefits avoiding the distinct
Bart (that is still looking for some opinions on this one!)
The main reason is that any extra action determining the count is potentially hurting performance because it has to traverse the complete set. This can be avoided in every subsequential page retrieved. So you first determine the count, then you page through it. Page 2, 3 etc. don't have to determine the page count anymore.
What's also the case is that in a lot of cases, you can use a simpler query to determine the total # of elements in the set, i.e. only index fetches, which leads to faster performance, using a scalar query. If you determine the set size every time, this is potentially slower: the CTE isn't likely bringing the complete set into memory at once. With the count it has to (in some cases).