Query-Tuning

Category: query-tuning

A Case of Inconsistent Wait Stats and Query Duration

A Case of Inconsistent Wait Stats and Query Duration

You know how they say “don’t sweat the small stuff”?

That’s good advice for lots of things, but when it comes to query tuning - I WANT TO KNOW MORE when something is inconsistent. I just can’t let it go. I go total X-Files: The Truth Is Out There.

Continue reading

Auto-Tuning: Automatic Plan Correction is Cleared on Restart

Auto-Tuning: Automatic Plan Correction is Cleared on Restart

The new Enterprise Automatic Tuning feature in SQL Server 2017 may sound intimidating at first – one question I get a lot lately is whether or not there’s a future for DBAs. Will Auto-Tune mean we don’t need any more human tuning?

Well, not anytime super soon.

Continue reading

The Case of MAX() Requiring an Index Scan, While TOP(1)/ORDER BY  DESC Does Not

The Case of MAX() Requiring an Index Scan, While TOP(1)/ORDER BY DESC Does Not

By Kendra Little on March 14, 2018

Most of the time in SQL Server, the MAX() function and a TOP(1) ORDER BY DESC will behave very similarly.

If you give them a rowstore index leading on the column in question, they’re generally smart enough to go to the correct end of the index, and – BOOP! – just pluck out the data you need without doing a big scan.

Continue reading

What is a Morally Equivalent Execution Plan, and Why Is It Useful?

What is a Morally Equivalent Execution Plan, and Why Is It Useful?

on March 12, 2018

I recently wrote a fairly complicated post, called “Forced Plan Confusion: Is_Forced vs Use Plan = True.”

You do NOT need to go read that post to understand this one. I think I’ve found simpler way to explain theΒ most important part of that post - and why it’s A Very Good Thing.

Continue reading

sp_query_store_flush_db, Query Store, and Backups

sp_query_store_flush_db, Query Store, and Backups

on August 23, 2017

One of the cool things about Query Store is that you can back it up with the database.

This isn’t perfect for every situation, because you must back up the whole database. If you’ve got a multi-terabyte database, your Query Store isn’t super portable! But still, it’s great to have an option.

Continue reading

IF Statement Branching and Parameter Sniffing

IF Statement Branching and Parameter Sniffing

on July 12, 2017

It can be tricky to remember that SQL Server doesn’t short circuit on IF statements in stored procedures. Even when you know this, sometimes it’s hard to recognize the impacts.

Continue reading

Removing Query Hints with Plan Guides (Dear SQL DBA Episode 43)

Removing Query Hints with Plan Guides (Dear SQL DBA Episode 43)

If you need to add, remove, or replace hints from ad-hoc queries where you can’t change the code, plan guides can help. See a demo of removing a query hint from parameterized TSQL run from an application, and get tips on how to make your plan guides work in SQL Server.

Continue reading