What is columnstore index and how is different from clustered and non-clustered

前端 未结 3 998
猫巷女王i
猫巷女王i 2021-02-07 11:05

Hi I am confused about columnstore index, what is column store index and how it is different from clustered and non-clustered index..

3条回答
  •  终归单人心
    2021-02-07 11:42

    Assume you have a table like below with col1 as primary key

    col1  col2  col3
    1      2     3
    4      5     6
    

    Normal index will be stored like below,assuming a page can hold only one row

       row1  1   2  3--page1-- all columns reside in one page
       row2  4   5  6--page2
    

    so when you want to read some thing like sum(col3),SQLServer will need to read page1 and page 2 to get 3,6,that's a cost of two pages..

    Now with column store indexes,The same table will be stored like below

    page1  page2   page3
    1       2       3
    4       5       6
    

    Now if you want to do a sum of col3,it just has to read one page(page3)

    Benefit of using column store indexes is, you may touch only necessary pages from Disk .Memory is also efficiently used ,since you will not be storing/reading unwanted data

提交回复
热议问题