|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, March 13, 2012 9:16 AM
Points: 6,
Visits: 75
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 5:19 AM
Points: 228,
Visits: 472
|
|
| Since TOP supports a variable , add top variable to select with row_number statement to improve performance
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Sunday, May 12, 2013 4:01 AM
Points: 406,
Visits: 1,364
|
|
Adding a top clause to the sub query will break the intended functionality: only the first page will return data. You could put a top clause in the outer query, but from what I've tested quickly this doesn't make any difference for IO nor cpu time. In fact, the query plan seems identical. The 2nd has the disadvantage that it returns data for negative page numbers too (i.e. it may be considered less robust).
declare @nRowsPerPage int; declare @nPage int;
select @nRowsPerPage = 25, @nPage = 142;
select x.* from ( select row_number() over (order by col.object_id, col.name) as rowNB, col.* from sys.columns col ) x where x.rowNB > (@nRowsPerPage * (isnull(@nPage,0) - 1)) and x.rowNB <= (@nRowsPerPage * isnull(@nPage,0)) order by x.rowNB;
select top (@nRowsPerPage) x.* from ( select row_number() over (order by col.object_id, col.name) as rowNB, col.* from sys.columns col ) x where x.rowNB > (@nRowsPerPage * (isnull(@nPage,0) - 1)) order by x.rowNB;
Posting Data Etiquette - Jeff Moden Posting Performance Based Questions - Gail Shaw Hidden RBAR - Jeff Moden Cross Tabs and Pivots - Jeff Moden Catch-all queries - Gail Shaw
If you don't have time to do it right, when will you have time to do it over?
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 27, 2012 1:23 AM
Points: 9,
Visits: 160
|
|
It is a good way to process large data, only
PRINT @message could be replaced by RAISERROR(@message, 5, 1) WITH NOWAIT
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, July 06, 2012 10:51 AM
Points: 68,
Visits: 374
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, June 13, 2012 3:26 PM
Points: 566,
Visits: 341
|
|
Hi Zach, I think thats a pretty neat approach.
With large tables I prefer to use table partitioning, which gets around the issue of locking a live table for an extended period of time, and improves query performance etc. I can see how your method would be benefitial for non-partitioned tables though.
Cheers for the article.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, March 13, 2012 9:16 AM
Points: 6,
Visits: 75
|
|
Yes, I agree that partitioning is very useful and should be strongly considered by anyone that is working with large data sets. I am using partitions and still find breaking large operation into smaller pieces to be very useful. In my situation, I have SQL statements that operate on huge portions of the partitions and cause a lot of table locks within the partitions themselves. These locks cause too much contention with the production system and are not feasible for the business.
When I use this technique on a partitioned table, I always order the records primarily by the partition key. This further reduces lock contention and allows SQL Server to perform well by leveraging the clustered index.
Even in the case when partitions are being used to perform operations "offline", breaking large SQL into smaller pieces is useful. For example, for some SQL operations, I switch select partitions into an "offline" table which eliminates any lock contention by any operations against those partitions from the production system. I also drop all unnecessary indexes in the "offline" table so that the operation will run much faster. Even for these "offline" partitions, I have found that breaking large SQL operations into smaller pieces is helpful. So, instead of inserting 10,000,000 rows in one shot, I use this technique to insert 20 sets of 500,000 rows. This causes less system resources to be used at a time and allows any other processes running on the same database server to run better. An additional benefit is that the operation can be stopped and started mid-stream which is helpful if it is an operation that takes hours rather than minutes to run.
Zach Mided www.AllianceGlobalServices.com
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: 2 days ago @ 11:09 AM
Points: 115,
Visits: 322
|
|
Zach,
The research looks great and the article is nice explains itself very good. In SQL Server or any RDBMS partitioning large table helps in many ways and batch processing always improves the performance. It is all depends on your server and database architect.
I like this document. I use to work for him 10 years ago.. 
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 20, 2013 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, June 21, 2012 8:27 AM
Points: 3,
Visits: 10
|
|
| Nice Article, a perfect representation of "Incremental Loading" wonder if an error handling section could be added somewhere
|
|
|
|