sql server 2005中处理的行统计信息
在 Oracle 中,有一个名为 V$SQLAREA 的视图,它列出了共享 SQL 区域的统计信息,并且每个 SQL 字符串包含一行。它提供内存中、已解析且准备执行的 SQL 语句的统计信息。
有一列 -ROWS_PROCESSED 计算代表此 SQL 语句处理的总行数。
我正在 SQLSERVER 2005 中寻找附带信息。
我查看了一些 DMV(如 sys.dm_exec_query_stats),但没有找到任何相关信息。
@@ROWCOUNT 对我来说没有用,因为我需要增量统计信息来汇总数据库中最高 cpu/io/执行消耗查询的 rows_processed。
我将不胜感激有关该主题的任何帮助。
预先感谢,
罗尼。
我看到当我查询以下查询时,我收到了 XML 格式的查询计划。
在 XML 计划代码中,有一个“EstimateRows”部分,其中的数字与查询的估计行数相关。
我正在考虑选择 substr query_plan 列以仅检索上述信息(除非我在某些系统视图/表中找到它)。
在哪里可以找到查询的实际行数?它存储在哪里?
SELECT
case when sql_handle IS NULL
then ' '
else ( substring(st.text,(statement_start_offset+2)/2,
(case when qs.statement_end_offset = -1
then len(convert(nvarchar(MAX),st.text))*2
else statement_end_offset
end - statement_start_offset) /2 ) )
end as query_text ,
query_plan,
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
cross apply sys.dm_exec_sql_text(sql_handle) st;
In Oracle, there's a view called V$SQLAREA that lists statistics on shared SQL area and contains one row per SQL string. It provides statistics on SQL statements that are in memory, parsed, and ready for execution.
There is one column -ROWS_PROCESSED that sums the Total number of rows processed on behalf of this SQL statement.
I'm looking for collateral information in SQLSERVER 2005.
I looked in some of the DMV's (like sys.dm_exec_query_stats), but I haven't found anything related.
@@ROWCOUNT won't be useful to me, as I want incremental statistics information that will sum the rows_processed of the top cpu/io/execution consumption queries in the database.
I would appreciate any help in regards the subject.
Thanks in advance,
Roni.
I saw that when I query the following query, I receive the Query Plan in XML.
Inside the XML plan code, there's a "EstimateRows" part with a number that correlates to the number of estimation rows of the query.
I'm thinking of the option to substr the query_plan column to retreive only the above information (unless I would find it in some system views/tables).
Where can I find the Actual number of rows of the query ? Where is it stored ?
SELECT
case when sql_handle IS NULL
then ' '
else ( substring(st.text,(statement_start_offset+2)/2,
(case when qs.statement_end_offset = -1
then len(convert(nvarchar(MAX),st.text))*2
else statement_end_offset
end - statement_start_offset) /2 ) )
end as query_text ,
query_plan,
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
cross apply sys.dm_exec_sql_text(sql_handle) st;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,没有直接的等价物,特别是对于行计数。相关的 dmvs 跟踪 IO 成本,用于显示丢失的索引、最昂贵的查询等。
这将为您提供当前会话的每个 SQL 语句的统计信息。 YMMV:我只是根据我现有的脚本将其组合在一起。
我的脚本基于我的链接 这里提到
There isn't a direct equivalent especially for rowcounts as far as I know. The relevant dmvs track IO cost which is used to show missing indexed, most expensive queries etc
This will give you stats per SQL statement for current sessions. YMMV: I've just put it together based on scripts I have lying around.
My scripts are based on the links I mentioned here
您可以使用系统变量@@rowcount来了解最后一条语句影响的记录数。
You can use the system variable @@rowcount to know the number of records affected by last statement.