问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/10702447/calculating-the-execution-time-of-a-mysql-query-based-on-the-number-of-records