老师的毕业设计要求通过大量的实验数据来研究数据库读写速度优化的方法。如果我插入一行数据,那么怎样能够知晓这条命令所占用的执行时间呢?
------解决方案--------------------
set statistics time on ;
t-sql
set statistics time off ;
------解决方案--------------------
set statistics time on
会返回如下的信息:
SQL Server 分析和编译时间:
CPU 时间 = 7 毫秒,占用时间 = 7 毫秒。
(259 行受影响)
SQL Server 执行时间:
CPU 时间 = 0 毫秒,占用时间 = 98 毫秒。
也就是一共是98+7 = 106
------解决方案--------------------
研究性的东西,我建议去研究mysql,毕竟开源
------解决方案--------------------
--CPU最高的查询
SELECT TOP 3
total_worker_time ,
execution_count ,
total_worker_time / execution_count AS [Avg CPU Time] ,
CASE WHEN deqs.statement_start_offset = 0
AND deqs.statement_end_offset = -1
THEN '-- see objectText column--'
ELSE '-- query --' + CHAR(13) + CHAR(10)
+ SUBSTRING(execText.text, deqs.statement_start_offset / 2,
( ( CASE WHEN deqs.statement_end_offset = -1
THEN DATALENGTH(execText.text)
ELSE deqs.statement_end_offset
END ) - deqs.statement_start_offset ) / 2)
END AS queryText
FROM sys.dm_exec_query_stats deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.plan_handle) AS execText
--WHERE execText.text like '%指定查询%'
ORDER BY deqs.total_worker_time DESC;
--批级别的查询统计信息
SELECT TOP 100
SUM(total_logical_reads) AS total_logical_reads ,
COUNT(*) AS num_queries , --number of individual queries in batch
--not all usages need be equivalent, in the case of looping
--or branching code
MAX(execution_count) AS execution_count ,
MAX(execText.text) AS queryText
FROM sys.dm_exec_query_stats deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS execText
GROUP BY deqs.sql_handle
HAVING AVG(total_logical_reads / execution_count) <> SUM(total_logical_reads)
/ SUM(execution_count)
ORDER BY 1 DESC
--逻辑读最高
-- Top Cached SPs By Total Logical Reads (SQL 2008 only).
-- Logical reads relate to memory pressure
SELECT TOP ( 25 )
p.name AS [SP Name] ,
deps.total_logical_reads AS [TotalLogicalReads] ,
deps.total_logical_reads / deps.execution_count AS [AvgLogicalReads] ,
deps.execution_count ,
ISNULL(deps.execution_count / DATEDIFF(Second, deps.cached_time,
GETDATE()), 0) AS [Calls/Second] ,