Home Archives Pseudo FAQ
2008.06.30

Indices Matter

I was writing a small class that would iterate over about a thousand schools and perform a distance check against a user-entered ZIP code, to see if it was within an allowed distance. This is a semi-complex computation, and I was worried about whether it would be too expensive to iterate over every school, and considering the possibility of needing to find a better algorithm if it took more than, say, one or two seconds to do.

Imagine how horrified I was to get this output from my system log:
[luke@optimus tmp]$ tail -f testlog
[14:42:17]: About to get the zip code...
[14:42:17]: I am about to try to pull the full list of schools with lat and long.
[14:43:49]: About to iterate through the schools to perform distance calculations (778 results)...
[14:43:49]: Done iterating.

The good news: my iteration was fast. The bad news: My query...not so much. Turns out there were no indices on either table. Whups. Once that was fixed, the entire thing runs essentially instantly. Just one more reminder of why MySQL indices matter.

comments(1) | permalink

Posted by at 3:06 p.m.

The difference between exegesis and hermeneutics.

Posted by on 2008.07.08 at 2:36 p.m.

Post a Comment