Category: Indexing

Performance Tuning

Free Webcast: Fixing Parameter Sniffing with Index Tuning

When a query is sometimes fast and sometimes slow, there are a lot of ways you can reduce the effects of parameter sniffing. We're always going to have parameter sniffing in SQL Server and Azure SQL DB - it's just the way the product is built - but there are a lot of options to reduce the blast radius.

Read more about Free Webcast: Fixing Parameter Sniffing with Index Tuning 4 comments — Join the discussion

Logical Reads Aren’t Repeatable on Columnstore Indexes. (sigh)

Sometimes I really hate my job. Forever now, FOREVER, it's been a standard thing where I can say, "When you're measuring storage performance during index and query tuning, you should always use logical reads, not physical reads, because logical reads are repeatable, and physical reads aren't. Physical reads can change based on what's in cache,…

Read more about Logical Reads Aren’t Repeatable on Columnstore Indexes. (sigh) 12 comments — Join the discussion
Performance Tuning

How to Query JSON Data Quickly in SQL Server, Part 1: Pre-2025

Before SQL Server 2025, if you want to store JSON data in Microsoft SQL Server or Azure SQL DB, and you want fast queries, the easiest way is to:

Store the data in an NVARCHAR(MAX) column (because the native JSON datatype didn't arrive until SQL Server 2025)
Add a computed column for the specific JSON keys we'll want to query quickly
Index those keys
Query it using the JSON_VALUE function

Read more about How to Query JSON Data Quickly in SQL Server, Part 1: Pre-2025 12 comments — Join the discussion

Index Rebuilds Make Even Less Sense with ADR & RCSI.

Accelerated Database Recovery (ADR) is a database-level feature that makes transaction rollbacks nearly instantaneous. Here's how it works.

Without ADR, when you update a row, SQL Server copies the old values into the transaction log and updates the row in-place. If you roll that transaction back, SQL Server has to fetch the old values from the transaction log, then apply them to the row in-place. The more rows you've affected, the longer your transaction will take.

Read more about Index Rebuilds Make Even Less Sense with ADR & RCSI. 6 comments — Join the discussion
Performance Tuning

What’s Faster: IN or OR? Columnstore Edition

Pinal Dave recently ignited a storm of controversy when he quizzed readers about which one of these would be faster on AdventureWorks2019:
[crayon-6a5aae669509f449365293/]
I laughed so hard when I saw the storm of responses on Twitter. People sure do get passionate about this kind of thing. If you ever wanna witness patience and generosity in action, look at Pinal's responses to this tweet.

Read more about What’s Faster: IN or OR? Columnstore Edition 19 comments — Join the discussion

Columnstore Indexes are Finally Sorted in SQL Server 2022.

There's a widespread misconception that SQL Server's columnstore indexes are like an index on every column.

I debunk that myth in the first 30 minutes of my Fundamentals of Columnstore class, where I explain that a better way to think of them is that your table is broken up into groups of rows (1M rows or less per group), and in each group, there's an index on every column.

Read more about Columnstore Indexes are Finally Sorted in SQL Server 2022. 23 comments — Join the discussion
Performance Tuning

When Should You Use DESC in Indexes?

The short answer is that if your query orders columns by a mix of ascending and descending order, back to back, then the index usually needs to match that same alternating order. Now, for the long answer. When you create indexes, you can either create them in ascending order - which is the default: [crayon-6a5aae6695e3c695001462/] Or…

Read more about When Should You Use DESC in Indexes? 8 comments — Join the discussion
Performance Tuning

Stop Procrastinating: Master Index Tuning in 1 Month for $195.

You've conquered my Fundamentals of Index Tuning and Fundamentals of Columnstore classes, and you're ready to take it to the next level.

It's time for you to join my Mastering Index Tuning class. When I teach it live - the next one is July 19-21 - it's 3 days of lectures and hands-on labs where you learn:

Read more about Stop Procrastinating: Master Index Tuning in 1 Month for $195. 3 comments — Join the discussion

Lock Escalation Sucks on Columnstore Indexes.

If you've got a regular rowstore table and you need to modify thousands of rows, you can use the fast ordered delete technique to delete rows in batches without hitting the lock escalation threshold. That's great for rowstore indexes, but...columnstore indexes are different.

To demo this technique, I'm going to use the setup from my Fundamentals of Columnstore class:

Read more about Lock Escalation Sucks on Columnstore Indexes. 1 comment — Join the discussion