Short answer: a columnstore index stores a table by column instead of by row, in rowgroups of up to about a million rows, each column compressed on its own. A query that sums one column over millions of rows reads only that column, compressed many times over, and runs in batch mode. Use a clustered columnstore for large fact tables and reports; keep rowstore indexes for tables you look up or update row by row.
Analytics queries touch few columns and many rows; order entry touches all columns of few rows. The two storage layouts each suit one of those.
How is it stored?
- Rowgroupsup to 1,048,576 rows each
- Segmentsone per column per rowgroup, compressed on its own
- Delta storenew rows wait here in rowstore until a rowgroup is full
- Delete bitmapmarks deleted rows until the rowgroup is rebuilt
Each segment also keeps the minimum and maximum of its values, so a filter on a date range can skip whole rowgroups without opening them.
How do you create and load one?
CREATE TABLE dbo.FactSales (
DateKey int NOT NULL,
CustomerKey int NOT NULL,
ProductKey int NOT NULL,
Quantity int NOT NULL,
Amount decimal(18,2) NOT NULL,
INDEX cci_FactSales CLUSTERED COLUMNSTORE
);Load in large batches. A bulk insert of 102,400 rows or more goes straight into compressed rowgroups; smaller inserts land in the delta store and are compressed later by a background task. Thousands of single-row inserts keep rows in the delta store, uncompressed, and every read scans them row by row.
SELECT OBJECT_NAME(object_id) AS TableName, state_desc, total_rows, deleted_rows
FROM sys.dm_db_column_store_row_group_physical_stats
WHERE object_id = OBJECT_ID('dbo.FactSales');What goes wrong?
- Small rowgroups. Many rowgroups well below a million rows compress poorly. Rebuild or reorganise the index after many small loads.
- Heavy updates and deletes. An update is a delete plus an insert; deleted rows stay in the bitmap until a rebuild. Columnstore suits tables that mostly grow.
- Lookups by key. Finding one order by its ID scans segments. Add a nonclustered rowstore index for such queries, or keep the table rowstore.
Where can you check this?
- Microsoft Learn: Columnstore indexes: overview
- Microsoft Learn: Columnstore indexes: data loading guidance
Where do you start?
Star schema in Power BI explains the fact tables that suit this index, and DirectQuery models in Power BI storage modes are fastest on a source built this way.