Find SQL statements with high CPU usage

Source: Internet
Author: User
Tags high cpu usage

Recently, we have been dealing with database data transmission problems. The data transmitted every day is about 40 w-50w. SQL services often occupy 1.7 GB of CPU memory. Fortunately, the data servers are 8-16 cores. I found an element code on the Internet to test the database's performance and record:

Select top 10 rank () over (order by (total_worker_time + 0.0)/execution_count DESC, SQL _handle, statement_start_offset) as row_no, (rank ()
Over (order by (total_worker_time + 0.0)/execution_count DESC, SQL _handle, statement_start_offset) % 2 as L1, creation_time, last_execution_time,
(Total_worker_time + 0.0)/1000 as total_worker_time, (total_worker_time + 0.0)/(execution_count * 1000) as [avgcputime],
Total_logical_reads as [logicalreads], total_logical_writes as [logicalwrites], execution_count, total_logical_reads + total_logical_writes as [aggio],
(Total_logical_reads + total_logical_writes)/(execution_count + 0.0) as [avgio], case when SQL _handle is null then ''else (substring (St. Text,
(Qs. statement_start_offset + 2)/2, (case when Qs. statement_end_offset =-1 then Len (convert (nvarchar (max), st. Text ))
* 2 else Qs. statement_end_offset end-Qs. statement_start_offset)/2) end as query_text, db_name (St. dbid) as db_name, st. objectid as object_id
From SYS. dm_exec_query_stats QS cross apply SYS. dm_exec_ SQL _text (SQL _handle) ST
Where total_worker_time> 0
Order by [avgcputime] DESC

Author: lifuyun
Source: http://lifuyun.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.