Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm using SQL Server 2012. I’m using CTE to create an orders table from the items table. The final count for the orders table is around 120 million. It is taking about 2 hours for the whole process.

Can partitioning the table help reduce the completion time?

If so, can I partition an empty table by order year and then insert into the orders table from the CTE. Or will I need to create a partition on the items table since the CTE is rolled up from the items table?

Also my estimated number of rows differ significantly from the actual number of rows.

share|improve this question

3 Answers 3

Can partitioning the table help reduce the completion time?

No. Partitioning is not a performance feature, is used for other purposes. If the table has 120 million rows unpartitioned, it will also have 120 million rows after partitioning. Read How To Decide if You Should Use Table Partitioning.

If you want to improve performance you need to identify the bottleneck and address them appropriately. Is it a bad plan? Missing index? Slow IO? Slow CPU? Not enough RAM? Poor code? USe a methodology like Waits and Queues to identify the bottleneck.

share|improve this answer

You might improve performance with partitioning. You will need to experiment on a development server and see if it is something that can benefit you.

You may improve query performance, based on the types of queries you frequently run and on your hardware configuration. For example, the query optimizer can process equi-join queries between two or more partitioned tables faster when the partitioning columns in the tables are the same, because the partitions themselves can be joined.

Partitioned Tables and Indexes (msdn)

share|improve this answer

Can partitioning the table help reduce the completion time?

Yes - if you have sufficient CPU and IO resources to achieve query parallelism and partition the table on a key that will result in a set number of partitions having a roughly equal number of rows in them at all times. This approach uses a principle of spreading the workload across the partitions much like a MPP architecture. The drawback of the approach is you lose the ability to perform fast switching of partitions for deletion of data. We have used this approach in a DB2 z/OS based billing system for 15 years, where our "orders" table is partitioned by a random account number that hashes between the fixed number of partitions (200). Our batch billing process uses query parallelism to spread workload between up to 32 worker threads and thus completing the query to bill 1/20'th of the accounts in 1/32 the time it would take if a serialized process were used on a non-partitioned table.

Almost all SQL Server advice focuses on partition elimination for query performance and fast switching to achieve quick purge of inactive data and in most cases that is appropriate. But your question is a good one as it shows that there are edge cases where a different approach to partitioning can be beneficial.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.