Edit

Share via


Use query labels in Fabric Data Warehouse

Applies to: ✅ SQL analytics endpoint and Warehouse in Microsoft Fabric

Query labels provide a mechanism for locating queries in query insights views or source control.

Tip

Good naming conventions are helpful. For example, starting the label with PROJECT, PROCEDURE, STATEMENT, or COMMENT helps identify queries among the many in your warehouse.

LABEL syntax

SELECT ...
FROM ...
OPTION (LABEL = '<label text>');

Examples

Note

Completed queries can take up to 15 minutes to appear in query insights views depending on the concurrent workload being executed.

A. Track important query performance in Query Insights

Place a unique label in a high-cost query you want to track the performance of over time.

SELECT FinanceKey, DateKey, OrganizationKey, DepartmentGroupKey, SUM(AMOUNT)
FROM dbo.FactFinance
WHERE OrganizationKey = 123
AND DepartmentGroupKey = 123
GROUP BY FinanceKey, DateKey, OrganizationKey, DepartmentGroupKey
OPTION (LABEL = 'SALES DASHBOARD');

You can then find the performance of that query in Query insights views, for example:

SELECT * 
FROM 
    queryinsights.long_running_queries
WHERE 
    last_run_command LIKE '%SALES DASHBOARD%'
ORDER BY 
    median_total_elapsed_time_ms DESC;
SELECT *
FROM 
    queryinsights.exec_requests_history 
WHERE 
    label IN ('SALES DASHBOARD')
ORDER BY 
    submit_time DESC;

B. Track query performance of multiple labels

You can review and compare multiple query labels, for example:

SELECT *
FROM 
    queryinsights.exec_requests_history 
WHERE 
    label IN ('Regular','Clustered')
ORDER BY 
    submit_time DESC;