By: Sushil Rout
There are two types of storage available in the database; RowStore and ColumnStore.
In RowStore, data rows are placed sequentially on a page while in ColumnStore values from a single column, but from multiple rows are stored contiguously. So a ColumnStore Index works using ColumnStore storage.
Now let's show how we can create a ColumnStore Index and how performance can be improved.
Creating a Column Store Index
Creating a ColumnStore Index is the same as creating a NonClustered Index except we need to add the ColumnStore keyword as shown below.
The syntax of a ColumnStore Index is:
Performance Test
I used the AdventureWorks sample database for performing tests.
At this point we have created the ColumnStore Index on our test table. Now we will run the SELECT query with and without the ColumnStore Index and analyze performance.
Query Without ColumnStore Index
We have used the OPTION(IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX) query hint to not to use the ColumnStore Index this time.
Query With ColumnStore Index
Here are the Actual Execution Plans for both queries:
We can see the cost when using the NonClustered Index is 59 % while using the ColumnStore index is 13%.
Now if we hover the mouse over the Index Scans we can see details for these operations. The below is a comparison:
It is clear from the results that the query performs extremely fast after creating the ColumnStore Index as the column needed for the query is stored in the same page and the query does not have to go through every single page to read these columns.
Performing INSERT, DELETE or UPDATE Operations
We cannot perform DML ( Insert\ Update \ Delete ) operations on a table having a ColumnStore Index, because this puts the data in a Read Only mode. So one big advantage of using this feature is a Data Warehouse where most operations are read only.
For example, if you perform a DELETE operation on a table with a ColumnStore Index you will get this error:
However, to perform the operation we would need to disable the ColumnStore Index before issuing the command as shown below:
Creating a ColumnStore Index using Management Studio
Right click and select New Index and select Non-Clustered Columnstore Index...
Click add to add the columns for the index.
After selecting the columns click OK to create the index.
Limitations of a ColumnStore Index
- It cannot have more than 1024 columns.
- It cannot be clustered, only NonClustered ColumnStore indexes are available.
- It cannot be a unique index.
- It cannot be created on a view or indexed view.
- It cannot include a sparse column.
- It cannot act as a primary key or a foreign key.
- It cannot be changed using the ALTER INDEX statement. You have to drop and re-create the ColumnStore index instead. (Note: you can use ALTER INDEX to disable and rebuild a ColumnStore index.)
- It cannot be created with the INCLUDE keyword.
- It cannot include the ASC or DESC keywords for sorting the index.
No comments:
Post a Comment