SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Pagination options SQL 2012 vs 2008 (Performance perspective)


Pagination options SQL 2012 vs 2008 (Performance perspective)

Author
Message
npranj
npranj
Mr or Mrs. 500
Mr or Mrs. 500 (521 reputation)Mr or Mrs. 500 (521 reputation)Mr or Mrs. 500 (521 reputation)Mr or Mrs. 500 (521 reputation)Mr or Mrs. 500 (521 reputation)Mr or Mrs. 500 (521 reputation)Mr or Mrs. 500 (521 reputation)Mr or Mrs. 500 (521 reputation)

Group: General Forum Members
Points: 521 Visits: 323
I need to understand which one is better with respect to performance :

1. SQL 2012 has introducted FETCH OFFSET ...

SELECT FirstNm,LastNm
FROM Person
ORDER BY FirstNm
OFFSET 5 ROWS
FETCH NEXT 10 ROWS ONLY

2. SQL 2008 has an option of ROW_NUMBER() and then pick up specific row numbers. Sample below -
SELECT * FROM
(SELECT t1.colX, t2.colY
ROW_NUMBER() OVER (ORDER BY t1.col3) AS row
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.col1=t2.col2
)a
WHERE row >= n AND row <= m

Note: there is an index of t1.Col3.
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)SSC Guru (96K reputation)

Group: General Forum Members
Points: 96739 Visits: 38988
npranj (9/2/2013)
I need to understand which one is better with respect to performance :

1. SQL 2012 has introducted FETCH OFFSET ...

SELECT FirstNm,LastNm
FROM Person
ORDER BY FirstNm
OFFSET 5 ROWS
FETCH NEXT 10 ROWS ONLY

2. SQL 2008 has an option of ROW_NUMBER() and then pick up specific row numbers. Sample below -
SELECT * FROM
(SELECT t1.colX, t2.colY
ROW_NUMBER() OVER (ORDER BY t1.col3) AS row
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.col1=t2.col2
)a
WHERE row >= n AND row <= m

Note: there is an index of t1.Col3.


Best thing you could do is test them. What works best in one situation may not work the best in another.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
gsc_dba
gsc_dba
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2333 Visits: 2042
npranj (9/2/2013)
I need to understand which one is better with respect to performance :

1. SQL 2012 has introducted FETCH OFFSET ...

SELECT FirstNm,LastNm
FROM Person
ORDER BY FirstNm
OFFSET 5 ROWS
FETCH NEXT 10 ROWS ONLY

2. SQL 2008 has an option of ROW_NUMBER() and then pick up specific row numbers. Sample below -
SELECT * FROM
(SELECT t1.colX, t2.colY
ROW_NUMBER() OVER (ORDER BY t1.col3) AS row
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.col1=t2.col2
)a
WHERE row >= n AND row <= m

Note: there is an index of t1.Col3.


Having tried this on my setup, the new method is slightly better and IMO more readable.

Here is an external link that may provide more insight...
http://www.dbadiaries.com/new-t-sql-features-in-sql-server-2012-offset-and-fetch

gsc_dba
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search