Who is afraid of Columnstore Indexes? (Michael Zilberstein, DB-Art)
This talk describes new SQL Server 2012 feature called "columnstore index". In this session we will learn about the differences between columnstore indexes and B-Tree indexes we are used to work with. We will see when it is best to use and when not to use this new index. We will cover limitations that columnstore index imposes on the tables that use it and how to live with those limitations. Like in all my sessions, I won't let you go without some internals – how columnstore index is organized on a physical level and how Query Processor works this new type of index. And of course Demos, Demos, Demos…
5. Reduced IO
Fetches only needed columns
from disk
SELECT C2, SUM (C3) …
C2 C3 Columns are compressed
C1 C4 C5 C6
Less IO
Better buffer hit rates
5
6. New query execution technology
Batch mode execution of some operations
– processes rows in batches
– groups of batch operations in query plan
Better parallelism, better algorithms
6
7. Dictionary-based compression
Year of Code
Birth
1996 1
Fact - 60 distinct values 1975 15
Internal Dictionary
1948 50
Year of
1932 58
Birth
… 60
1996 On-the-fly build dictionary with
all distinct value.
1975 Substitute non-selective
1975 values with ID.
Index in our example – 6 bits
1948 Year of per row.
Birth
1932 Code
1 Compressed Fact
…
15
15
50
58
60
7
8. Segments
C1 C2 C3 C4 C5 C6 Column segment
Set of contains values from
about 1M one column for a set
rows of about 1M rows
Column segments
are compressed
Each column
segment stored in
separate LOB
Column segment is
Column unit of transfer from
Segment disk
8
11. Best practices / worst practices
Best practices:
–Put columnstore indexes on large tables only.
–Include every column of the table in the
columnstore index.
–Structure your queries as star joins with grouping
and aggregation as much as possible.
Worst practices:
–Avoid JOIN and/or filter on string columns in the
table with columnstore index.
–Avoid OUTER JOIN, UNION ALL, IN/NOT IN.
–Avoid JOIN between 2 Fact tables.
11