Posts Tagged ‘explain’

Profiling SQL queries with EXPLAIN

Wednesday, January 18th, 2012 | Life, Tech

If you have a complex SQL query, you might find that performance isn’t exactly ideal. Worse still, you don’t actually know which part of the query it is that is actually taking so long.

Luckily, MySQL comes to the rescue with the ability to explain.

All you have to do is start your query with the keyword EXPLAIN and MySQL will, rather than returning you a recordset of results, will instead provide a break down of everything it has done, including how it made the table joins and what order it did everything in.

EXPLAIN SELECT a INNER JOIN b ON a.col1 = b.col2 WHERE a.col1 > 1 AND b.col2 > 2;