I’m a Pain

Uncategorized
Or maybe I'm misreading that I'm supposed to be helping to alleviate pain. Either way, next Thursday, June 17, I'll be taking part in the Quest Pain of the Week webcast: Easy Ways to Fix Hard SQL Server Problems - Without a Guru. It should be a lot of fun. Please stop by and ask hard questions.
Read More

T-SQL Tuesday #1: Date/Time Tricks

SQL Server, T-SQL
I'm going to try out Adam Machanic's idea for a blog party. The topic this month are Date/Time tricks. Instead of supplying a trick for Date/Time, I'm going to caution you about the tricks that you use. Let's take a simple issue. You want to pull back data from a table, let's use the Production.TransactionHistoryArchive in AdventureWorks2008, for a given month of data. Before we run the query, let's create an index on the table: CREATE INDEX ixTest ON Production.TransactionHistoryArchive (TransactionDate) The query itself is pretty simple. This is one mechanism that will retrieve the data for the month of July in 2003: SELECT tha.TransactionID FROM Production.TransactionHistoryArchive AS tha WHERE DATEPART(yy,tha.TransactionDate) = 2003 AND DATEPART(mm,tha.TransactionDate) = 7 In theory you should be able to use the index that was created earlier,…
Read More

SQL Server XQuery For Idiots

SQL Server, T-SQL
I'm still struggling with learning XQuery. My latest little revelation was small, but vital. The difference between: @inXML.nodes('/rss/channel/item') and @inXML.nodes('/rss[1]/channel[1]/item') Is the difference between a 10 minute query and a 4 second query. Kind of shocking really. My understanding is that XQuery assumes there are multiple possible paths that look like "/rss/channel" so it searches over and over again through the XML to see if it can find them. But by identifying it as a root, showing that only one possible path is available, it stops stumbling around in the dark and simply reads the data. It's a little thing, but it made an enormous difference. I've still got a long way to go in learning how to use XPath within XQuery. UPDATED: I modified the title so that it's…
Read More

Gila Monster on Estimated vs. Actual Row Counts

SQL Server, T-SQL
I don't generally do lots of blog aggregation and cross post linking & stuff. It's just not something I'm that into. However, this time is an exception. Gail Shaw, Gila Monster to those who hang on out SQL Server Central, has posted an excellent explanation of times when Estimated and Actual row counts vary for a reason. I'm one of those who emphasises that differences between estimated & actual is an indication of... something. It could be out of date or missing statistics or it could be caused by query language like multi-statement table valued functions, but it's usually and indication of a problem. Except when it's not. Read Gail's explanation for more.
Read More

Identifying Frequently Running Queries

SQL Server, T-SQL
It's not enough to look at the longest running query. What if you have two queries, one runs for 5 minutes and the other runs for 5 seconds. Which do you tune? The first one, of course. But, let's add a little information to our thought experiment. The one that runs for 5 minutes is called 2AM, your local time, when there are almost no users on the system and the one that runs for 5 seconds is called 40 times a minute all day long. Now, which one do you tune? That's right, suddenly that 5 second query takes on a HUGE significance based on how often it's called. But how do you know how often a query is called? The easiest way to gather that information is not…
Read More

No Join Predicate

SQL Server, T-SQL
You could be looking at an execution plan on a query and see this message: Warning, No Join Predicate. With a very few exceptions (very few), that's not a warning, like "Mind the gap" or "Your Mileage May Vary" or "Never fight a land war in Asia." No. It's a screaming shout saying "BY ALL THE GODS IN VALHALA, YOU DON'T HAVE ANY JOIN PREDICATES IN THIS QUERY!" Seriously, that's exactly what it says. But, you might be asking yourself, that's what it says, but what does it mean? Please allow me to explain. The tables in your system, whether it's a classic BI star schema, or a highly normalized OLTP system, or even (shudder) ORM objects, are related to one another. Usually they're related through the use of primary…
Read More

LaRock on Monitoring

SQL Server, T-SQL
Since I just spent a bit more than half of my 24 Hours of PASS presentation on tuning queries talking about monitoring performance, you could probably tell that I think that the two are inextricably linked. I'm not alone. Tom LaRock has put a post on why it's important to understand the extent of your problem prior to attempting to fix it. It's absolutely spot-on and a must read. Remember, if someone says performance on a system you manage is slow, you have to ask, as compared to what? You need to understand what "normal" performance is on your system in order to arrive at the ability to identify a particular process as performing in an abnormal manner. That's not to say that you couldn't tune a query in complete…
Read More

Debuting: Beginning SQL Server 2008 Administration

Uncategorized
The new book is up on Amazon. I only worked on three chapters of Rob Walter's new book and that was after begging to only work on two, so I can't take much credit for the effort that went into this book. However, thanks to our editor Jonathan Gennick, I was privileged to work with Rob & Carmen, if pretty indirectly. I know I mentioned the book before when it was put up on the Apress web site, but this is Amazon. Once it's up on Amazon, it's real.
Read More

No really. When did this statement start?

SQL Server
I thought I had an interesting answer to the question. Unfortunately Adam Machanic, who has been working in this specific area quite a bit longer than I have, and, let's face it, is a bit smarter, pointed out (in the comments) the possibility that I didn't have this quite right. I ran all his tests and sure enough, it wasn't working the same way that I saw it work. First, I tried modifying his query so that it ran the SELECT statements from the DMV's between the operations, but this didn't change the results, start_time and last_request_start_time were the same. From a scientific stand-point, if no one can replicate your results, the experiment failed. So I went back and tried again. To be sure I got things right and wasn't, somehow,…
Read More

MS Field Engineer’s on Performance Troubleshooting

SQL Server, T-SQL
Do you want to get a glimpse into how the Microsoft Field Engineers would go about troubleshooting performance issues on your server? Then go and read this blog entry by Denzil Ribeiro. Not only is this an excellent how-to on troubleshooting performance problems, but Mr. Ribeiro provides multiple links that describe the concepts he's dealing with further, making it a great piece of documentation. The MS Field Engineer blog is not terribly active, but what gets posted there is worth reading. If you don't have it on your feed list, you should.
Read More