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

More Free Training

SQL Server, T-SQL
Quest Connect 2009, taking place in October 21 for 24 hours, looks like it's going to have 64 different sessions, live and recorded, by a variety of the names in the industry. It's another chance to dig in and learn the details on a variety of topics from some of the top names in the business. Can you say Tom LaRock? How about Tim Ford? I know you want to hear from Brent Ozar. Those are just some of the featured speakers. There are a whole slew of others, it's worth pursuing, and did I mention, the price is right. I recorded a session for them last night. It's on the basics of understanding execution plans.
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

Spools in Execution Plans

SQL Server, T-SQL
I got the question the other day, when are you likely to see a spool in an execution plan? Easy, whenever SQL Server needs to walk through the data multiple times, usually in JOIN operations... Yeah, well, once again, my flip answers are not quite the entire story. Spool operations are temporary storage of the data for later reuse in a query plan. There are two types of spool operations, eager spool and lazy spool. A spool is basically a temporary table created within the execution of the query that is used when it's likely that data will be needed again, and again during the execution of the query. This is not an explicit #temp temporary table, but a work table for operations within the processing necessary for a given query's…
Read More

24 Hours of PASS

PASS, SQL Server, T-SQL
This was a pretty cool event. The advertising leading up to it seemed to really cover the community very well. There was even a link to 24 Hours of PASS in my team's local web site. Unfortunately, I'm not an iron man like Tom LaRock, watching all 24 hours. I only hit a few sessions. The first session I hit was Allen White's PowerShell for SQL Server. I have attended a couple of  his presentations at the PASS Summit. I think he's done a great job of gleaning better and better examples out of his presentations. This one was good. I loved the way he put together the backup processes for automating backups. It looked good, took into account common issues, it just worked. I was really happy I got…
Read More

What happens when you use WITH RECOMPILE

SQL Server, T-SQL
I saw this question and my immediate thought was "Well, duh, the execution plan is recreated by a recompile." But, someone a bit smarter than myself suggested that, in fact, no plan was stored in cache, forcing a new plan to be created each time the query was run. So, which is it? Does a plan get added to cache and then removed every time the procedure is called, or do you get nothing in cache and the "recompile" is actually a compile every time? As Mr. Owl says, let's find out. I have a small script that looks like this: CREATE TABLE [dbo].[Test]( [col] [varchar] (10) NULL ); CREATE TABLE [dbo].[Test2] ( [col] VARCHAR(10) NULL ); INSERT INTO dbo.Test (col) VALUES ('Val1'), ('Val2'),   ('Val3') ; INSERT INTO dbo.Test2…
Read More

Two Book Recommendations

PowerShell, SQL Server
I have two new books that I can heartily recommend. This isn't a review of either book since I've only just started reading them. However, I've used each to solve a couple of small problems within a day of having them on the shelf. To me, that proves their worth. First up is Michael Coles new book "Pro SQL Server 2008 XML." I'm still a bit jittery with XQuery... OK, I have a hard time writing XQuery and I have to look up how to do every step and I still get things wrong. Anyway... There are two entire chapters devoted to how to use XQuery and an appendix with an XQuery & XPath reference. Great stuff. Look for an extended review several weeks from now after I've had a chance to…
Read More

Excellent Blog List

SQL Server, T-SQL
For the one or two you that are not reading Buck Woody's blog (and why aren't you), you may not have seen that he's posted a recommended reading list of the blogs that he reads on a regular basis. This list must be reviewed by you, now. Go on, I'll wait here till you get back.
Read More

SQL Quiz 5: SANs Mirroring

SQL Server
My turn to answer Chris Shaw's questions "Do I feel I have a reliable SAN solution?" and "Describe Database Mirroring for the layman?" Thanks Tim. I've a feeling you're going to be disappointed. SAN: Hell, how should I know? Want to talk about a black box? Our SAN, as far as I'm aware, is run by a group of crack-shot ninja assassins and powered by pureed virgin unicorn. This strange mix of esoteric skill, magic and blood is evidently able to provide us with just about perfect up time. Once, one of the ninja's must have gone rogue (speculation) and had to be put down by his brother ninjas because we had a drive disappear on the cluster server. It took us a couple of hours, but it recovered as if it…
Read More