QuestionQ27

Secure, optimize, and deploy database solutions

You have a SQL database in Microsoft Fabric that includes a table called WebSite.Logs. WebSite.Logs stores application telemetry data and contains an nvarchar(max) column named log that holds JSON documents.

A daily report filters on the $.severity JSON property and returns LogId, LogDateTime, and log. The report often performs full table scans.

You need to modify WebSite.Logs so filtering by $.severity is efficient and key lookups are avoided for the columns the report returns.

How should you complete the Transact-SQL code to prevent full table scans? Each value may be used once, more than once, or not at all.

Drag & Drop
ALTER TABLE WebSite.Logs
    ADD severity ;
GO

CREATE INDEX ix_severity
    ON WebSite.Logs(severity)
    ;
GO
Explanation

JSON_VALUE extracts the scalar severity value from each JSON document. Defining it as a persisted computed column permits indexing that value. An index on severity with LogId, LogDateTime, and log as included columns covers the report, so SQL can use the index for filtering without fetching those columns through key lookups.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!