有什么办法检查mysql索引的性能 [英] Is there any way to check the performance of mysql Indexing
问题描述
我为我的表分配了索引。有什么方法来确定我的查询的性能吗?谢谢
I have assigned Indexes for my tables. Is there any way to identify the performance of my query? Thank you
EDIT
这里我附加我的测试服务器EXPLAIN结果。在测试服务器中只有很少的行,但在活动服务器中有大量的记录,并且它需要10到15分钟来执行查询。
如果此处显示不可见此处显示此图片的网址
Here i am attaching my test servers EXPLAIN result. In test server there are only few rows but in live server there are crores of records and it takes 10 to 15 minutes to execute query. if its not visible here i am giving url for this image
http://i45.tinypic.com/n6t8cx.jpg
推荐答案
以下查询将告诉您查询是否使用索引:
Following query will tell you whether query uses index or not:
EXPLAIN EXTENDED SELECT col1, col2, col3, COUNT(1)
FROM table_name
WHERE col1 = val
GROUP BY col1
ORDER BY col2;
SHOW WARNINGS;
您可以添加覆盖索引以获得最佳性能。
You can add covering index for best performance.
对于覆盖索引,您可以添加在where子句中使用的列,然后使用按顺序使用的列,然后在select中使用的列在组中使用的列。
For covering index you add columns used in where clauses first then columns used in group by the columns used in order by and then columns used in select.
例如对于上述查询,您可以添加覆盖索引 KEY(col1,col2,col3)
e.g. for above query you can add covering index KEY(col1, col2, col3)
*注意添加更多索引减慢你的插入查询。
*Note Adding more indexes will slow down your insert queries.
这篇关于有什么办法检查mysql索引的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!