fun with stored procedures

I had some fun today optimizing a stored procedure. It was taking about 10 minutes to run, and I got it down to running in two seconds with a pretty minor change.

Without getting into too many gory details, it was basically doing a somewhat complicated PIVOT. It was using a SUM() call to generate a value that it was really just ignoring, just checking to see if it was null or not. I replaced the SUM() with a COUNT(), and checked for zero instead of null, and bam, 10 minutes down to 2 seconds.

This is the kind of stuff I really like doing — figuring out how to make a minor change in a bit of code that doesn’t affect the output, but results in a measurable improvement in performance. The only thing that’s still a little frustrating about this is that I don’t completely understand why the difference is so great. I have a general idea of why this worked, but something weird must be going on internally with the PIVOT option in MS SQL for this to have made such a huge difference.

my dad

Today is the one-year anniversary of my dad’s death. I considered a few things I might do today to remember and honor him. In the end, I decided to stay home and watch the Giants game, since that’s likely what he’d be doing today if he was still around.

I haven’t been down to my parents’ old house in a few weeks, and I really need to get down there are get some more stuff done, but I couldn’t quite talk myself into going down there today.

time for a new Kindle?

My Kindle 1 may be on its last legs. First, the battery doesn’t last long anymore. If it were only that, I’d just buy a new battery. But it’s also been locking up a lot lately. Thinking that this might just have something to do with my internal memory being almost full, I’ve moved nearly everything to the SD card. And today I deleted the system indexes from both the internal memory and SD card, to force the Kindle to recreate them. No clue if that will help. If it doesn’t, then I guess I’m going to be looking at the Kindle 3.

DropBox

I finally decided to switch from Windows Live Sync (aka FolderShare) to DropBox. I’ve got it installed on my desktop, Dell laptop, MacBook, and Acer netbook now, and I’ve moved everything from FolderShare to DropBox.

The main problem with FolderShare is that it doesn’t actually store any of your stuff, it just enables you to sync a folder between shared computers. So, to sync two computers, for instance, you need to have them both turned on and connected to the internet at the same time. For me, this has been leading to occasional problems, where I wind up with two versions of the same file, or I need to turn on my desktop computer to get the latest version of a file down to my laptop, for instance.

DropBox stores your stuff in the cloud, so it shouldn’t be a problem to get a shared file from one computer to another without needing them both on at the same time. We’ll see how it works in practice, but so far, so good.

Sept 11

I fully intended on ignoring the fact that today is Sept 11. I had a few things lined up to do in the morning, then I was planning on watching some college football in the afternoon. I went out for a haircut this morning, though, and walked past the Sept 11 memorial here in Somerville. There were a bunch of people gathered around it, in silence. I think I walked by after all the official speeches were done. There was something about just seeing the people there, no one really talking, or doing anything, just being there.

When I got to the barber, he had the TV on, set to channel 7, where they were showing the reading of the names at the WTC site. I had about an hour wait before my haircut, so I got to listen to quite a few names being read. Very moving. So my plan to ignore Sept 11 has failed, and I am spending a good bit of time thinking about it now.

Two good articles to read: first, this classic Onion piece: God Angrily Clarifies ‘Don’t Kill’ Rule. The Onion did a great job in the days after 9/11 figuring out how a satirical newspaper / web site could possibly approach such a topic.

Second, this John Hodgman piece at McSweeney’s.