Mysql optimizing – querys with no indexes
March 15, 2010 by admin · Leave a Comment
Mysql optimization of a site is one of the most important aspects of optimizing a website.
If you have a website is very important to try to optimize it better. Optimizing a site you can get rid of a greater expense to a hosting service.
The first thing i try is to add in my.conf (config mysql) the following code:
log-queries-not-using-indexes
What is the setting above? Simply addes the mysql query logs of a sites that do not use an index.
In other words: to find a result in a mysql table each record’s is compared with the condition of the query.
So if you have a query that finds data into a tabl;e with 100,000 records you will notice that during the process that mysql resources used are extremely large compared to the situation that your query has a good index. But if I can not access the file my.conf? Nothing more simple …
Natural the question that comes now is: How do I know if a query correctly selects an index?
For this there EXPLAIN the syntax of MySQL. This is the syntax for explain query:
[/php]
Explain SELECT id, username FROM users WHERE id = 3
[/ php]
The result of this query is a table with several fields that will contain two known possible_key and key.
These two fields actually shows you potential index and the index that MySQL’s chosen to use.
Soon I want to make available a mysql class that can help you easily debuggul and that contain data from this short tutorial. Soon other details …
Related posts: