根据记录数计算Mysql查询的执行时间

时间:2022-05-08 03:49:56

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?

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

1 个解决方案

#1


3  

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

不是。执行查询所需的时间有很多因素,包括:

  • Hardware specs
  • 硬件规格
  • Network configuration, bandwidth, and load
  • 网络配置,带宽和负载
  • MySQL Server configuration and server load
  • MySQL服务器配置和服务器负载
  • MySQL index usage and execution plan
  • MySQL索引使用和执行计划
  • Size of data
  • 数据大小
  • Size of index
  • 指数大小
  • Size of result set
  • 结果集的大小

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.

确定查询将花费多长时间的最佳方法是运行它。您应该使用SQL_NO_CACHE禁用查询缓存,以便查询缓存不会使结果发生偏差。

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

使用SHOW PROFILE查看MySQL花费时间的位置。

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.

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

#1


3  

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

不是。执行查询所需的时间有很多因素,包括:

  • Hardware specs
  • 硬件规格
  • Network configuration, bandwidth, and load
  • 网络配置,带宽和负载
  • MySQL Server configuration and server load
  • MySQL服务器配置和服务器负载
  • MySQL index usage and execution plan
  • MySQL索引使用和执行计划
  • Size of data
  • 数据大小
  • Size of index
  • 指数大小
  • Size of result set
  • 结果集的大小

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.

确定查询将花费多长时间的最佳方法是运行它。您应该使用SQL_NO_CACHE禁用查询缓存,以便查询缓存不会使结果发生偏差。

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

使用SHOW PROFILE查看MySQL花费时间的位置。

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.

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