0% found this document useful (0 votes)
118 views22 pages

ColumnStore Indexes

This document provides an overview of columnstore indexes in SQL Server. It begins with an introduction to the speaker and their background. It then covers the basics of columnstore indexes, including that they store data in a columnar format compared to the row-based format of traditional indexes. The document demonstrates columnstore indexes in SQL Server 2012 and 2014 and covers features, best practices, data type support and restrictions. It concludes by discussing enhancements to columnstore indexes in SQL Server 2016 and later versions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views22 pages

ColumnStore Indexes

This document provides an overview of columnstore indexes in SQL Server. It begins with an introduction to the speaker and their background. It then covers the basics of columnstore indexes, including that they store data in a columnar format compared to the row-based format of traditional indexes. The document demonstrates columnstore indexes in SQL Server 2012 and 2014 and covers features, best practices, data type support and restrictions. It concludes by discussing enhancements to columnstore indexes in SQL Server 2016 and later versions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

ColumnStore Indexes

UNIQUE and NOT DULL www.MyGareth.com


Agenda
ColumnStore Indexes

About me
The Basics
Key Characteristics
DEMO
SQL Server 2014 ColumnStore indexes
DEMO
Best Practices
Data Types
Restrictions
SQL Server 2016+ ColumnStore indexes

UNIQUE and NOT DULL www.MyGareth.com


Gareth Swanepoel

From South Africa originally

Been in IT for 25+ years

Was first a sysadmin, then a DBA

Premier Field Engineer with Microsoft

Author - SQL 2012 Pro Admin


Speaker – SQL User Groups, SQL Saturdays,
Webinars, SQL PASS Summit

eMail : [email protected]
Twitter : @GarethSwan
Website : www.MyGareth.com

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
ColumnStore Indexes – the basics

Row Store (Heap / B-Tree) Column Store (values compressed)


ProductID OrderDate SaleAmount ProductID OrderDate SaleAmount

data
310 20010701 2171.29
data 310 data 20010701 data 2171.29

page 311 20010701 1912.15 page 311 page 20010701 page 1912.15

1000 312 20010702 2171.29 2000 312 2010 20010702 2040 2171.29

313 20010702 413.14 313 20010702 413.14

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
Key Characteristics of CSI's
➢ Columnar data format
➢ Key columns
➢ Faster query results
➢ Partitioning
➢ Record size limit
➢ Query processing
➢ Table cannot be updated … WHAT ????

UNIQUE and NOT DULL www.MyGareth.com


DEMO SQL 2012 ColumnStore Index

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
PDW & SQL 2014 Column Segment

C1 C2 C3 C4 C5 C6

Row Group:

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
PDW & SQL 2014 Delta (row)
C1 C2 C3 C4 C5 C6

store


C1 C2 C3 C4 C5 C6

Updates
Column
Store

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
PDW v2 & SQL 2014
xVelocity - Memory Optimised, Updateable CLUSTERED CSI

➢ ColumnStore is the preferred storage engine in PDW 2012


➢ No secondary indexes are supported with CCSI’s
➢ Tables are divided up into “Row Groups” & “Column Segments”
➢ Row Groups are approx. 1 million rows in size
➢ Index creation runs in parallel

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
PDW v2 & SQL 2014
DUI support is achieved by the use of a “Delta table”
➢ The Delta table is in row store format (no CCI)
➢ Delta rows are included into the CCI automatically (at approx. 1 million
rows in size)
➢ CLOSED Delta rowgroups can be manually added with:
ALTER INDEX <idx_name> REORGANIZE
➢ Deleted space can be reclaimed with:
ALTER INDEX <idx_name> REBUILD PARTITION =
<partition number | all>

UNIQUE and NOT DULL www.MyGareth.com


DEMO SQL 2014 ColumnStore Index

UNIQUE and NOT DULL www.MyGareth.com


2014 ColumnStore indexes
• INSERTED a single record into a table with clustered columnstore index

• Screenshots taken from DMV sys.column_store_row_groups (subset of total rows returned)

• Before row inserted:

• After single row inserted (deltastore has been created and single row represented)

• After REBUILD
• REORGANIZE only moved delta store records into segment
• REBUILD affects entire index (or entire partition index) Segment row count increased by 1

UNIQUE and NOT DULL www.MyGareth.com


2014 ColumnStore indexes
• The state_description field has three states: COMPRESSED, OPEN, and CLOSED
• COMPRESSED represents a row group that is stored in columnstore format
• OPEN represents a deltastore that is accepting new rows
• CLOSED represents a full deltastore ready for REORGANIZE

• When inserting 102,400 rows or more in a single batch into a columnstore index distribution, the data will compress automatically

• When inserting 102,399 or less rows in a single batch, the data will be stored in the delta store

• The actual maximum number of rows per delta store is 1,048,576 at which point it is CLOSED
• This is also the ideal segment size that SQL Server will try to create when first building a columnstore index from a table
• When Index Build encounters memory pressure, DOP is reduced first and then segment size is reduced

• Only the REBUILD statement can compress a delta store that is not in the CLOSED state
• Neither REORGANIZE or the Tuple Mover process will have any effect on an OPEN delta store

UNIQUE and NOT DULL www.MyGareth.com


2014 ColumnStore indexes
• Consider a table with a single partition range of 100 with two partitions

• INSERT the partition key values 50 and 150 into the table

• REBUILD the index on partition 1

• INSERT three more records into partition 1 (Note partition 2 is still in deltastore form also)

• REBUILD the entire index (as opposed to the single partition above)

Note: When attempting a partition MERGE or SPLIT operation, be aware that a table with a columnstore index will return an error and fail to
execute whereas a traditional row-based clustered index/heap will perform the operation successfully

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
Best Practices
➢ Choosing Columns (Non-Clustered CSI only)
➢ DO … put CSI's on large tables only
➢ DO … structure queries as star-joins
➢ DON'T … use OUTER JOIN
➢ DON'T … use UNION ALL
➢ DON'T … use string filters, etc
➢ DON'T … use NOT IN (<subquery>)

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
Supported Data Types
➢ char and varchar
➢ nchar and nvarchar (except varchar(max) and nvarchar(max))
➢ decimal (and numeric)
➢ int , bigint, smallint, tinyint and bit
➢ float (and real)
➢ Uniqueidentifier (2014 only)
➢ money and smallmoney
➢ All date and time data types
➢ binary and varbinary (except varbinary(max))

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
Unsupported Data Types

➢ ntext , text, and image


➢ varchar(max) and nvarchar(max)
➢ varbinary(max)
➢ rowversion (and timestamp)
➢ sql_variant
➢ CLR types (hierarchyid and spatial types)
➢ Xml

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
Restrictions
➢ Cannot have more than 1024 columns (SQL limitation)
➢ Cannot be a clustered index (2012 only)
➢ Cannot be a unique index (with caveats)
➢ Cannot act as a primary key or a foreign key (with caveats)
➢ Cannot be created on a view or indexed view
➢ Cannot include a sparse column
➢ Cannot be changed using the ALTER INDEX statement
➢ Cannot be created by with the INCLUDE keyword
➢ Cannot include the ASC or DESC keywords for sorting the index

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
Feature Restrictions

➢ Page and row compression, and vardecimal storage format


➢ Replication
➢ Change tracking
➢ Change data capture
➢ FileStream
➢ FileTable

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
ColumnStore Indexes in SQL 2016+ & Azure SQL DB, DW, APS

➢ Snapshot isolation and read-committed snapshot isolation


➢ Specify ColumnStore index when creating a table
➢ Updateable non-clustered ColumnStore indexes
➢ AlwaysOn readable secondary supports updateable ColumnStore
indexes
➢ ColumnStore index on a memory-optimized table
➢ Filtered non-clustered ColumnStore indexes
➢ Performance enhancements
➢ 2017 only – non-persisted computed columns

UNIQUE and NOT DULL www.MyGareth.com


ColumnStore Indexes
References
➢ Books On-Line: https://docs.microsoft.com/en-us/sql/relational-
databases/indexes/columnstore-indexes-overview
➢ ColumnStore Indexes Versioned Feature Summary:
https://docs.microsoft.com/en-us/sql/relational-
databases/indexes/columnstore-indexes-what-s-new
➢ Niko Neugebauer ColumnStore Blog Series:
http://www.nikoport.com/columnstore/

UNIQUE and NOT DULL www.MyGareth.com


Thanks
eMail : [email protected]
Twitter : @GarethSwan
Website : www.MyGareth.com

You might also like