Is it possible to update a COLUMNSTORE index in a DB transaction? I would like to use the following SQL command inside transaction:
ALTER INDEX [IX_Name] ON [dbo].[TableName] REORGANIZE WITH (COMPRESS_ALL_ROW_GROUPS = ON)
The transaction can take a long time. Will other SQL clients be able to use the index during the transaction?
Note that everything in SQL runs in it's own implicit transaction if you don't specify one, so if you're just running
REORGANIZEthere's no difference between running it or wrapping it in aBEGIN/COMMIT.COMPRESSEDrow groups are immutable, so let's use defragmentation rather than update for your scenario. In columnstore world an update translates into a delete + insert and a delete is "deferred". More specifically deletes are reflected in the deleted bitmap, which the engine joins with the data and returns the rows visible to your transaction. The per-row group state of the delete bitmap can be seen in thesys.dm_db_column_store_row_group_physical_statsDMV as thedeleted_rowscolumn. Also note that deleting or updating anOPENorCLOSEDrow group happens in-place: for deletes you'll see the row count decrement (updates won't change the row count), however you will never see anydeleted_rowsin these two types of row groups.So what does
REORGANIZEdo? It reads small and/or fragmented row groups and combines them, but not in place, rather it writes them out as new row groups and the old row group's state will change toTOMBSTONE. Old row groups will be around while they have active readers, while transactions started after theREORGANIZEwill always read the data from the new row groups.