我有一个SQL Profiler跟踪保存到SQL Server中的表。
我想对跟踪中的查询执行CPU /读取/持续时间的总和/平均/计数分析。但是大多数分析器数据记录使用uniqueidentifer
参数调用存储过程:
EXECUTE GetTransactionCounts @BankGUID = '{231281D7-F6C2-4EAE-98AE-E9196D8016F0}', @SessionGUID='{7F34361F-CEEA-4CEA-8CBD-2704FFE92DEF}'
SELECT SUM(Total) AS Total FROM fn_BalancingAdditionsUS('{C08961DB-0B6A-4E67-A82B-5BBBA0A84A74}')
EXEC CreateCloser '{7F34361F-CEEA-4CEA-8CBD-2704FFE92DEF}', NULL , '{08E74DBB-3BC4-49A7-AA10-95AA6BD24784}'
EXECUTE GetMachineImpressmentForSession @SessionGUID = '{446881BA-1439-4AD8-B33B-C784120EFBA2}'
SELECT SUM(Total) AS Total FROM fn_BalancingAdditionsCanadian('{446881BA-1439-4AD8-B33B-C784120EFBA2}')
SELECT SUM(Total) AS Total FROM fn_BalancingSubtractionsUS('{446881BA-1439-4AD8-B33B-C784120EFBA2}')
因此,当我尝试聚合探查器跟踪数据以查找性能最差的查询时:
SELECT
Description,
COUNT(*) AS EventCount,
AVG(CPU) AS CPU, SUM(CPU) AS CpuTotal,
AVG(Reads) AS Reads, SUM(Reads) AS ReadsTotal,
AVG(Duration) AS Duration, SUM(Duration) AS DurationTotal
FROM SlowQueriesTrace
GROUP BY Description
然后不会发生聚合,因为每个GUID都是唯一的。我需要的是用通用%g
标记替换uniqueidentifier参数的一些方法:
EXECUTE GetTransactionCounts @BankGUID = %g, @SessionGUID=%g
SELECT SUM(Total) AS Total FROM fn_BalancingAdditionsUS(%g)
EXEC CreateCloser %g, NULL , %g
EXECUTE GetMachineImpressmentForSession @SessionGUID = %g
SELECT SUM(Total) AS Total FROM fn_BalancingAdditionsCanadian(%g)
SELECT SUM(Total) AS Total FROM fn_BalancingSubtractionsUS(%g)
然后我的聚合将起作用。
除了将表格导出到Excel并手动编辑所有10,270个事件之外,还可以考虑以任何方式执行GUID搜索&替换SQL Server内部的模式匹配?
我试过的其他黑客:
将description
修剪为前40个字符(即CAST(description AS varchar(40))
):
EXECUTE GetTransactionCounts @BankGUID =
SELECT SUM(Total) AS Total FROM fn_Balan
EXEC CreateCloser '{7F34361F-CEEA-4CEA-8
EXECUTE GetMachineImpressmentForSession
SELECT SUM(Total) AS Total FROM fn_Balan
SELECT SUM(Total) AS Total FROM fn_Balan
除非合并不应合并的项目,否则应合并的其他项目不合并。
使用SoundEx:
E223
S423
E220
E223
S423
除了你可以看到完全不同的线被赋予相同的soundex。此外,我无法确定查询S338
对应的内容。
我最终使用的hack是创建一个新的Category
列,初始为null。然后我花了两个小时精心挑选了LIKE
子句来挑选一个特定的查询,然后用查询“标记”它们。 e.g:
UPDATE QueryTrace
SET Category = 'EXECUTE GetTransactionCounts @BankGUID ='
WHERE Description LIKE 'EXECUTE GetTransactionCounts @BankGUID =%'
和
UPDATE QueryTrace
SET Category = 'SELECT SUM(Total) AS Total FROM fn_BalancingAdditionsCanadian'
WHERE Description LIKE '%FROM fn_BalancingAdditionsCanadian%'
这并不意味着我不需要使用这个问题的解决方案。
答案 0 :(得分:1)
您是否尝试过使用执行某些查询参数化/规范化的ClearTrace?
另一种选择是使用CLR功能:Determining Poorly Performing Queries for Tuning from SQL Server Workload Trace Files
每当您收集工作负载跟踪时 识别性能不佳的查询, 你需要将这些数据导入到 数据库表,并“规范化”和 汇总此信息以进行识别 最严重的罪犯。这可以做到 以各种方式。一种方法是 定义一个正则表达式,如 这个SQL CLR方法基于完成的工作 由Itzik Ben-Gan和Adam修改 Machanic:
[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true)]
public static SqlString sqlsig(SqlString querystring)
{
return (SqlString)Regex.Replace(
querystring.Value,
@"([\s,(=<>!](?![^\]]+[\]]))(?:(?:(?:(?:(?# expression coming
)(?:([N])?(')(?:[^']'')*('))(?# character
)(?:0x[\da-fA-F]*)(?# binary
)(?:[-+]?(?:(?:[\d]*\.[\d]*[\d]+)(?# precise number
)(?:[eE]?[\d]*)))(?# imprecise number
)(?:[~]?[-+]?(?:[\d]+))(?# integer
)(?:[nN][uU][lL][lL])(?# null
))(?:[\s]?[\+\-\*\/\%\&\\^][\s]?)?)+(?# operators
)))",
@"$1$2$3#$4");
}
按OP编辑:我没有听说过ClearTrace。我试过了:
编辑:您是否使用正确的跟踪模板来收集跟踪?