So indexes really DO matter!

I’ve always heard that indexes are efficient and a best practice, and I’ve tended to include them when I set up tables in MySQL or SQL Server. But I’ve never really tested it.

Today a coworker was running a statement something like this, as part of a script: SELECT streetnumber, streetname FROM addresses WHERE streetnumber = 1000. These queries were taking about 20 seconds each, which we chalked up to it being a table with lots of rows, but it still seemed overly long considering there was no aggregation or ordering in the statement.

We brainstormed what the issue could be, and he proposed it might be lack of index. He indexed the column, which only took a couple of seconds.

He ran the script again, and now it executed several queries per second. Wow!

 

Leave a Reply

Your email address will not be published. Required fields are marked *