Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how many index per database table? [closed]

How many indexes is preferred for one table in MySQL??

I have a company table where I search mostly for ID, state, and category.

like image 932
Bart Avatar asked May 09 '26 02:05

Bart


1 Answers

There is no one single answer for this question: create as many indexes are required to make your queries fast enough, and no more.

You have to trade off various things when deciding what to index:

  • The more indexes you have, the slower inserts and updates will be (because they need to update all of the indexes)
  • Queries over tables without an appropriate index can be very slow, if the database has to do a table scan
  • Some columns do not require indexes (for example, a 'gender' column where the only possible value is "M" or "F")

For your particular scenario, it seems like three indexes, one on ID (if this is the primary key, then it already has an implicit index), one on state and one on category, would suffice.

like image 159
Dean Harding Avatar answered May 11 '26 18:05

Dean Harding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!