如何检查mysql查询的性能? [英] How to check performance of mysql query?

查看:69
本文介绍了如何检查mysql查询的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习查询优化,提高查询性能,但总的来说,如果创建查询,我们如何才能知道这是否是明智的查询.

I have been learning query optimization, increase query performance and all but in general if we create a query how can we know if this is a wise query.

我知道我们可以在下面看到执行时间,但是如果没有大量数据,这一次不会给出明确的指示.通常,当我们创建一个新查询时,我们没有太多要检查的数据.

I know we can see the execution time below, But this time will not give a clear indication without a good amount of data. And usually, when we create a new query we don't have much data to check.

我已经了解了子句和命令的性能.但是,有什么方法可以检查查询的性能?这里的性能不是执行时间,这意味着查询是否确定" ,是否与数据无关.

I have learned about clauses and commands performance. But is there is anything by which we can check the performance of the query? Performance here is not execution time, it means that whether a query is "ok" or not, without data dependency.

由于我们无法创建实时数据库中的大量数据.

As we cannot create that much data that would be in live database.

推荐答案

可以使用MySQL中的EXPLAIN命令检查查询的一般性能.参见 https://dev.mysql.com/doc/refman/5.7/en/using-explain.html

General performance of a query can be checked using the EXPLAIN command in MySQL. See https://dev.mysql.com/doc/refman/5.7/en/using-explain.html

它向您展示MySQL引擎如何计划执行查询并允许您进行一些基本的检查,例如,如果引擎将使用键和索引来执行查询,请查看MySQL将如何执行联接(即,如果没有外键) (没有丢失)等等.

It shows you how MySQL engine plans to execute the query and allows you to do some basic sanity checks i.e. if the engine will use keys and indexes to execute the query, see how MySQL will execute the joins (i.e. if foreign keys aren't missing) and many more.

您可以在此处找到有关如何使用EXPLAIN来优化查询的一些一般性提示(以及一些不错的示例):

You can find some general tips about how to use EXPLAIN for optimizing queries here (along with some nice samples): http://www.sitepoint.com/using-explain-to-write-better-mysql-queries/

这篇关于如何检查mysql查询的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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