Execution Plan Cost Estimates

SQL Server, T-SQL
It's been emphasized over and over that the costs of operations within an execution plan, and the estimated costs of the plan themselves are, in fact, estimates. But it goes further than that. The estimated values are based on statistics, or the lack thereof. Statistics themselves are also estimates. This means that the costs you're seeing are extrapolations based on extrapolations. So, you should just ignore those values and move on, right? Wrong. In order to understand how the optimizer is choosing to put together an execution plan for your query so that you can use that understanding to then make intelligent choices as to modifying the query or the structure of your database, you must use the values you have at hand. However, you must also understand where and…
Read More

sp_executesql, Parameters and Parameter Sniffing

SQL Server, T-SQL
I'm honestly not crazy about dynamic T-SQL within stored procedures. There are just a few too many opportunities to mess it up with dire circumstances to your server and your data. However, I absolutely recognize that dynamic T-SQL may be needed, and, in some situations, the best way to solve a problem. If you must use dynamic T-SQL, there are ways that are much more efficient than others. The very best thing you can do if you need to build dynamic strings to execute T-SQL in your stored procedures is use sp_executesql. The main reason I advocate for sp_executesql is because you can build out completely dynamic strings of T-SQL, but, you can still take advantage of parameters. Parameters help you avoid a chat with the parents of Bobby Tables…
Read More

Learn Query Tuning in Dallas

SQL Server, T-SQL
I am excited to be able to tell you about an all day seminar that I'll be putting on prior to the Dallas SQL Saturday #255. The seminar will be on November 1, 2013. It's called Query Performance Tuning in SQL Server. We're going to cover the topic from an understanding of the optimizer to collecting data using extended events to reading execution plans and then on to lots of standard problems and their solutions. If you sign up before September 21st you can get a substantial early-bird discount, so I'd jump on it. Also, seats are limited, so don't wait too long. Let's get together and talk query tuning.
Read More

Be Cautious Offering Guidance

Azure, SQL Server, T-SQL
Guidance is hard. Seriously, you'd think it would be easy. You'd think you say things like, don't shrink your database, most tables should have a clustered index, never go against a Sicilian when death is on the line, don't mix sharks and tornados, and that would be it. You'd be done. But it's not that easy. Even worse, it's SHOCKINGLY easy to get stuff wrong. An example. I was looking at information over at Microsoft Developers Network (MSDN) in the SQL Server Books Online. I was reading through information about wait types when I found this little beauty: Occurs when trying to synchronize the query processor exchange iterator. Know what that is? Yeah, OK, a few of you who memorize wait stats do (shut up Tom), but most of us…
Read More

Helping Database Administrators

Redgate Software, SQL Server
Let's be honest. Database administration is not all that tough. Set up your backups. Test them. Get consistency checks on line. Some maintenance routines for statistics and maybe for fragmentation are also helpful. Set up security. In most of the important ways, you're done. Sit back, monitor the whole thing and collect your paycheck. BWA-HA-HA! Yeah, well, it's a nice dream. The reality is that you're dealing with constant change that throw this simple set of maintenance monitoring tasks into the garbage. No, you've got new databases under development. Sometimes by development teams that are absolute rocket scientists and you sit at their feet learning how they did some really cool piece of code. And sometimes by development teams that more resemble crazed monkeys throwing poo at the walls to…
Read More

SQLBits Public Sessions

SQL Server
If you're over in the UK, or close to it, you've probably heard of SQL Bits even if you haven't attended. If you're across the pond here in the US or somewhere else you may have heard of SQL Bits, but few of you have gone. Well, let me tell you, from everything I've heard, this is a community event you want to find your way to. So, I'm trying. This is my first time submitting to this outstanding event and I really want to go. But, in order to make the cut, I need your help. They base who presents on community feedback. This means you go over and vote. You'll have to have a SQL Bits login, but if you're even thinking about attending you're going to have…
Read More

Sharing the Love

SQL Server, T-SQL
Just a few blog posts that you ought to go and read. First up, Tom LaRock maintains a listing of SQL bloggers split up into various cleverly named groups to show you where to go to get good information. This really is an excellent collection of bloggers. It's the people I go to when I need information. Some of them are better resources than the Books Online when they post something. Personally, I've made the list for the last several years, but Tom has decided that I'm worth of elevation, so I've gone from the Model database to the Master database. Thanks Tom. One blog that's not on Tom's list is Tom's blog. You should be reading that regularly too. And congratulations to Tom again on making MCM. Next, one…
Read More

Clustered Indexes Have Statistics Too

SQL Server, T-SQL
It may seem obvious, but I've heard more than one person suggest to me that statistics on a clustered index just don't matter. That if the clustered index can satisfy a given query, it's going to get selected. That just didn't make any sense to me, but I haven't seen anyone set up a test that shows how it might work one way or the other. Here you go. First, I'm going to create a table and load it up with data. I'm intentionally using strings because I don't want to confuse the ease of management of integers within indexes. I also went for one column that would have a very attractive set of statistics and one that would have a very ugly set. Also, because we're only dealing with…
Read More

Interviewing a DBA

PASS, SQL Server, T-SQL
I'm not a fan of trivia style interview questions. Yes, I ask a few because you have to in order to immediately eliminate the completely unqualified applicants. Even those types of questions, in my opinion, need to be focused on concepts and not syntax. The reason we have the Books Online with SQL Server is because you shouldn't have to memorize every possible command along with all their parameters. Want to know how to write a MERGE query? Look it up. What does a MERGE query do? That you ought to know. I think concepts are important. Questions about the recovery models within SQL Server aren't trivia about the system, they're trying to get to your understanding of how point in time recovery works. I don't really like posting interview…
Read More

SQL Server vs. Oracle

PASS, Redgate Software, SQL Server, T-SQL
Just so we're clear, I use SQL Server. I like SQL Server. But, this doesn't mean I have anything against Oracle. It's fine. It's good. But, I know very little about it. However, throughout my career I've found myself needing to understand it better. Either because I'm trying to train Oracle people to better use SQL Server and I need to be able to speak a little of their language to facilitate translation. Or, because I'm defending SQL Server on some technical point that the Oracle people don't completely understand. Or, because I've said something stupid about Oracle in my ignorance. Now, you know how busy you are, and I know how busy I am, so I doubt either of us has the time we really need to learn Oracle…
Read More