Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good tool for MySQL that will help me optimise my queries and index settings? [closed]

I use MySQL in a fairly complex web site (PHP driven).

Ideally, there would be a tool I could use that would help me test the SQL queries I am using and suggest better table indexes that will improve performance and avoid table scans.

Failing that, something that will tell me exactly what each query is up to, so I can perform the optimisation myself.

Edit: a simple guide to understanding the output from EXPLAIN ... would also be useful.

Thank you.

like image 264
Rik Heywood Avatar asked Sep 24 '08 14:09

Rik Heywood


2 Answers

Here's some info about EXPLAIN (referenced from the High Performance MySQL book from O'Reilly):

When you run an EXPLAIN on a query, it tells you everything MySQL knows about that query in the form of reports for each table involved in the query.

Each of these reports will tell you...

  • the ID of the table (in the query)
  • the table's role in a larger selection (if applicable, might just say SIMPLE if it's only one table)
  • the name of the table (duh)
  • the join type (if applicable, defaults to const)
  • a list of indexes on the table (or NULL if none), possible_keys
  • the name of the index that MySQL decided to use, key
  • the size of the key value (in bytes)
  • ref shows the cols or values used to match against the key
  • rows is the number of rows that MySQL thinks it needs to examine in order to satisfy the query. This should be kept as close to your calculated minimum as possible!
  • ...then any extra information MySQL wishes to convey

The book is completely awesome at providing information like this, so if you haven't already, get your boss to sign off on a purchase.

Otherwise, I hope some more knowledgeable SO user can help :)

like image 127
Pete Karl II Avatar answered Jan 01 '23 21:01

Pete Karl II


As a simplest thing, enable Slow Query Log and see what queries are slow, then try to analyze them as suggested.

like image 40
Michael Pliskin Avatar answered Jan 01 '23 20:01

Michael Pliskin