1

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

4

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 index usage and execution plan
  • 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.

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

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

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.

于 2012-05-22T13:02:17.607 回答