I have a project where all SQL queries was already written. Most of them can be improved, and I want to do that.
But how I can check and analyze the both queries [pre-written and I write same queries using different way].
I want to analyze the queries if I rewrite them then I can check if I did right or if old query is better than mine.
I need a queries analyzer tool for Mysql based RDBMS.
[if any mistake goes then edit it]
MySQL has an
EXPLAINstatement, which tells you what execution path the engine will follow. You can use that to determine what changes to make:See: http://dev.mysql.com/doc/refman/5.0/en/explain-output.html
Pay special attention to the
rowscolumn, which shows how many table rows need to be examined to execute that part of the query, as well as theExtracolumn, which show more importantly, how the query gets executed.For example, if you see “Using temporary” in the
Extracolumn, that usually means that the DB will need to write the query results out to a temporary table (possibly on disk), sort them, and then re-read them (or at least some of them).You can avoid temporary tables and other nasty performance killers by providing appropriate indexes. And not just enough indexes, but rather the correct indexes. Just because you’ve indexed a column doesn’t mean that index can be used in your query.