To Boldly Nerd…

Video games, pen&paper RPGs and other nerdery

How Not To SQL

| 4 Comments

One of my work’s clients have been moaning about how slow a piece of software is. This software’s due for a rewrite as they want a bunch of features added, and they’ve been treating it like a clown car for the last couple years – it was meant to handle a couple hundred thousand records, and there’s about five million hanging out in there with their red noses and big shoes. So we’ve been nodding and yes-dearing for a while, waiting for them to approve the rewrite.

But they mentioned at a meeting the other day that it took twenty minutes for the start page to load. Well, hell. Fine, I said, I’ll take a look. This software was written over five years ago by an intern, and apparently nobody competent looked it over before it went live. I popped the hood of the clown car this afternoon:

recordSet = select * from reallyBigTableFullOfClowns
output: count(recordSet)

And this is how it should be done:

output: select count(*) from reallyBigTableFullOfClowns

How can I sum this up for non-programmers? Okay, picture this. You’re at a… sauna. There are a lot of naked people. You want to know how many there are, so you’re going to have to count them. There are two ways you can do this:

A) Count them.
B) Have sex with each one and put a notch on your bedpost. Afterwards, count the notches.

Now, obviously, that second option takes a lot more time and effort. Especially when we’ve got five million rows in the database to go through. It’s a common beginner’s mistake, and it costs a lot of $$ in condoms.

Don’t do this, people. Think of the clowns.

4 Comments

  1. Arguably approach B is more fun though.

  2. Hilarious example. Well done! 🙂

Leave a Reply

Required fields are marked *.


CommentLuv badge

%d bloggers like this: