Indexing and Statistics

Designing, evaluating, maintaining, and troubleshooting indexes and statistics.

568 associated posts270 primary posts

Rebuild or Reorganize? How to Set Up Index Maintenance in SQL Server (video)

Index maintenance is confusing. Should you use maintenance plans or customized SQL Agent jobs? Join Kendra to learn the difference between index ‘rebuild’ and ‘reorganize’ commands, and how to avoid the pitfalls of maintenance plans in SQL Server.

https://www.youtube.com/watch?v=6nJKIeJC2lg

Read more about Rebuild or Reorganize? How to Set Up Index Maintenance in SQL Server (video) 8 comments — Join the discussion
Performance Tuning

Should I Run sp_recompile After I Create An Index?

Making index changes in SQL Server is tricky: you immediately want to know if the new index helped your performance and if it's being used, but SQL Server execution plans and their related statistics can be are insanely confusing.

It can be useful to run sp_recompile after you create an index, but not necessarily for the reason you might think.

Read more about Should I Run sp_recompile After I Create An Index? 5 comments — Join the discussion

Generating Identities

The only thing you ever need to use for database identity is an IDENTITY, right? Well, maybe. There are a lot of different options and they all have different pros and cons.
IDENTITY columns
The default way to identify objects in SQL Server is to use an INT or BIGINT column marked as an IDENTITY. This guarantees relatively sequential numbers, barring restarts and failed inserts. Using identity columns put the responsibility for creating and maintaining object identity in the database.

Read more about Generating Identities 21 comments — Join the discussion
Performance Tuning

Comparing Estimated and Actual Execution Plans in SQL Server

Let’s say you want to have an addition built on your house. You contact a contractor, who comes to your house, looks at your lot, looks at what exists, and asks you questions about exactly what you want. He then gives you an estimate of the work – approximately how long he thinks it will take his crew, what supplies will be needed, and the cost of those supplies.

Read more about Comparing Estimated and Actual Execution Plans in SQL Server 17 comments — Join the discussion
Performance Tuning

Stabilizing Execution Plans: Plan Guides and NORECOMPUTE

Sometimes you end up in a good plan / bad plan situation: an important query runs just fine most of the time. The query is parameterized, a good execution plan gets re-used, everything is cool. But sometimes, a "bad plan" gets compiled and starts to be reused. This is "bad" parameter sniffing. "Bad plans" can come in a few…

Read more about Stabilizing Execution Plans: Plan Guides and NORECOMPUTE 16 comments — Join the discussion

4 Lightweight Ways to Tell if a Database is Used

We've all found those databases. They're on your production SQL Server instance, but nobody seems to know if they're being used, or what's using them.

You could run some sort of trace, but you'd probably drag down performance on your SQL Server. What you need is a quicker way to find out if the database is in use.
Is a Login Using the database?
And if so, what query did they run last? My favorite way to see this is with Adam Machanic's sp_whoisactive.

Read more about 4 Lightweight Ways to Tell if a Database is Used 52 comments — Join the discussion

Why Index Fragmentation and Bad Statistics Aren’t Always the Problem (Video)

Do you rely on index rebuilds to make queries run faster? Or do you always feel like statistics are "bad" and are the cause of your query problems? You're not alone-- it's easy to fall into the trap of always blaming fragmentation or statistics. Learn why these two tools aren't the answer to every problem…

Read more about Why Index Fragmentation and Bad Statistics Aren’t Always the Problem (Video) 1 comment — Join the discussion

What happens to in-flight data compression in an emergency?

Data compression can have many uses and advantages, but it also has its drawbacks. It’s definitely not a one-size-fits-all strategy. One of the things to be aware of is that initial compression of a table or index can take quite some time, and will be resource-intensive. It also is an offline operation, so the object…

Read more about What happens to in-flight data compression in an emergency? 10 comments — Join the discussion
Performance Tuning

Are Table Variables as Good as Temporary Tables in SQL 2014?

There's a couple of new features in SQL Server 2014 that provide options for how you work with temporary objects. Will inline index creation or memory optimized temporary tables forever change the way you code? Let's take a look! Inline Index Creation SQL Server 2014 brings us a TSQL improvement called "inline specification of CLUSTERED…

Read more about Are Table Variables as Good as Temporary Tables in SQL 2014? 31 comments — Join the discussion
Performance Tuning

How to Add Nonclustered Indexes to Clustered Columnstore Indexes

SQL Server 2012 introduced nonclustered columnstore indexes, but I never saw them used in the wild simply because once created, they made the underlying table read-only. Not a lot of folks like read-only tables. (Bad news, by the way - that limitation hasn't disappeared in 2014.) SQL Server 2014 brings clustered columnstore indexes, and they're…

Read more about How to Add Nonclustered Indexes to Clustered Columnstore Indexes 15 comments — Join the discussion

How to Use Partitioning to Make kCura Relativity Faster

kCura Relativity is an e-discovery program used by law firms to find evidence quickly. I've blogged about performance tuning Relativity, and today I'm going to go a little deeper to explain why DBAs have to be aware of Relativity database contents.

In Relativity, every workspace (case) lives in its own SQL Server database. That one database houses:

Read more about How to Use Partitioning to Make kCura Relativity Faster 4 comments — Join the discussion