2014-03-30

Columnstore index is one of the new features shipped with SQL Server 2012. I have written few articles about this type of index and described how it boosts in the performance. Recently, I worked on a huge table having table partitions residing in different file groups. And it seems that it is already optimized using Table partition. However, I tried to create a columnstore Index to further boost its performance and I did succeed.

Let me demonstrate it step by step.

Step 1 :

First of all, you need to create a partition function as shown below. If you already have partition function please SKIP this step.

Step 2 :

Secondly, you need to create a partition scheme on the above partition function as shown below. If you already have partition scheme please SKIP this step.

Step 3 :

Now, it is time to create a table using above created partition scheme to partition the data accordingly as shown below. If you already created a table using partition scheme please SKIP this step.

Step 4 :

Lets insert some data to test the performance.

Step 5 :

Once you insert the data, lets build the columnstore index. Remember, once you build the columnstore index you cannot modify the data in the table.

Step 6 :

Once you build the columnstore index, lets execute the query and view the result set WITHOUT columnstore index.

SQL Server parse and compile time:

CPU time = 15 ms, elapsed time = 69 ms.

(265 row(s) affected)

Table ‘Worktable’. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table ‘PurchaseOrderDetail_Sample’. Scan count 3, logical reads 4100, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

SQL Server Execution Times:
CPU time = 983 ms, elapsed time = 1158 ms.

Step 7 :

Lets execute the query and view the result set WITH the columnstore index.

SQL Server parse and compile time:

CPU time = 16 ms, elapsed time = 57 ms.

(271 row(s) affected)

Table ‘Worktable’. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table ‘PurchaseOrderDetail_Sample’. Scan count 1, logical reads 242, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

SQL Server Execution Times:
CPU time = 717 ms, elapsed time = 782 ms.

Conclusion :

As you can observe, there is huge difference between both queries (with and without columnstore index) performance. However, you need to test it in your scenario and implement it accordingly. In addition, kindly read the restrictions & limitation about columnstore index as well.

Show more