有什么办法可以检查mysql索引的性能 [英] Is there any way to check the performance of mysql Indexing

查看:24
本文介绍了有什么办法可以检查mysql索引的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的表分配了索引.有什么方法可以确定我的查询的性能吗?谢谢

I have assigned Indexes for my tables. Is there any way to identify the performance of my query? Thank you

编辑

在这里我附上我的测试服务器解释结果.在测试服务器中只有几行,但在实时服务器中有千万条记录,执行查询需要 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 子句中使用的列,然后按 order 中使用的列添加 group 中使用的列,然后添加 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆