Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to automatically generate a list of columns that need indexing?

The beauty of ORM lulled me into a soporific sleep. I've got an existing Django app with a lack of database indexes. Is there a way to automatically generate a list of columns that need indexing?

I was thinking maybe some middleware that logs which columns are involved in WHERE clauses? but is there anything built into MySQL that might help?

like image 216
Andy Baker Avatar asked Jan 13 '09 10:01

Andy Baker


2 Answers

Yes, there is.

If you take a look at the slow query log, there's an option --log-queries-not-using-indexes

like image 57
Greg Avatar answered Sep 25 '22 19:09

Greg


No.

Adding indexes willy-nilly to all "slow" queries will also slow down inserts, updates and deletes.

Indexes are a balancing act between fast queries and fast changes. There is no general or "right" answer. There's certainly nothing that can automate this.

You have to measure the improvement across your whole application as you add and change indexes.

like image 29
S.Lott Avatar answered Sep 22 '22 19:09

S.Lott