Decision when to create Index on table column in database?

Don’t create Indexes in every column! It will slow things down on insert/delete/update operations.

As a simple reminder, you can create an index in columns that are common in WHERE, ORDER BY and GROUP BY clauses. You may consider adding an index in colums that are used to relate other tables (through a JOIN, for example)

Example:

SELECT col1,col2,col3 FROM my_table WHERE col2=1

Here, creating an index on col2 would help this query a lot.

Also, consider index selectivity. Simply put, create index on values that has a “big domain”, i.e. Ids, names, etc. Don’t create them on Male/Female columns.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)