Tell me your secrets

2024-01-30 22:48
文章标签 secrets tell

本文主要是介绍Tell me your secrets,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

请复制粘贴然后F5,经典无须多说!

复制代码
/*******************************************************************************************************SQL SERVER 2005 - Tell me your secrets!********************************************************************************************************Description: Report on the current performance health status of a SQL Server 2005 server using non-instrusive methods.Purpose: Identify areas where the database server as a whole can be improved, using data collected by SQL Server itself. Many of these items apply to the database server as a whole, rather than specific queries. Author: Ian Stirk (Ian_Stirk@yahoo.com).Date: June 2007.Notes: This collection of SQL inspects various DMVs, this information can be used to highlightwhat areas of the SQL Server sever can be improved. The following items are reported on:1. Causes of the server waits2. Databases using the most IO3. Count of missing indexes, by database4. Most important missing indexes5. Unused Indexes6. Most costly indexes (high maintenance)7. Most used indexes8. Most fragmented indexes9. Most costly queries, by average IO10. Most costly queries, by average CPU11. Most costly CLR queries, by average CLR time12. Most executed queries13. Queries suffering most from blocking14. Queries with the lowest plan reuse********************************************************************************************************PRE-REQUISITE
1. Best to have as much DMV data as possible (When last rebooted? Want daily? weekly, monthly, quarterly results).
2. Output HSR to Grid? Text? File? Table? Reporting Services? If set results to text, get the actual sprocs in output.
3. Decide if want to put results in a database? Later analysis, historical comparisons, impact of month-end, quarter etc. 
4. Decide if want to run the defrag code, can be expensive.
5. Decide if want to iterate over all databases for a specific aspect (e.g. average IO).FOLLOW-UP (After running this routine's SQL)
1. Investigative work, use dba_SearchDB/dba_SearchDBServer for analysis.
2. Demonstrate/measure the improvement: Find underlying queries, apply change, run stats IO ON, see execuation plan.
3. SQL Server Best Practices Analyzer.INTRUSIVE INSPECTION (Follow-up and corollary to this work)
1. Trace typical workload (day, monthend? etc)
2. Reduce recorded queries to query signatures (Ben-Gan's method)
3. Calculate the total duration for similar query patterns
4. Tune the most important query patterns in DTA, then apply recommended indexes/stats.*********************************************************************************************************/-- Do not lock anything, and do not get held up by any locks. 
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTEDSELECT 'Identify what is causing the waits.' AS [Step01];
/************************************************************************************/
/* STEP01.                                                                            */
/* Purpose: Identify what is causing the waits.                                        */
/* Notes: 1.                                                                        */
/************************************************************************************/
SELECT TOP 10[Wait type] = wait_type,[Wait time (s)] = wait_time_ms / 1000,[% waiting] = CONVERT(DECIMAL(12,2), wait_time_ms * 100.0 / SUM(wait_time_ms) OVER())
FROM sys.dm_os_wait_stats
WHERE wait_type NOT LIKE '%SLEEP%' 
--AND wait_type NOT LIKE 'CLR_%'
ORDER BY wait_time_ms DESC;SELECT 'Identify what databases are reading the most logical pages.' AS [Step02a];
/************************************************************************************/
/* STEP02a.                                                                            */
/* Purpose: Identify what databases are reading the most logical pages.                */
/* Notes : 1. This should highlight the databases to target for best improvement.    */
/*           2. Watch out for tempDB, a high value is suggestive.                        */    
/************************************************************************************/
-- Total reads by DB
SELECT TOP 10 [Total Reads] = SUM(total_logical_reads),[Execution count] = SUM(qs.execution_count),DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
GROUP BY DB_NAME(qt.dbid)
ORDER BY [Total Reads] DESC;SELECT 'Identify what databases are writing the most logical pages.' AS [Step02b];
/************************************************************************************/
/* STEP02b.                                                                            */
/* Purpose: Identify what databases are writing the most logical pages.                */
/* Notes : 1. This should highlight the databases to target for best improvement.    */
/*           2. Watch out for tempDB, a high value is suggestive.                        */    
/************************************************************************************/
-- Total Writes by DB
SELECT TOP 10 [Total Writes] = SUM(total_logical_writes),[Execution count] = SUM(qs.execution_count),DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
GROUP BY DB_NAME(qt.dbid)
ORDER BY [Total Writes] DESC;SELECT 'Count of missing indexes, by databases.' AS [Step03];
/************************************************************************** ******************/
/* STEP03.                                                                            */
/* Purpose: Identify the number of missing (or incomplete indexes), across ALL databases.     */
/* Notes : 1. This should highlight the databases to target for best improvement.             */
/*********************************************************************************************/
SELECT DatabaseName = DB_NAME(database_id),[Number Indexes Missing] = count(*) 
FROM sys.dm_db_missing_index_details
GROUP BY DB_NAME(database_id)
ORDER BY 2 DESC;SELECT 'Identify the missing indexes (TOP 10), across ALL databases.' AS [Step04];
/****************************************************************************************************/
/* STEP04.                                                                            */
/* Purpose: Identify the missing (or incomplete indexes) (TOP 20), for ALL databases.                */
/* Notes : 1. Could combine above with number of reads/writes a DB has since reboot, but this takes */
/*           into account how often index could have been used, and estimates a 'realcost'            */
/****************************************************************************************************/
SELECT  TOP 10 [Total Cost]  = ROUND(avg_total_user_cost * avg_user_impact * (user_seeks + user_scans),0) , avg_user_impact -- Query cost would reduce by this amount, on average., TableName = statement, [EqualityUsage] = equality_columns , [InequalityUsage] = inequality_columns, [Include Cloumns] = included_columns
FROM        sys.dm_db_missing_index_groups g 
INNER JOIN    sys.dm_db_missing_index_group_stats s ON s.group_handle = g.index_group_handle 
INNER JOIN    sys.dm_db_missing_index_details d ON d.index_handle = g.index_handle
ORDER BY [Total Cost] DESC;SELECT 'Identify which indexes are not being used, across ALL databases.' AS [Step05];
/*******************************************************************************************************/
/* STEP05.                                                                            */
/* Purpose: Identify which indexes are not being used, for a given database.                            */
/* Notes: 1. These will have a deterimental impact on any updates/deletions.                            */
/*          Remove if possible (can see the updates in user_updates and system_updates fields)            */
/*          2. Systems means DBCC commands, DDL commands, or update statistics - so can typically ignore.    */
/*          3. The template below uses the sp_MSForEachDB, this is because joining on sys.databases        */
/*            gives incorrect results (due to sys.indexes taking into account the current database only).    */     
/********************************************************************************************************/
-- Create required table structure only.
-- Note: this SQL must be the same as in the Database loop given in following step.
SELECT TOP 1DatabaseName = DB_NAME(),TableName = OBJECT_NAME(s.[object_id]),IndexName = i.name,user_updates    ,system_updates    -- Useful fields below:--, *
INTO #TempUnusedIndexes
FROM   sys.dm_db_index_usage_stats s 
INNER JOIN sys.indexes i ON  s.[object_id] = i.[object_id] AND s.index_id = i.index_id 
WHERE  s.database_id = DB_ID()AND OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0AND    user_seeks = 0AND user_scans = 0 AND user_lookups = 0-- Below may not be needed, they tend to reflect creation of stats, backups etc...
--    AND    system_seeks = 0
--    AND system_scans = 0
--    AND system_lookups = 0AND s.[object_id] = -999  -- Dummy value, just to get table structure.
;-- Loop around all the databases on the server.
EXEC sp_MSForEachDB    'USE [?]; 
-- Table already exists.
INSERT INTO #TempUnusedIndexes 
SELECT TOP 10    DatabaseName = DB_NAME(),TableName = OBJECT_NAME(s.[object_id]),IndexName = i.name,user_updates    ,system_updates    -- Useful fields below:--, *
FROM   sys.dm_db_index_usage_stats s 
INNER JOIN sys.indexes i ON  s.[object_id] = i.[object_id] AND s.index_id = i.index_id 
WHERE  s.database_id = DB_ID()AND OBJECTPROPERTY(s.[object_id], ''IsMsShipped'') = 0AND    user_seeks = 0AND user_scans = 0 AND user_lookups = 0AND i.name IS NOT NULL    -- I.e. Ignore HEAP indexes.-- Below may not be needed, they tend to reflect creation of stats, backups etc...
--    AND    system_seeks = 0
--    AND system_scans = 0
--    AND system_lookups = 0
ORDER BY user_updates DESC
;
'-- Select records.
SELECT TOP 10 *  FROM #TempUnusedIndexes ORDER BY [user_updates]  DESC
-- Tidy up.
DROP TABLE #TempUnusedIndexesSELECT 'Identify which indexes are the most high maintenance (TOP 10), across ALL databases.' AS [Step06];
/********************************************************************************************************/
/* STEP06.                                                                            */
/* Purpose: Identify which indexes are the most high maintenance (TOP 10), for a given database.        */
/* Notes: 1. These indexes are updated the most, may want to review if the are necessary.                */
/*        2. Another version shows writes per read.                                                          */
/*          3. Systems means DBCC commands, DDL commands, or update statistics - so can typically ignore. */
/*          4. The template below uses the sp_MSForEachDB, this is because joining on sys.databases        */
/*            gives incorrect results (due to sys.indexes taking into account the current database only).    */     
/********************************************************************************************************/
-- Create required table structure only.
-- Note: this SQL must be the same as in the Database loop given in following step.
SELECT TOP 1[Maintenance cost]  = (user_updates + system_updates),[Retrieval usage] = (user_seeks + user_scans + user_lookups),DatabaseName = DB_NAME(),TableName = OBJECT_NAME(s.[object_id]),IndexName = i.name-- Useful fields below:
--        ,user_updates  
--        ,system_updates
--        ,user_seeks 
--        ,user_scans 
--        ,user_lookups 
--        ,system_seeks 
--        ,system_scans 
--        ,system_lookups -- Useful fields below:
--        ,*
INTO #TempMaintenanceCost
FROM   sys.dm_db_index_usage_stats s 
INNER JOIN sys.indexes i ON  s.[object_id] = i.[object_id] AND s.index_id = i.index_id
WHERE s.database_id = DB_ID() AND OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0AND (user_updates + system_updates) > 0 -- Only report on active rows.AND s.[object_id] = -999  -- Dummy value, just to get table structure.
;-- Loop around all the databases on the server.
EXEC sp_MSForEachDB    'USE [?]; 
-- Table already exists.
INSERT INTO #TempMaintenanceCost 
SELECT TOP 10[Maintenance cost]  = (user_updates + system_updates),[Retrieval usage] = (user_seeks + user_scans + user_lookups),DatabaseName = DB_NAME(),TableName = OBJECT_NAME(s.[object_id]),IndexName = i.name-- Useful fields below:
--        ,user_updates  
--        ,system_updates
--        ,user_seeks 
--        ,user_scans 
--        ,user_lookups 
--        ,system_seeks 
--        ,system_scans 
--        ,system_lookups -- Useful fields below:
--        ,*
FROM   sys.dm_db_index_usage_stats s 
INNER JOIN sys.indexes i ON  s.[object_id] = i.[object_id] AND s.index_id = i.index_id
WHERE s.database_id = DB_ID() AND i.name IS NOT NULL    -- I.e. Ignore HEAP indexes.AND OBJECTPROPERTY(s.[object_id], ''IsMsShipped'') = 0AND (user_updates + system_updates) > 0 -- Only report on active rows.
ORDER BY [Maintenance cost]  DESC
;
'-- Select records.
SELECT TOP 10 *  FROM #TempMaintenanceCost ORDER BY [Maintenance cost]  DESC
-- Tidy up.
DROP TABLE #TempMaintenanceCostSELECT 'Identify which indexes are the most often used (TOP 10), across ALL databases.' AS [Step07];
/********************************************************************************************************/
/* STEP07.                                                                            */
/* Purpose: Identify which indexes are the most used (TOP 10), for a given database.                     */
/* Notes: 1. These indexes are updated the most, may want to review if the are necessary.                   */
/*          2. Systems means DBCC commands, DDL commands, or update statistics - so can typically ignore. */
/*          3. Ensure Statistics are up-to-date for these.                                                 */
/*          4. The template below uses the sp_MSForEachDB, this is because joining on sys.databases        */
/*            gives incorrect results (due to sys.indexes taking into account the current database only).    */     
/********************************************************************************************************/-- Create required table structure only.
-- Note: this SQL must be the same as in the Database loop given in following step.
SELECT TOP 1[Usage] = (user_seeks + user_scans + user_lookups),DatabaseName = DB_NAME(),TableName = OBJECT_NAME(s.[object_id]),IndexName = i.name-- Useful fields below:
--        ,user_updates  
--        ,system_updates
--        ,user_seeks 
--        ,user_scans 
--        ,user_lookups 
--        ,system_seeks 
--        ,system_scans 
--        ,system_lookups -- Useful fields below:--, *
INTO #TempUsage
FROM   sys.dm_db_index_usage_stats s 
INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id] AND s.index_id = i.index_id 
WHERE   s.database_id = DB_ID() AND OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0AND (user_seeks + user_scans + user_lookups) > 0 -- Only report on active rows.AND s.[object_id] = -999  -- Dummy value, just to get table structure.
;-- Loop around all the databases on the server.
EXEC sp_MSForEachDB    'USE [?]; 
-- Table already exists.
INSERT INTO #TempUsage 
SELECT TOP 10[Usage] = (user_seeks + user_scans + user_lookups),DatabaseName = DB_NAME(),TableName = OBJECT_NAME(s.[object_id]),IndexName = i.name-- Useful fields below:
--        ,user_updates  
--        ,system_updates
--        ,user_seeks 
--        ,user_scans 
--        ,user_lookups 
--        ,system_seeks 
--        ,system_scans 
--        ,system_lookups -- Useful fields below:--, *
FROM   sys.dm_db_index_usage_stats s 
INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id] AND s.index_id = i.index_id 
WHERE   s.database_id = DB_ID() AND i.name IS NOT NULL    -- I.e. Ignore HEAP indexes.AND OBJECTPROPERTY(s.[object_id], ''IsMsShipped'') = 0AND (user_seeks + user_scans + user_lookups) > 0 -- Only report on active rows.
ORDER BY [Usage]  DESC
;
'-- Select records.
SELECT TOP 10 * FROM #TempUsage ORDER BY [Usage] DESC
-- Tidy up.
DROP TABLE #TempUsageSELECT 'Identify which indexes are the most logically fragmented (TOP 10), across ALL databases.' AS [Step08];
/********************************************************************************************/
/* STEP08.                                                                            */
/* Purpose: Identify which indexes are the most fragmented (TOP 10), for a given database.  */
/* Notes: 1. Defragmentation increases IO.                                                    */
/********************************************************************************************/
---- Create required table structure only.
---- Note: this SQL must be the same as in the Database loop given in following step.
--SELECT TOP 1 
--        DatbaseName = DB_NAME()
--        ,TableName = OBJECT_NAME(s.[object_id])
--        ,IndexName = i.name
--        ,[Fragmentation %] = ROUND(avg_fragmentation_in_percent,2)
--        -- Useful fields below:
--        --, *
--INTO #TempFragmentation
--FROM sys.dm_db_index_physical_stats(db_id(),null, null, null, null) s
--INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id] 
--    AND s.index_id = i.index_id 
--WHERE s.[object_id] = -999  -- Dummy value, just to get table structure.
--;
--
---- Loop around all the databases on the server.
--EXEC sp_MSForEachDB    'USE [?]; 
---- Table already exists.
--INSERT INTO #TempFragmentation 
--SELECT TOP 10
--        DatbaseName = DB_NAME()
--        ,TableName = OBJECT_NAME(s.[object_id])
--        ,IndexName = i.name
--        ,[Fragmentation %] = ROUND(avg_fragmentation_in_percent,2)
--        -- Useful fields below:
--        --, *
--FROM sys.dm_db_index_physical_stats(db_id(),null, null, null, null) s
--INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id] 
--    AND s.index_id = i.index_id 
--WHERE s.database_id = DB_ID() 
--      AND i.name IS NOT NULL    -- I.e. Ignore HEAP indexes.
--    AND OBJECTPROPERTY(s.[object_id], ''IsMsShipped'') = 0
--ORDER BY [Fragmentation %] DESC
--;
--'
--
---- Select records.
--SELECT TOP 10 * FROM #TempFragmentation ORDER BY [Fragmentation %] DESC
---- Tidy up.
--DROP TABLE #TempFragmentationSELECT 'Identify which (cached plan) queries are the most costly by average IO (TOP 10), across ALL databases.' AS [Step09];
/****************************************************************************************************/
/* STEP09.                                                                            */
/* Purpose: Identify which queries are the most costly by IO (TOP 10), across ALL databases.        */
/* Notes: 1. This could be areas that need optimisation, maybe they crosstab with missing indexes?  */
/*          2. Decide if average or total is more important.                                            */
/****************************************************************************************************/
SELECT TOP 10 [Average IO] = (total_logical_reads + total_logical_writes) / qs.execution_count,[Total IO] = (total_logical_reads + total_logical_writes),[Execution count] = qs.execution_count,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) ,[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
--WHERE DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY [Average IO] DESC;SELECT 'Identify which (cached plan) queries are the most costly by average CPU (TOP 10), across ALL databases.' AS [Step10];
/****************************************************************************************************/
/* STEP10.                                                                            */
/* Purpose: Identify which queries are the most costly by CPU (TOP 10), across ALL databases.        */
/* Notes: 1. This could be areas that need optimisation, maybe they crosstab with missing indexes?  */
/*          2. Decide if average or total is more important.                            */
/****************************************************************************************************/
SELECT TOP 10 [Average CPU used] = total_worker_time / qs.execution_count,[Total CPU used] = total_worker_time,[Execution count] = qs.execution_count,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2),[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
--WHERE DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY [Average CPU used] DESC;SELECT 'Identify which CLR queries, use the most average CLR time (TOP 10), across ALL databases.' AS [Step11];
/****************************************************************************************************/
/* STEP011.                                                                            */
/* Purpose: Identify which CLR queries, use the most avg CLR time (TOP 10), across ALL databases.   */
/* Notes: 1. Decide if average or total is more important.                                            */
/****************************************************************************************************/
SELECT TOP 10 [Average CLR Time] = total_clr_time / execution_count ,[Total CLR Time] = total_clr_time ,[Execution count] = qs.execution_count,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2),[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid)-- Useful fields below:--, *
FROM sys.dm_exec_query_stats as qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
WHERE total_clr_time <> 0
--AND DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY [Average CLR Time] DESC;SELECT 'Identify which (cached plan) queries are executed most often (TOP 10), across ALL databases.' AS [Step12];
/********************************************************************************************/
/* STEP12.                                                                            */
/* Purpose: Identify which queries are executed most often (TOP 10), across ALL databases.  */
/* Notes: 1. These should be optimised. Ensure Statistics are up to date.                    */
/********************************************************************************************/
SELECT TOP 10 [Execution count] = execution_count,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2),[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
--AND DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY [Execution count] DESC;SELECT 'Identify which (cached plan) queries suffer the most from blocking (TOP 10), across ALL databases.' AS [Step13];
/****************************************************************************************************/
/* STEP13.                                                                            */
/* Purpose: Identify which queries suffer the most from blocking (TOP 10), across ALL databases.    */
/* Notes: 1. This may have an impact on ALL queries.                                                */
/*          2. Decide if average or total is more important.                                            */
/****************************************************************************************************/
SELECT TOP 10 [Average Time Blocked] = (total_elapsed_time - total_worker_time) / qs.execution_count,[Total Time Blocked] = total_elapsed_time - total_worker_time ,[Execution count] = qs.execution_count,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) ,[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
--AND DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY [Average Time Blocked] DESC;SELECT 'What (cached plan) queries have the lowest plan reuse (Top 10), across ALL databases.' AS [Step14];
/************************************************************************************/
/* STEP14.                                                                            */
/* What queries, in the current database, have the lowest plan reuse (Top 10).        */
/* Notes: 1.                                                                          */
/************************************************************************************/
SELECT TOP 10[Plan usage] = cp.usecounts,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2),[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid),cp.cacheobjtype-- Useful fields below:--, *
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
INNER JOIN sys.dm_exec_cached_plans as cp on qs.plan_handle=cp.plan_handle
WHERE cp.plan_handle=qs.plan_handle
--AND DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY [Plan usage] ASC;-- MIGHT BE USEFUL
/*/* ALTERNATIVE. */
SELECT 'Identify what indexes have a high maintenance cost.' AS [Step];
/* Purpose: Identify what indexes have a high maintenance cost. */
/* Notes : 1. This version shows writes per read, another version shows total updates without reads. */
SELECT     TOP 10DatabaseName = DB_NAME(),TableName = OBJECT_NAME(s.[object_id]),IndexName = i.name,[Writes per read (User)] = user_updates / CASE WHEN (user_seeks + user_scans + user_lookups) = 0 THEN 1 ELSE (user_seeks + user_scans + user_lookups) END ,[User writes] = user_updates,[User reads] = user_seeks + user_scans + user_lookups,[System writes] = system_updates,[System reads] = system_seeks + system_scans + system_lookups-- Useful fields below:--, *
FROM   sys.dm_db_index_usage_stats s , sys.indexes i 
WHERE   s.[object_id] = i.[object_id] AND s.index_id = i.index_id AND s.database_id = DB_ID()AND OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0
ORDER BY [Writes per read (User)] DESC;-- Total Reads by most expensive IO query
SELECT TOP 10 [Total Reads] = total_logical_reads,[Total Writes] = total_logical_writes,[Execution count] = qs.execution_count,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) ,[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
ORDER BY [Total Reads] DESC;-- Total Writes by most expensive IO query
SELECT TOP 10 [Total Writes] = total_logical_writes,[Total Reads] = total_logical_reads,[Execution count] = qs.execution_count,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2),[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid)
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
ORDER BY [Total Writes] DESC;-- Most reused queries...
SELECT TOP 10 [Run count] = usecounts,[Query] = text,DatabaseName = DB_NAME(qt.dbid),*
FROM sys.dm_exec_cached_plans cp
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) as qt
--AND DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY 1 DESC;-- The below does not give the same values as previosu step, maybe related to 
-- individual qry within the parent qry? 
SELECT TOP 10 [Run count] = usecounts,[Individual Query] = SUBSTRING (qt.text,qs.statement_start_offset/2, (CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2),[Parent Query] = qt.text,DatabaseName = DB_NAME(qt.dbid),*
FROM sys.dm_exec_cached_plans cp
INNER JOIN sys.dm_exec_query_stats qs ON cp.plan_handle = qs.plan_handle
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) as qt
--AND DB_NAME(qt.dbid) = 'pnl'  -- Filter on a given database.
ORDER BY 1 DESC;*/
复制代码


引用连接:http://msdn.microsoft.com/en-us/magazine/cc135978.aspx?pr=blog

这篇关于Tell me your secrets的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/661792

相关文章

Show,Attend and Tell: Neural Image Caption Generation with Visual Attention

简单的翻译阅读了一下 Abstract 受机器翻译和对象检测领域最新工作的启发,我们引入了一种基于注意力的模型,该模型可以自动学习描述图像的内容。我们描述了如何使用标准的反向传播技术,以确定性的方式训练模型,并通过最大化变分下界随机地训练模型。我们还通过可视化展示了模型如何能够自动学习将注视固定在显着对象上,同时在输出序列中生成相应的单词。我们通过三个基准数据集(Flickr9k,Flickr

解决git提交报错please tell me who you are

今天提交项目突然提示报错: unable to auto-detect email address:无法自动检测电子邮件地址 需要手动配置一下自己的邮件地址   1.《全局配置》可根据提示配置: git config --global user.eamil "xxxxx@XXXX.com"git config --global user.name "xxxxx" 2.《单独项目配

【云原生】Kubernetes----配置资源管理Secrets与ConfigMaps

目录 一、Secrets (一)Secrets概述 (二)Secrets类型 (三)Secrets使用方式 (四)创建Secrets 1.陈述式命令创建 1.1 定义用户与密码文件 1.2 使用陈述式命令创建 2.使用base64创建 2.1 获取加密信息 2.2 使用yaml文件创建 (五)使用Secrets 1.使用挂载的方式 2.使用环境变量的方式 (六)Sec

Git 相关问题: Please tell me who you are.

换了台电脑,提交代码的时候git出现了一个问题(我是直接将.ssh文件考到了相对的位置): 然后: 最终可以commit。 然后提交代码的时候又来了… 然后我就直接按照提示来了 git config --global push.default matchinggit config --global push.default simple 相关的修改也提交上去了 上网

Python入门文件之: seek()和tell()函数

Python open() 函数打开文件并读取文件中的内容时,总是会从文件的第一个字符(字节)开始读起。 那么,有没有办法可以自定指定读取的起始位置呢? 实现对文件指针的移动,文件对象提供了 tell() 函数和 seek() 函数。tell() 函数用于判断文件指针当前所处的位置,而 seek() 函数用于移动文件指针到文件的指定位置。 各个参数的含义如下: file:表

6.k8s中的secrets资源

一、Secret secrets资源,类似于configmap资源,只是secrets资源是用来传递重要的信息的; secret资源就是将value的值使用base64编译后传输,当pod引用secret后,k8s会自动将其base64的编码,反编译回正常的字符串; Secret 用于保存机密数据的对象。一般由于保存密码、令牌或密钥等。 data字段用来存储 base64 编码数据。

6.k8s中的secrets资源-初识secret

目录 一、Secret 二、创建secrets资源 1.创建工作目录 2.尝试使用base64进行编码  3.声明式创建secrets资源 4.响应式创建secret 三、pod引用secret资源 1.pod资源env环境变量引用 2.pod资源volume存储卷引用secret资源  3.pod资源清单指定key引用secret 四、secret类型之-私有镜像仓库使

Behind Closed Doors : Secrets of Great Management (Pragmatic Programmers)

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp Great management is difficult to see as it occurs. It's possible to see the results of great management

Secrets of RSS (Visual QuickStart Guide)

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp Whether you want to create your own RSS feeds or just would like to locate and add them to your Web sit

The Art of ClearCase(R) Deployment: The Secrets to Successful Implementation

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp By using IBM Rational ClearCase, development teams can dramatically improve their productivity and resp