0

我们针对托管实例数据库启用了 Azure SQL 分析。

“错误/阻塞/超时/死锁”图表按时间显示计数视图,然后在下面列出问题,例如

按时间显示的错误计数图表

如果您单击一个条目,您将看到一个详细视图,例如

错误详情

该消息不提供其他上下文,例如正在查询的表。我无法将此错误追溯到引发此错误的实际查询。没有提供查询哈希以允许在查询计划缓存中找到它。由于这是一个通用错误,因此在尝试查找错误代码时它的价值很小。

有没有人有 Kusto-fu 来提供查询,我可以针对分析日志运行以获取更多上下文,或者 T-SQL 查询来查找在给定日期和时间运行的查询?

编辑:我找到了原始日志条目,但所有查询哈希值都是 -1

在此处输入图像描述

4

1 回答 1

0

There is a few ways that you can possibly track this down. First i would start with this query running in the master database for the server:

SELECT * FROM sys.event_log WHERE severity=2

This will show you errors, and hopefully yours shows up there. After getting an idea of what database is having this error, assuming you didnt already know, you can then go to that database's query store and search for statements run at the same time as your error. Query store can be found in the object explorer in SSMS but that only gives you the out of the box options. Here is a query you can play around with to assist in your rearch - note you will need to change the where clause in the bottom portion.

IF OBJECT_ID('tempdb..#compiledValue') IS NOT NULL
    DROP TABLE #compiledValue;

SELECT q.object_id
    ,pp.name
    ,p.query_plan AS QryPlan
    ,CAST(p.query_plan AS XML) query_plan
    ,q.last_execution_time
    ,t.query_sql_text
    ,TRY_CONVERT(XML, SUBSTRING(p.query_plan, CHARINDEX('<ParameterList>', p.query_plan), CHARINDEX('</ParameterList>', p.query_plan) + LEN('</ParameterList>') - CHARINDEX('<ParameterList>', p.query_plan))) AS Parameters
INTO #compiledvalue
FROM sys.query_store_plan AS p
INNER JOIN sys.query_store_query AS q ON p.query_id = q.query_id
INNER JOIN sys.query_store_query_text AS t ON q.last_compile_batch_sql_handle = t.statement_sql_handle
INNER JOIN sys.procedures pp ON q.object_id = pp.object_id;

SELECT object_id
    ,name
    ,query_plan
    ,last_execution_time
    ,query_sql_text
    ,pc.compiled.value('@Column', 'nvarchar(128)') AS Parameterlist
    ,pc.compiled.value('@ParameterCompiledValue', 'nvarchar(128)') AS [compiled Value]
FROM #compiledValue cvalue
OUTER APPLY cvalue.parameters.nodes('//ParameterList/ColumnReference') AS pc(compiled)
WHERE pc.compiled.value('@Column', 'nvarchar(128)') IS NOT NULL
    AND pc.compiled.value('@ParameterCompiledValue', 'nvarchar(128)') <> 'NULL'
    --QryPlan LIKE '%Table Scan%'

This isnt meant to be a full answer, but too long to be a comment.

于 2021-10-20T15:46:46.173 回答