简体   繁体   English

计算查询执行时间

[英]Calculating query execution time

I have aa table of questions in my database here are column and data types of questions table 我的数据库中有一个问题表,这里是问题表的列和数据类型

Field           Datatype
QID             BIGINT
UserID          INT(11)
Question        VARCHAR(100)
Description     Text
Date            DateTime
Status          TINYINT

this table is expected to have around 2 Million entries my question is how do i calculate query execution time if i am searching a record based on QID, UserID or Question. 该表预计将有大约200万个条目。我的问题是,如果我要基于QID,UserID或Question搜索记录,该如何计算查询执行时间。

You can use the General Query Log but it has certain disadvantages too so think before running it on some production environment. 您可以使用常规查询日志,但它也有某些缺点,因此请在某些生产环境中运行它之前先考虑一下。

You can use it like: 您可以像这样使用它:

SET profiling = 1;

and then execute your query like 然后像这样执行查询

SHOW PROFILES;

EDIT:- 编辑:-

I dont know if that is the best approach to go with but here it goes as it may depend on the CPU and the number of processes running on your system: 我不知道这是否是最好的方法,但是这可能取决于CPU和系统上运行的进程数:

declare @start timestamp
declare @stop timestamp

set @start = select NOW();
//Your query
set @stop = select NOW();

Execution time = @stop - @start 执行时间 = @stop - @start

Afaik you can only find out number of block accesses but calculating query execution time would be impossible you can only estimate it because you never know how many processes will be executing on your actual hardware and that's why you have no way to calculate for how long will processor serve your process only. Afaik您只能找出块访问的数量,但是无法计算查询执行时间,您只能估算它,因为您不知道实际硬件上将执行多少个进程,这就是为什么您无法计算将要执行多长时间的原因处理器只为您服务。

To find out number of block accesses follow first answer of this question best explanation i guess 要找出阻止访问的数量,请遵循此问题的第一个答案,我猜这是最佳解释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM