Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Custom Pagination with Complex Queries
Message
From
18/06/2009 09:43:08
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Application:
Web
Miscellaneous
Thread ID:
01406794
Message ID:
01406852
Views:
52
See the order here:

Re: Interview questions Thread #1380550 Message #1401825


>I'm not 100% certain, but I think using UNION it always first tries to produce this huge result set and only then apply Row_NUMBER(), so no wonder it would be slow.
>
>You may try to create the inner result (the UNION one) as a view and see if the performance could be improved.
>
>>Hi all,
>>
>>Currently my application is facing slow performance due to the growth of data. After reading some articles, I have a brief understanding on how pagination works.
>>
>>However, I would like to ask for some advice on implementing pagination for complex SQL with lots of JOIN and UNION.
>>
>>For simple SQL, I use the following approach.
>>
>>
>>-- * Pagination with Simple Query --
>>SELECT * FROM (
>>     SELECT field1, field2, field 3, ROW_NUMBER() OVER (ORDER BY field1) AS RowNum      
>>FROM table1
>>) AS Result
>>WHERE Result.RowNum BETWEEN 1 AND 10
>>
>>
>>For complex SQL
>>
>>-- * Pagination with Complex Query --
>>SELECT * FROM (
>>     SELECT *, ROW_NUMBER() OVER (ORDER BY field1) AS RowNum FROM (
>>          SELECT field1, field2, field3 FROM table1       
>>          UNION       
>>          SELECT field1, field2, field3 FROM table2       
>>          UNION       
>>          SELECT field1, field2, field3 FROM table3   
>>) AS UnionData) AS Result
>>WHERE Result.RowNum BETWEEN 1 AND 10
>>
>>
>>Is there a better approach for complex queries? Kindly advise, thanks.
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform