Search code examples
mysqlsqlindexingdatabase-performance

Improve MySQL perforance by indexing everything


By indexing a column, MySQL does not need to look through every row in the table, instead it can find the data you are searching for alphabetically, then skip immediately to look at the row(s) where the data is located.

So I'm starting to think that, by setting every columns the performance should be even better. Am I right?

And if so, what would be the downside of this? Because if it's better for performance and if there is no downside, every columns should be defined as index by default.

Thanks for your advices.


Solution

  • Large numbers of indexes can slow down INSERT/UPDATE queries and take up significant amounts of disk space (potentially more than the data itself). You should index the columns intelligently, based on the sorts of queries your application makes.