Slowlog中long_query_time时间设置以下的query

Mysql Version :5.1.72

OS Version :CentOS release 6.4 (Final)

说到慢查询,有点老生常谈了,但是慢查询相关的有个参数可能会被很多人忽略。

log_queries_not_using_indexes

这个参数设置当查询没有使用索引的情况下,是否记录到slowlog中。

模拟情景:

当前long_query_time = 1 && log_queries_not_using_indexes = on

运行一个全表扫描的sql:

当执行当前sql的时候,查看slowlog会发现,虽然long_query_time=1,但是这条sql仍然会被记录在slowlog中

图中看到query_time:0.001311秒

如果你使用的mysql版本大于5.6.5,也可以通过设置

log_throttle_queries_not_using_indexes

这个参数表示每分钟允许记录到slowlog且未使用索引的次数。默认值为0,标识没有限制。

相关文档(摘取Mysql 5.1官方文档):

5.2.5 The Slow Query Log

The slow query log consists of SQL statements that took more than long_query_time seconds
to execute and (as of MySQL 5.1.21) required at least min_examined_row_limit rows
to be examined. The default value oflong_query_time is
10. Beginning with MySQL 5.1.21, the minimum is 0, and the value can be specified to a resolution of microseconds. For logging to a file, times are written including the microseconds part. For logging to tables, only integer times are written; the microseconds
part is ignored. Prior to MySQL 5.1.21, the minimum value is 1, and the value for this variable must be an integer.

By default, administrative statements are not logged, nor are queries that do not use indexes for lookups. This behavior can be changed using --log-slow-admin-statements and --log-queries-not-using-indexes,
as described later.

The time to acquire the initial locks is not counted as execution time. mysqld writes
a statement to the slow query log after it has been executed and after all locks have been released, so log order might differ from execution order.

Control the slow query log at server startup as follows:

If the slow query log file is enabled but no name is specified, the default name is host_name-slow.log and
the server creates the file in the same directory where it creates the PID file. If a name is given, the server creates the file in the data directory unless an absolute path name is given to specify a different directory.

To disable or enable the slow query log or change the log file name at runtime, use the global slow_query_logand slow_query_log_file system
variables. Set slow_query_log to
0 (or OFF) to disable the log or to 1
(or ON) to enable it. Set slow_query_log_file to
specify the name of the log file. If a log file already is open, it is closed and the new file is opened.

When the slow query log is enabled, the server writes output to any destinations specified by the --log-outputoption
or log_output system
variable. If you enable the log, the server opens the log file and writes startup messages to it. However, further logging of queries to the file does not occur unless the FILE log
destination is selected. If the destination is NONE,
the server writes no queries even if the slow query log is enabled. Setting the log file name has no effect on logging if the log destination value does not contain FILE.

The server writes less information to the slow query log (and binary log) if you use the --log-short-formatoption.

To include slow administrative statements in the statements written to the slow query log, use the --log-slow-admin-statements server
option. Administrative statements include ALTER
TABLE
ANALYZE
TABLE
CHECK
TABLE
CREATE
INDEX
DROP
INDEX
OPTIMIZE
TABLE
, and REPAIR
TABLE
.

To include queries that do not use indexes for row lookups in the statements written to the slow query log, use the --log-queries-not-using-indexes server
option. See Section 5.1.3,
“Server Command Options”
. When such queries are logged, the slow query log may grow quickly.

The server uses the controlling parameters in the following order to determine whether to write a query to the slow query log:

  1. The query must either not be an administrative statement, or --log-slow-admin-statements must
    have been specified.
  2. The query must have taken at least long_query_time seconds,
    or --log-queries-not-using-indexes must
    have been specified and the query used no indexes for row lookups.
  3. The query must have examined at least min_examined_row_limit rows.

The server does not write queries handled by the query cache to the slow query log, nor queries that would not benefit from the presence of an index because the table has zero rows or one row.

Prior to MySQL 5.1.45, replication slaves did not write replicated queries to the slow query log, even if the same queries were written to the slow query log on the master. (Bug #23300) In MySQL 5.1.45 and later, this behavior can be overridden using the --log-slow-slave-statements option.

The slow query log should be protected because logged statements might contain passwords. See Section 6.1.2.3,
“Passwords and Logging”
.

The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization. However, examining a long slow query log can become a difficult task. To make this easier, you can process a slow query log file using
the mysqldumpslow command
to summarize the queries that appear in the log. See Section 4.6.8,
“mysqldumpslow —
Summarize Slow Query Log Files”
.

时间: 2024-11-08 16:38:56

Slowlog中long_query_time时间设置以下的query的相关文章

JS中Date时间设置溢出问题

在采购商财务电子钱包中提供了可查询最近一个月数据的功能:该功能会使用JS Date类型计算新的日期. 这里有一点需要注意:在设置日期时,date.setMonth(m);//m is from 0 to 11. 这里如果当前日期时2015年3月31日,date.setMonth(1);得到的结果是2015年3月3日. 对于最近一个月的定义如下: 1.上月无当日的(3月31日,2月无31日.闰年2月29也在考虑范围内)最近一个月为:当月1日~当前日. 2.其余(上月有当日) 最近一个月为:上月当日

R语言时间序列中的时间设置

时间序列的不同时间分段设置 1. 普通的时间序列:年.月.季 1 myserises<-ts(data,start=,end=,frequency=)#其中frequency=1代表年:frequency=12代表月:frequency=4代表季度数据 2. 如果以天为单位的时间序列 1 t<-ts(1:365,frequency=1,start=as.Date("2017-05-01")) 2 s<-as.Date("2017-05-01") 3

【转】 c#中两个DateTimePicker,一个时间设置为0:0:0,另一个设置为23:59:59

[转] c#中两个DateTimePicker,一个时间设置为0:0:0,另一个设置为23:59:59 stp1为第一个DateTimePicker this.dtp1.Value=this.dtp1.Value.Date; stp2为第二个DateTimePicker 设置dtp2的值的时间部分是23:59:59. this.dtp2.Value = new DateTime(this.dtp2.Value.Year, this.dtp2.Value.Month, this.dtp2.Valu

Linux系统时间和硬件时间设置

在Linux中有硬件时钟与系统时钟两种时钟.硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟.系统时钟则是指kernel中的时钟.所有Linux相关指令与函数都是读取系统时钟的设定.因为存在两种不同的时钟,那么它们之间就会存在差异.当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作. 用date命令对系统时间进行设置后,并不会去修改硬件时钟,所以系统重启后,系统时间还算会去读取硬件时间,这就是为何date设置失效到原因. 因此,需要在设置系统时间后,将

录像过程中系统时间改变了,怎么避免带来的悲剧

在android系统上,我们知道改变系统时间的方法有两种,一种就是通过再设置应用里面设置日期时间,第二种就是通过网络后台同步时间,在手机平板上这两种是比較多的,当然作为车载设备.一般还会添加用GPS时间来同步系统时间. 系统时间改变有这么几种方式.可是在录像过程中系统时间改变了,会有什么危害呢? 通过笔者的实验.假设開始录像是2014年5月20日10点整開始,过了一分钟.添加通过网络已经同步改动了系统时间到2014年7月1日,那么即使这个录像文件实际上仅仅录了5分钟.我们回放这个文件的时候显示的

C中的时间函数的用法

C中的时间函数的用法    这个类展示了C语言中的时间函数的常用的用法. 源代码: #include <ctime>#include <iostream> using namespace std; class MyTime{public:    MyTime() { mPTime = 0; mStLocalTime = 0; mStGMTTime = 0; }    ~MyTime() {}; //time_t time(time_t * timer) 返回自1970年1月1日00

如果将缓存“滑动过期时间”设置为1秒会怎样?

今天编写了一个采用ASP.NET Caching的组件,在为它编写Unit Test的过程中发现了一个有趣的问题,接下来我通过一个简单的实例说明这个问题.我们在一个控制台应用中编写了如下一段程序,这个段程序很简单:我们通过HttpRuntime的静态属性Cache得到表示当前缓存的Cache对象,并调用其Insert方法对当前的时间实施缓存.需要注意的是,我们采用“滑动时间”过期策略,并将这个滑动时间设置为1秒.

VC socket Connect 超时时间设置

设置connect超时很简单,CSDN上也有人提到过使用select,但却没有一个令人满意与完整的答案.偶所讲的也正是select函数,此函数集成在winsock1.1中,简单点讲,"作用使那些想避免在套接字调用过程中被锁定的应用程序,采取一种有序的方式,同时对多个套接字进行管理"(<Windows网络编程技术>原话).使用方法与解释请见<Windows网络编程技术>. 在使用此函数前,需先将socket设置为非阻塞模式,这样,在connect时,才会立马跳过,

php学习笔记3--php中获取时间与实际时间不符

问题描述:在php脚本中使用date()获取服务器时间时总是与实际时间相差几个小时. 可能原因:php配置文件中时区的设置出现问题 解决方法: 方法1. php.ini文件中date.timezone=PRC 或者date.timezone = Asia/Shanghai 方法2. 在调用date()等时间相关的函数之前调用:date_default_timezone_set('PRC'); 或者date_default_timezone_set('Asia/Shanghai');