Launch week: the Season Pass & Fundamentals Week are 50% off — ends in 7d 16h 21mSee the sale

T-SQL & Development

[Video] How to Find Queries Using OPTION RECOMPILE (And Their Parameters)

For years, I hated troubleshooting servers with high CPU usage caused by queries constantly asking for new execution plans. Hated it. SQL Server just doesn’t make it easy to find queries with recompile hints.

Then Erik Darling’s sp_HumanEvents came along.

And now troubleshooting frequent compilations is as easy as this:

Which produces this:

ARE YOU KIDDING ME? It gives me the parameters, the number of times the query compiled, how much time was spent doing those compilations, and more! It’s a SINGLE LINE OF T-SQL that sets up an Extended Events session, waits, tears it back down, and then lays out the output in a ridiculously easy-to-consume format!

Or, say you’re facing frequent re-compilations due to stats changes in high-turnover tables. No problem:

Here, I’m running a workload that causes a stats update in the middle of the workload, which triggers a recompile of a normally stable stored procedure:

It doesn’t get any easier than that. These are by no means the only tricks up sp_HumanEvents’ sleeve, either: it has all kinds of parameters to help you track down issues that would usually involve a lot of work.

If you prefer moving pictures with audio gibberish, here’s a live stream of me setting up the demo for this blog post:

Live Coding T-SQL with Microsoft SQL Server

Enjoyed this session? Follow me on TwitchYouTube, or Facebook to be alerted whenever I’m streaming. Here’s the code I used with the Stack Overflow database in the live session:

 

Free, 3× a week

Get my new posts by email

Three posts a week, plus a Monday roundup of the best database news from around the web.

1 comment

  1. Brent, You live in Iceland now? No wonder my DBA skills have diminished! The Ozar Aura can only travel 2400 miles. + it is so dangerous there!! Iceland may be spectacular with beauty but is a MOVING VOLACANO. Y I u and Erika, please be safe.

Leave a comment

Your email address will not be published. Required fields are marked *

Email me about new comments: