BorderLayoutBoxedLayoutOpenLayoutMaximum textMedium textSmall text


Register
Thursday, November 20, 2008

SQL Server News & Information

tsql, performance tuning, industry trends, & bad jokes

exec spSubscribeMinimize
Print  
sp_help 'jmassie'Minimize

This site is maintained by Jason Massie. He has 10 years experience as a DBA and has specialized in performance tuning for the last five. He was recognized by Microsoft as a SQL Server MVP. Jason has spoken at the Professional Association of SQL Server Conference, the North Texas SQL Server Users Group, SQL Connections and TechED. He has worked at Terremark (formerly Data Return) for nearly a decade.

You can contact him at jason@statisticsio.com or 469.569.5965

Jason has the following certifications:
  • Microsoft Certified IT Professional Database Administrator (early adopter)
  • Microsoft Certified IT Professional Database Developer
  • MCDBA (7.0 and 2000)
  • MCSE
  • MCSD
Print  
tblTagCloudMinimize

Abstracts addition Affinity Aggregation allocation Always Analysis Announced another API Appending article Authentication backup be Behavior between Bootstrapper Breaking Build Cache Caching Check checksums Codeplex collection Connecting contest Controller Creating CTEs CTP CUBE cursors Data Database DATALENGTH Debugging Design Diagnosing Diagnostic Differences Documentation DTS Emergency enhancement Entity ETW Exchange execution Express Extensions Fall February Filestream Filtered group GROUPING have Hosting Idle impact Improvement Increase Index Indexes Inserts Instances Interoperability Introduction IO large Late LOB local Localized Magazine Maintaining Maintenance Management maps March Microsoft minutes missing Mix Never November Offline OLE Online operations operators optimizations Optimized Overlapping Package Page Paging Panacea parallel part Partial Partition partitioned Partitioning PASS Performance PFS plan Plans Practices problem Problems Procedure Program programmatically Programming Protection Queries query read recent Recursive Related released Reports Restore return ROLLUP ROWCOUNT Runtime Security Select Sequence sequential Server Services set SETS Shooting shorts sizes Solutions Sortable SPARSE Spool SQL SQLIOSim SSIS Stalled Star Statement Statements stats Stored strategy Stuck Studio Submission Subreports Suggested Summarizing system Table Tables Tampa Task Than there through Timeouts Total Traces Transaction transfer Tricks Trouble TSQL turning understand Understanding undocumented Unique unused upgrade Upgrading Useful Value variables VDI Vista Will Windows Wireless

Print  

Query Hashes in SQL 2008 RC0

Posted by Jason on Tuesday, June 10, 2008 to SQL Server 2008, SQL performance tuning, DMVs, RC0
210 Views | 0 Comments | Article Rating

I believe this is a new feature RC0. If I missed it before, shame on me because this is awesome. My first 2 blog posts(Part 1 and Part 2) were on doing a similar things with query patterns. It is basically an additional column on sys.dm_exec_requests and sys.dm_exec_query_stats that hold a binary hash. The hash is same for queries that are the same or similar. For example, these queries should all have the same hash(disregard parameterization and trivial plans for simplicity):

select c1 from t1 where c2 = 1

select c1 from t1 where c2 = 1

select c1 from t1 where c2 = 2

But this query will have a different hash:

select c1 from t1 where c2 > 1

This allows you to group and aggregate similar queries by the hash. It is really useful in OLTP environments where the same query might only take milliseconds but execute 1000's of times a second. If you don't aggregate, those those types of queries may not show up on the radar but might be responsible 90% of the CPU usage. Shaving a couple of cycles of CPU off of one of those and server-wide utilization drops.

Here is a nice sample from BOL.

 

   1:SELECT TOP 5 query_stats.query_hash AS "Query Hash", 
   2:SUM(query_stats.total_worker_time) / SUM(query_stats.execution_count) AS "Avg CPU Time",
   3:MIN(query_stats.statement_text) AS "Statement Text"
   4:FROM 
   5:    (SELECT QS.*, 
   6:SUBSTRING(ST.text, (QS.statement_start_offset/2) + 1,
   7:    ((CASE statement_end_offset 
   8:WHEN -1 THEN DATALENGTH(st.text)
   9:ELSE QS.statement_end_offset END 
  10:            - QS.statement_start_offset)/2) + 1) AS statement_text
  11:FROM sys.dm_exec_query_stats AS QS
  12:CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) as ST) as query_stats
  13:GROUP BY query_stats.query_hash
  14:ORDER BY 2 DESC;
  15:GO

email it! |   |   |   |  | 
Permalink     0 Comments  

Rate this Post:
COMMENTS:

Name (required)

Email (required)

Website


Simple BBCode can be used like [URL]...[/URL] and [B]

Copyright 2006 by Statistics IO, My SQL Server Blog