This code is useful when to perform recalculation on very large partitioned tables. It allows to divide the calculation per partition , and works into staging table that are independent from each other
For instance if table has 30 partitions, is possible to run this code IN PARALLEL 30 times,
for example with jobs, or by sqlcmd in batch scripts for windows,
then to switch the results into the target table
It is fast : my test performed a 10mil rows table in about 5 minutes
Limitations: It will work with partitioned tables by range , having PK clustered or nonclustered sorted asc, and no check or foreign key constraints .
Supports data compression , so if the code needs to be compiled on sqlserver2005 is necessary to comment a piece.
Is possible to execute or only to script commands
- Input Parameters:
1. @output_type: S=script only, E=execute only, SE = both
2. @SchemaName - Partitioned Table Schema Name
3. @TabName - Partitioned Table Name
4. @PartitionNo - Partition number to be rebuilded
exec dbo.populate_partition 'S','dbo','POSTPAID_RATED_EVENT',15,
' ( select *
from POSTPAID_RATED_EVENT_old a
and $partition.Traffic_Data_Monthly_PF(Network_Start_Time) =15 ) qioren'
Warning: Clause with(tablock) could create problems during parallel execution