根据记录数计算一个Mysql Query的执行时间 [英] Calculating the execution time of a Mysql Query based on the number of records

查看:39
本文介绍了根据记录数计算一个Mysql Query的执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行查询之前,有什么方法可以计算执行一组 Mysql 查询所需的时间,可能基于记录数或其他什么?

Is there any way by which i can calculate the time that would take for a set of Mysql Queries to execute, may be based on the number of records or something, before executing the query?

推荐答案

没有.影响查询执行时间的因素有很多,包括:

No. There are many factors that go into how long a query takes to execute, including:

  • 硬件规格
  • 网络配置、带宽和负载
  • MySQL 服务器配置和服务器负载
  • MySQL 索引使用和执行计划
  • 数据大小
  • 索引大小
  • 结果集的大小

确定查询需要多长时间的最佳方法是运行它.您应该使用 SQL_NO_CACHE 禁用查询缓存,以便查询缓存不会歪曲结果.

The best way to determine how long a query will take is to run it. You should disable the query cache using SQL_NO_CACHE so that the query cache does not skew the results.

使用 SHOW PROFILE 来查看 MySQL 把时间花在了什么地方.

Use SHOW PROFILE to see where MySQL is spending its time.

使用EXPLAIN查看执行计划,以便优化执行计划.

Use EXPLAIN to see the execution plan so that you can optimize the execution plan.

使用 EXPLAIN,您可以了解查询是否有效,但您仍然需要运行它以查看在您的环境中需要多长时间.

Using EXPLAIN, you can get a feel for whether the query is efficient or not, but you will still have to run it to see how long it takes in your environment.

这篇关于根据记录数计算一个Mysql Query的执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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