I was rewriting the whole bloody thing. I used too many complex queries in the last one, and if there is anything I've learned about SQL in the last few months, it's that lots of simple queries are far more efficient that one big one. It's now running at 5 times the speed.
Ok, now to implement the suggestions that Saerules and fr0d0 gave me.
Ok, now to implement the suggestions that Saerules and fr0d0 gave me.