The CASE Statement and Performance

SQL Server, T-SQL
In case you don't know, this query: UPDATE dbo.Test1 SET C2 = 2 WHERE C1 LIKE '%33%'; Will run quite a bit slower than this query: UPDATE dbo.Test1 SET C2 = 1 WHERE C1 LIKE '333%'; Or this one: UPDATE dbo.Test1 SET C2 = 1 WHERE C1 = '333'; That's because the second two queries have arguments in the filter criteria that allow SQL Server to use the statistics in an index to look for specific matching values and then use the balanced tree, B-Tree, of the index to retrieve specific rows. The argument in the first query requires a full scan against the index because there is no way to know what values might match or any path through the index to simply retrieve them. But, what if we…
Read More

SQL Server 2014 and the New Cardinality Estimator

Uncategorized
Cardinality, basically the number of rows being processed by an operation with the optimizer, is a calculation predicated on the statistics available for the columns in question. The statistics used are generally either the values from the histogram or the density. Prior to SQL Server 2014, and going all the way back to SQL Server 7.0 (in the Dark Ages when we had to walk uphill to our cubicles through 15 feet of snow battling Oracle DBAs and Fenris the whole way), there's been one cardinality estimator (although you can modify the behavior somewhat with a traceflag in 2008R2 and 2012). Not any more. There's a possibility for really complex, edge-case queries, that you may run into a regression from this. You control whether or not you get the new…
Read More

Speaker of the Month, February 2014

Professional Development
I didn't get out to many events in January, so I was somewhat limited in the pool of presenters that I could choose from. Luckily for me, that pool primarily consisted of the entire Caribbean since I was on the SQL Cruise. There I got to see some of the best in the business doing serious teaching (and networking, and water slides, and rum, and beaches, and rum). I could easily cop out, cheat, and name the Cruise as speaker of the month, but I have not yet sunk that low (plus, the rum is gone). Every speaker I saw was great too. Tim Ford doesn't let just anyone present in his watery venue. So, I could pick from any of them and be 100% right. But, I had to…
Read More

Thank You!

Azure, PASS
I am humbled and honored (and more than a little horrified) to be on this list of the Best of PASS Summit 2013. I mean look at those names. Every single one is a person I look up to and respect and learn from constantly. How I made a list like this... well, thanks. I appreciate the support and kindness that was shown at the PASS Summit when you filled out your evals. Oh, and while I realize intellectually and SQL skill-wise he totally kicks my behind... Neener, neener Conor. You're in the DBA track and I'm the only one in the top 10 in the Cloud track. By the gods, I'm going to pay for that, but it'll be worth it.
Read More

Book Review: The Phoenix Project

DevOps, Professional Development
Let's get this straight right up front, the thought of reading a novel that's about IT is so repellent, so repugnant, just so horribly wrong, that it's kind of hard to fathom why I would even attempt it. What's even more difficult for me to fathom is how much I enjoyed this book. Which is a novel. About IT. I can't figure it out. Maybe I need to start reading more IT novels... no. Let's hope that's not actually a thing. On with the review... The Phoenix Project is a story about a mid-level manager in a large company who has been running part of the IT organization that is a bit of a backwater, maintaining old big-iron systems, VAX, that type of thing. He gets called into the CEOs…
Read More

Time for a Quick Rant

Professional Development, SQL Server
This is an actual quote from what we can only assume is a functional human being: The database is very big so we stopped taking backup's. Eight lords a leaping are you kidding me? Seriously! Seriously? By the Great Gu and all the Valkyries in Valhalla, you stopped taking backups of your PRODUCTION database because it was "very big." And I'll put down Brobdingnagian stacks of cash that "very big" in this case is probably 200-500gb or at worst 1-2tb. People, assuming you have enough brain stem intact to regulate breathing, you must know, you must by all the sparkly vampires in Twighlight KNOW that you need to have backups. Right? I mean, nothing ever goes wrong on this shiny marble we call Dirt, does it? No one would EVER…
Read More

Database in Source Control

SQL Server, Tools
Many years ago, I was working with a great DBA. Seriously, a very smart and capable guy. He told me, "We need to put the database into source control, just like app code." And I just laughed. Not because I disagreed with him. I knew he was right, but I had tried, several times, to do just that. See, I'm not really a DBA. I'm a developer. I knew that code (and all the T-SQL that describes databases is code) needed to be versioned, sourced, tracked and audited. But great googly moogly, it was not an easy thing to do. I first tried just exporting the entire database into a script and then occasionally checking that script into source control. Yay! Mission Accomplished... Well, I had a database in source…
Read More

Sausage Making

Professional Development
For those who don't know, I work for Red Gate Software. I'm not a developer, but I work directly for the development teams so I spend a lot of time with them. This week I'm over in the UK, where they are headquartered, meeting with the different teams and discussing our products, their future, issues with them, enhancements, and all the rest. Suffice to say, I'm excited by the future. But the really fun bits are when you see behind the scenes stuff. Red Gate is pretty well known for polished, intelligent, elegant UI design (yes, they keep me away from that stuff). Behind those pretty pictures though is code. And our developers are just like your developers, smart, capable, skilled, but still learning. And it's those learning bits that…
Read More

Speaker of the Month, January 2014

Professional Development
A whole new year. Cool. I was at SQL Saturday DC, #233, at the beginning of December. I sat through several really good presentations. I could honestly give the award this month to any of the ones I took notes on, but I have to pick one person (although, not always, my award, my rules). So, speaker of the month for the brand new year is Konstantin Melamud (li|t). Yet another speaker without a blog. Maybe I should enforce my own rules at some at some point. <sigh> Anyway, I enjoyed Konstantin's presentation. Let's talk about it. Performance Tuning - Index Optimization was an excellent presentation. Konstantin came at the topic very carefully. He started off with a knowledge level baseline, right at the start. I thought that was a…
Read More