For The Love Of God, Use Keys!
December 20th, 2008 @ 4:49 pmI recently worked on an application I built some time ago. It was built before I had regard for performance or cared about how a MySQL database should be built. As such, it had no indexes.
That changed, especially when I started playing with old data that I wanted to migrate. The read time on 15 rows in a 325-row table was some 0.86 seconds (which isn’t bad but isn’t great). When indexes were applied, however, the read time went down to 0.01 seconds, an 88% decline in read time.
Indexes are easy to add. From your MySQL command prompt all you have to use is the ALTER command, like so:
ALTER TABLE tableName ADD KEY (columnNameHere);
That’s it! Of course, you may want to have some more complex keys (UNIQUE, FULLTEXT, etc) and I recommend you read the MySQL documentation.
Indexes aren’t for everything, but they can help with some things – especially on join clauses and WHERE clauses. So use them. You’ll be thankful you did.
The original work of Brandon Savage.
No related posts.
Categories: Databases, UncategorizedTags: , index, MySQLThere are currently no comments.
Web developer, amateur photographer, traveller, and amatuer chef. Expect to find me writing code, visiting new places or trying a new recipe. I live with my wife in Olney, Maryland. Follow Me On Twitter!- Excited About PHP Again
- Rethinking The Technical Resume
- We The State, Not We The People
- Working To Defeat the Stop Online Piracy Act
- Diversifying This Blog
- What do you want the web to be?
- Why I Love Being An Engineer
- Validation Blind Spots Hurt Real Users
- Finding A Job Without A Recruiter
- Why Recruiters Are Bad For Your Career


