Indexing

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: SELECT * FROM Sales.SalesOrderHeader WHERE CustomerID IN (1, 2, 3); SELECT * FROM Sales.SalesOrderHeader WHERE CustomerID = 1 OR CustomerID = 2 OR CustomerID = 3; 123456789 SELECT *FROM Sales.SalesOrderHeaderWHERE CustomerID IN (1,…
Read More

When Should You Use DESC in Indexes?

Indexing
8 Comments
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: CREATE INDEX…
Read More

New Year’s Resolution: Lose Weight in Your Database

Indexing
14 Comments
Made a New Year’s resolution to lose weight this year? Forget taking it off your waistline – take it off your database instead with: sp_BlitzIndex @GetAllDatabases = 1, @Mode = 2, @SortOrder = ‘size’ Or: sp_BlitzIndex @GetAllDatabases = 1, @Mode = 2, @SortOrder = ‘rows’ This produces an inventory of all the indexes sorted by…
Read More
Fundamentals of Columnstore

Lock Escalation Sucks on Columnstore Indexes.

Columnstore Indexes
1 Comment
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…
Read More

Learn Fundamentals of Index Tuning for $1.

Indexing
28 Comments
You’re lazy and overconfident. You’ve been reading this blog for a while, and you’ve been telling yourself, “Yeah, I’m pretty good at this database thing. I’ve got years of experience under my belt. I know the fundamentals.” You’ve told yourself, “Yeah, someday I’ll get to Brent’s How to Think Like the Engine class,” but…you’ve never…
Read More
And it looks bad even in shades.

Free Webcast: Help! My SQL Server Maintenance is Taking Too Long!

“Time for a smoke break.” You manage growing SQL Server databases with shrinking nightly maintenance windows. You just don’t have enough time left each night to do the necessary backups, corruption checking, index maintenance, and data jobs that your users and apps want to run. Cloud storage isn’t helping the problem, either. Stop playing Tetris…
Read More

When Do I Need to Use DESC in Indexes?

Indexing
4 Comments
If I take the Users table from any Stack Overflow database, put an index on Reputation, and write a query to find the top 100 users sorted by reputation, descending: CREATE INDEX Reputation ON dbo.Users (Reputation); SELECT TOP 100 * FROM dbo.Users ORDER BY Reputation DESC; 12345 CREATE INDEX Reputation ON dbo.Users (Reputation); SELECT TOP 100…
Read More