Posts by Erik Darling

Filtered Indexes: Just Add Includes

I found a quirky thing recently While playing with filtered indexes, I noticed something odd. By ‘playing with’ I mean ‘calling them horrible names’ and ‘admiring the way other platforms implemented them‘. I sort of wrote about a similar topic in discussing indexing for windowing functions. It turns out that a recent annoyance could also…
Read More

Window Functions and Cruel Defaults

SQL Server, T-SQL
5 Comments
My First Post Here… Well, my first technical post, was about how the default index creation method is OFFLINE. If you want that sweet, sweet Enterpri$e Edition ONLINE goodness, you need to specify it. It’s been a while since that one; almost six months to the day. So here’s another one! But Window Functions Are…
Read More

Performance Benefits of Unique Indexes

SQL Server
29 Comments
SQL server loves unique indexes Why? Because it’s lazy. Just like you. If you had to spend all day flipping pages around, you’d probably be even lazier. Thank Codd someone figured out how to make a computer do it. There’s some code below, along with some screen shots, but… TL;DR SQL is generally pretty happy…
Read More

Logical Query Processing Follow-up

SQL Server
0
i like questions! Because I don’t always like talking to myself, and robots are sometimes murderous and insane. So when this one came up in the comments of my previous post, I thought it would make a good follow-up blog. It’s a really good question, and definitely one I found myself asking quite a bit…
Read More

Finding Tables with Nonclustered Primary Keys and no Clustered Index

Indexing, SQL Server
31 Comments
i’ve seen this happen Especially if you’ve just inherited a database, or started using a vendor application. This can also be the result of inexperienced developers having free reign over index design. Unless you’re running regular health checks on your indexes with something like our sp_BlitzIndex® tool, you might not catch immediately that you have…
Read More

Logical Query Processing

You can’t do that on management studio Recently, while working with a client, I did something in a query that they were mystified by. I didn’t think much of it, but I thought it might be useful to you, dear readers, as well. Along with an explanation. Here’s a sample query that takes advantage of…
Read More

The sp_rename follies

SQL Server
28 Comments
Before we get started… I know. I know. BOL. It’s documented. They even show you how to rename a table. Thanks, sp_rename! But sometimes… You just forget. And as with most simple mistakes, fixing them is… Weird. Here’s what happened to me recently, when I was working on a table swapping demo. Transact-SQL CREATE TABLE…
Read More

Indexing for GROUP BY

Indexing, SQL Server
9 Comments
It’s not glamorous And on your list of things that aren’t going fast enough, it’s probably pretty low. But you can get some pretty dramatic gains from indexes that cover columns you’re performing aggregations on. We’ll take a quick walk down demo lane in a moment, using the Stack Overflow database. Query outta nowhere! Transact-SQL…
Read More

Indexing for Windowing Functions

Indexing, SQL Server, T-SQL
6 Comments
Hooray Windowing Functions They do stuff that used to be hard to do, or took weird self-joins or correlated sub-queries with triangular joins to accomplish. That’s when there’s a standalone inequality predicate, usually for getting a running total. With Windowing Functions, a lot of the code complexity and inefficiency is taken out of the picture,…
Read More

Forcing Join Order Without Hints

SQL Server
18 Comments
Brent buys lunch for the ladies The purpose of this post is to show a bit of syntax that often gets overlooked in favor of using query hints to force joins to occur in a particular order. We’ll start by creating three tables. One for employees, one for orders, and one for items in the…
Read More