A SQL Server table with a clustered columnstore index receives a steady trickle of single-row INSERTs and its scans slow down; what is happening, and how do you fix it?
answer
- where small inserts actually land
- the 102,400-row bulk threshold
- rowgroup states and trim reasons
- a REORGANIZE option for open rowgroups
basics
~20 sSmall inserts go to the delta store, uncompressed B-tree rowgroups that every scan must read alongside the compressed columnstore. Load in batches of at least 102,400 rows, or compress them now with ALTER INDEX ... REORGANIZE WITH (COMPRESS_ALL_ROW_GROUPS = ON).
solid answer
~50 sA SQL Server columnstore index compresses rows in **rowgroups** of up to 1,048,576 rows. Single-row inserts, and any batch under 102,400 rows, go to the **delta store** instead: OPEN delta rowgroups that are ordinary B-trees. A delta rowgroup becomes CLOSED only when it reaches 1,048,576 rows, and then the background tuple mover compresses it. Until then every scan reads those rows through a B-tree as well as scanning the columnstore. Updates add to it, because each one marks the compressed row deleted and inserts the new version into the delta store. I'd confirm it with `sys.dm_db_column_store_row_group_physical_stats` (`state_desc`, `total_rows`, `deleted_rows`, `trim_reason_desc`). Then I'd change the loader to send batches of 102,400 rows or more, which compress directly, and run `ALTER INDEX ... REORGANIZE WITH (COMPRESS_ALL_ROW_GROUPS = ON)` to compress the open rowgroups now. From SQL Server 2019 a background merge task also compresses small open rowgroups that have been around for a while.
code
sql · 7 linesSELECT row_group_id, state_desc, total_rows, deleted_rows, trim_reason_desc
FROM sys.dm_db_column_store_row_group_physical_stats
WHERE object_id = OBJECT_ID('dbo.SensorReadings')
ORDER BY row_group_id;
ALTER INDEX CCI_SensorReadings ON dbo.SensorReadings
REORGANIZE WITH (COMPRESS_ALL_ROW_GROUPS = ON);go deeper
Know that a columnstore index stores data by column for analytics and that SQL Server has clustered and nonclustered kinds.
Explain rowgroups, the delta store, the tuple mover and the 102,400-row threshold for compressing a bulk load directly.
Diagnose a degraded columnstore from rowgroup states, deleted rows and trim reasons, and fix the load pattern rather than scheduling rebuilds.
Decide where columnstore belongs: a clustered columnstore for warehouse tables, a nonclustered one for analytics on OLTP tables, or a separate analytical store, and what each costs in load design.
## How a columnstore index stores rows A **columnstore index** stores data by column rather than by row. Rows are gathered into **rowgroups**, normally of the maximum 1,048,576 rows, and each column of a rowgroup is compressed into a **column segment**. Queries read only the columns they need, and segments compress very well, which is why columnstore suits large scans and aggregations. Why columnar layouts compress and scan well in general is engine-neutral material; this answer is about how SQL Server manages it. SQL Server has two kinds: | | Clustered columnstore (CCI) | Nonclustered columnstore (NCCI) | | --- | --- | --- | | What it is | The table's primary storage | A compressed copy of chosen columns on a rowstore table | | Typical use | Fact tables, large history tables | Analytics over an OLTP table, side by side | | Other indexes | Nonclustered B-tree indexes allowed | The rowstore table keeps its own indexes | | Key columns | None | None; can carry a filter predicate | Constraints such as a primary key are always enforced by rowstore indexes, never by the columnstore itself. ## The delta store and the tuple mover Compressing a rowgroup is expensive, so SQL Server doesn't do it for small writes. A rowgroup moves through these states, visible in `sys.dm_db_column_store_row_group_physical_stats`: - **OPEN**: a delta rowgroup, an ordinary clustered B-tree, accepting new rows. - **CLOSED**: a delta rowgroup that has reached the maximum row count and is waiting to be compressed. - **COMPRESSED**: compressed column segments in the columnstore. - **TOMBSTONE**: a rowgroup no longer in use, such as a delta rowgroup that has been compressed or a compressed one whose rows were all deleted, waiting for cleanup. - **INVISIBLE**: a compressed rowgroup still being built. The **tuple mover** is the background process that compresses CLOSED rowgroups and removes tombstones. All delta rowgroups together are called the **delta store**, and a query combines rows from the columnstore and the delta store to return correct results. ## Why trickle inserts hurt - Every single-row `INSERT` lands in an OPEN delta rowgroup, and it won't close until it holds 1,048,576 rows. - Rows in the delta store are read through a B-tree, which is slower than reading compressed segments. - An `UPDATE` of a compressed row marks it **logically deleted** and inserts the new version into the delta store; a `DELETE` only marks it, so space isn't reclaimed until the rowgroup is reorganized or rebuilt. - Rows that go through the delta store are fully logged, while large batches compressed directly produce a much smaller log. ## Diagnose Query the rowgroup DMV for the table: ```sql SELECT partition_number, row_group_id, state_desc, total_rows, deleted_rows, trim_reason_desc FROM sys.dm_db_column_store_row_group_physical_stats WHERE object_id = OBJECT_ID('dbo.SensorReadings') ORDER BY partition_number, row_group_id; ``` Many OPEN rowgroups, many small COMPRESSED rowgroups, or a high share of `deleted_rows` all point at the load pattern. `trim_reason_desc` says why a compressed rowgroup holds fewer than the maximum rows, for example `BULKLOAD`, `REORG`, `DICTIONARY_SIZE` or `MEMORY_LIMITATION`. ## Fix 1. **Batch the load.** A bulk load or `INSERT ... SELECT` of 102,400 rows or more compresses straight into the columnstore; only a remainder under 102,400 rows goes to the delta store. Stage trickle data in a rowstore table and move it across in large batches. 2. **Compress what's already there** with `ALTER INDEX ... REORGANIZE WITH (COMPRESS_ALL_ROW_GROUPS = ON)`, which forces OPEN and CLOSED delta rowgroups into the columnstore. A plain `REORGANIZE` compresses CLOSED rowgroups, merges small compressed ones, and removes deleted rows from rowgroups where 10% or more are deleted. It always runs online. 3. **Rebuild a partition** when only some partitions are badly fragmented, instead of the whole table. 4. **Let the background merge help.** From SQL Server 2019, the tuple mover's background merge compresses small OPEN rowgroups that have existed for some time and merges compressed rowgroups with many deleted rows, which in most cases removes the need for regular `REORGANIZE` jobs. For a nonclustered columnstore on a busy OLTP table, `COMPRESSION_DELAY = n MINUTES` keeps closed rowgroups in the delta store for at least that long, so rows that are updated soon after insert aren't compressed and then deleted again. ## Version notes - **2019**: background merge in the tuple mover. - **2022**: ordered clustered columnstore indexes (`ORDER (...)`), which improve rowgroup elimination. - **2025**: ordered nonclustered columnstore indexes, and ordered columnstore indexes can be created or rebuilt online. Releases up to SQL Server 2017 could only rebuild a clustered columnstore index offline; current releases accept `ONLINE = ON`.
- When would you choose a nonclustered columnstore index rather than a clustered one?When the table is primarily transactional and must keep its rowstore clustered index for seeks and updates, but analytics also scan it. A nonclustered columnstore keeps a compressed, updatable copy of the chosen columns for those scans, at the cost of extra storage and write work. A clustered columnstore suits tables that are mostly loaded and scanned.
- Can a table stored as a clustered columnstore index enforce a primary key?Yes. Constraints are enforced with rowstore indexes, so a primary key or unique constraint adds a nonclustered B-tree index on the columnstore table. That index also allows fast seeks; when a query needs columns it lacks, the plan shows a Key Lookup that locates rows by their columnstore location rather than by a clustering key.
- Every INSERT into a columnstore is compressed into column segments immediately.
- The tuple mover compresses a delta rowgroup once it holds 102,400 rows.
- Deleting rows from a compressed rowgroup frees their space at once.
- Columnstore indexes need the same frequent REBUILD schedule as rowstore indexes.
- A nonclustered columnstore index makes the table read-only.
Assumes SQL Server 2025; the background merge task arrived in SQL Server 2019, ordered clustered columnstore in 2022 and ordered nonclustered columnstore in 2025.