-
Notifications
You must be signed in to change notification settings - Fork 149
Closed
Labels
Description
Your sample schema for Log table is a classic B-Tree, which is not optimal for storing large amount of data such as logs. CLUSTERED COLUMNSTORE index should be better choice for storing logs when JSON format is used (not applicable to XML).
- CCI are available in all editions of SQL Server (even in Express) since SQL-2016 SP1.
- CCI support nvarchar(max) type in the current CTP and Azure SQL Database, so we can store LogEvent column in CCI
- JSON support is available since SQL-2016, which enables us to query LogEvent column using the functions like JSON_VALUE(LogEvent, '$.Propertes.RequestPath')
Unfortunately XML is not yet supported in CCI, but if someone uses JSON as log format, CCI would be much better option than B-tree (JSON is stored in nvarchar(max)). Could you update your docs and propose something like the following table schema if JSON logging is used with the latest SQL Server:
CREATE TABLE [Logs] (
[Message] nvarchar(max) NULL,
[Level] nvarchar(128) NULL,
[TimeStamp] datetimeoffset(7) NOT NULL,
[LogEvent] nvarchar(max) NULL,
[Exception] nvarchar(max) NULL,
INDEX cci CLUSTERED COLUMNSTORE
)
nblumhardt