- 论坛徽章:
- 0
|
因为这些慢日志经过mysqldumpslow 处理过放在数据库中,现在根据需要从数据库中取出要匹配的内容,
内容有一下几种 可能 形式:
一、
只有一个Count:...加上SQL语句:
Count: 1 Time=2.00s (2s) Lock=0.00s (0s) Rows=17.0 (17) Examined=(17), moneyfinance_r[moneyfinance_r]@[10.71.10.42]
select * from holding_3 where portfolio_id=N
二、
有两个count加上SQL语句:
Count: 1 Time=2.00s (2s) Lock=0.00s (0s) Rows=100.0 (100) Examined=(170700), pn_r[pn_r]@[10.44.6.26]
select * from tb8_15 where N=N order by id desc limit N,N
Count: 1 Time=2.00s (2s) Lock=0.00s (0s) Rows=10.0 (10) Examined=(42124), iggames_r[iggames_r]@[10.44.6.52]
SELECT SQL_CALC_FOUND_ROWS `series_id`, `series_name`, `series_state` FROM `series` WHERE `series_id` IN (N,,{repeated 20074 times}N) AND `series_state` IN ('S', 'S', 'S') ORDER BY `series_id` DESC LIMIT N, N
三、
有N个以上类似语句:
Count: 1 Time=2.00s (2s) Lock=0.00s (0s) Rows=0.0 (0) Examined=(0), osinapay[osinapay]@[10.69.4.204]
SET insert_id=N;
insert into osinapay.payacc_order_list_57 (order_num, basenum, order_from, order_to, userid, userid_from, userid_to, money, point, sp_srv_id, cp_subprod_id, subprod_order_num, order_time, finish_time, userip, order_state) values('S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S')
Count: 1 Time=2.00s (2s) Lock=0.00s (0s) Rows=0.0 (0) Examined=(0), comment[comment]@[10.55.22.26]
SET insert_id=N;
INSERT INTO comment45 (res_id,res_uid,uid,ruid,content,ctime,ip,status,appid) VALUES ('S','S','S','S','S','S','S','S','S')
Count: 2 Time=2.00s (4s) Lock=0.00s (0s) Rows=0.0 (0) Examined=(0), osinapay[osinapay]@[10.69.4.202]
SET insert_id=N;
insert into osinapay.payacc_order_list_35 (order_num, basenum, order_from, order_to, userid, userid_from, userid_to, money, point, sp_srv_id, cp_subprod_id, subprod_order_num, order_time, finish_time, userip, order_state) values('S', 'S', 'S', 'S', 'S', 'S', 'S', 'S'
需求:给两个过滤值:((Time<5s ) && (Count< 5)) 即:同时满足查询时间小于5S和查询次数小于5次的慢日志记录删除或者替换为空,比如:
Count: 1 Time=2.00s (2s) Lock=0.00s (0s) Rows=100.0 (100) Examined=(170700), pn_r[pn_r]@[10.44.6.26]
select * from tb8_15 where N=N order by id desc limit N,N)这里Count: 1 Time=2.00s刚好满足条件,所以要全部去掉,我这里是替换为空。
我的部分程序:
while($res[1]=~m/\s*Count:\s*(\d+)\s*Time=(\d+.\w+\s*\(\-{0,1}\w+\))\s*Lock=(\d+.\w+\s*\(\w+\))\s*Rows=(\d+.\w+\s*\(\w+\))\s*Examined=(\(\d+\)), ([^[@]+).+(\n)*/)
{
$count=$1;
$sometime=" Query_time=$2 Lock_time=$3 Rows_sent=$4 Rows_examined 5";
$query_time = $2;
if ($query_time =~/(\d+\.\d+)s/)
{
$cmp_time = $1;
}
if (($count < $filter_count) && ($cmp_time < $filter_time))
{
$res[1]=~s/\s*Count:\s*(.*?)(Count */$2/;
print "#####################################\n";
print ">>>>>>>>>>>if_res $res[1]\n";
print "######################################\n";
next;
}
我这样写肯定不行,我想的是要加判断分别去匹配上面的三种情况,感觉有点复杂,看各位有没有好点的想法。 |
|