1

Possible Duplicate:
What columns generally make good indexes?

I'm working with mySQL database (with PHP) and wondering about database indexes which are used to speed up the queries.

Should we use indexes from the very beginning, even when there are only a few rows in the database, or should they only be applied if the database grows large and becomes slow?

Community
  • 1
  • 1
Jay
  • 11
  • 1

4 Answers4

1

Id use them from the creation if you ever plan on the table growing to that state. It will make your application fast right off and prevent unnecessarily bogging down the DBMS from having to apply the indexes later.

rayman86
  • 1,385
  • 10
  • 9
1

You will want to design your tables in respect to how you expect your table sizes to grow. Indexing does however require more disk space since it is essentially creating a copy of part of the table being indexed.

Depending on your time constraints, I'd go ahead and add the indexes now to prevent even more work in the future.

As with any project, you will want your data model to be sound before you find that you have to alter your entire code base because of a database change.

It Grunt
  • 3,300
  • 3
  • 21
  • 35
1

You should apply indexes to a database after analysing the type of queries you are going to perform, not by the number of rows in the table.

Add indexes from the start but also remember to revisit your analysis and don't be afraid to add or remove indexes as required; they are not something you only get one chance at.

Tony
  • 9,672
  • 3
  • 47
  • 75
0

Don't optimize to early. Anyway, add indexes to common search columns, Remember that each insert demands index update, so place your indexes wisely

qza
  • 599
  • 4
  • 7