任务描述

1.问题分析

华为gaussdb 慢sql了很多这个慢sql,执行很慢,把数据库连接对象都占了,导致其他连接不上

分析原因是没有走对索引,执行慢堆积了


select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=1  -- 5544213
select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=0  -- 1125
select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=3  --  222
select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=9  --  323906


select count(0) from `M_Mercadolibre_Notiftransfer_Site`  -- 302093746  302216446


2.解决方案

DBA 测试后给的方案是指定索引比较快,先添加一下


`M_Mercadolibre_Notiftransfer_Site` force index(idx_UserId_Status_CreateTime_id)


1.是否可以去掉ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了;

2.是否归档这些状态!=0的数据;


原始sql:


SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` > timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200

历史记录  
  1. 2023-08-04 15:44:32, 由 陈少军 创建。
  2. 2023-08-04 15:50:41, 由 陈少军 编辑。
    修改了 任务描述,区别为:
    010- 原始sql:
    010+ 是否可以去掉ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了
    012- SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` > timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200
    012+ 原始sql:
    013+
    014+ SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` > timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200
    010- <p>原始sql:</p>
    010+ <p>是否可以去掉<span>ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了</span></p>
    012- <p>SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200</p>
    012+ <p>原始sql:</p>
    013+ <p><br /></p>
    014+ <p>SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200</p>
  3. 2023-08-04 16:24:05, 由 陈少军 编辑。
    修改了 任务描述,区别为:
    005- 2.解决方案
    005+ select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=1 -- 5544213select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=0 -- 1125select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=3 -- 222select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=9 -- 323906
    006- DBA 测试后给的方案是指定索引比较快,先添加一下
    006+ select count(0) from `M_Mercadolibre_Notiftransfer_Site` -- 302093746 302216446
    008- `M_Mercadolibre_Notiftransfer_Site` force index(idx_UserId_Status_CreateTime_id)
    008+ 2.解决方案
    009-
    009+ DBA 测试后给的方案是指定索引比较快,先添加一下
    010- 是否可以去掉ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了
    010+
    011-
    011+ `M_Mercadolibre_Notiftransfer_Site` force index(idx_UserId_Status_CreateTime_id)
    012- 原始sql:
    012+
    013-
    013+ 是否可以去掉ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了
    014- SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200
    014+
    015+ 原始sql:
    016+
    017+ SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200
    005- <p>2.解决方案</p>
    005+ <p>select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=1 -- 5544213<br />select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=0 -- 1125<br />select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=3 -- 222<br />select count(0) from `M_Mercadolibre_Notiftransfer_Site` where status=9 -- 323906</p>
    006- <p>DBA 测试后给的方案是指定索引比较快,先添加一下</p>
    006+ <p><br />select count(0) from `M_Mercadolibre_Notiftransfer_Site` -- 302093746 302216446<br /></p>
    008- <p>`M_Mercadolibre_Notiftransfer_Site` force index(idx_UserId_Status_CreateTime_id)</p>
    008+ <p>2.解决方案</p>
    009- <p><br /></p>
    009+ <p>DBA 测试后给的方案是指定索引比较快,先添加一下</p>
    010- <p>是否可以去掉<span>ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了</span></p>
    010+ <p><br /></p>
    011- <p><br /></p>
    011+ <p>`M_Mercadolibre_Notiftransfer_Site` force index(idx_UserId_Status_CreateTime_id)</p>
    012- <p>原始sql:</p>
    012+ <p><br /></p>
    013- <p><br /></p>
    013+ <p>是否可以去掉<span>ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了</span></p>
    014- <p>SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200</p>
    014+ <p><br /></p>
    015+ <p>原始sql:</p>
    016+ <p><br /></p>
    017+ <p>SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200</p>
  4. 2023-08-04 16:42:02, 由 陈少军 编辑。
    修改了 任务描述,区别为:
    006- select count(0) from `M_Mercadolibre_Notiftransfer_Site` -- 302093746 302216446
    006+ select count(0) from `M_Mercadolibre_Notiftransfer_Site` -- 302093746 302216446
    013- 是否可以去掉ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了
    013+ 1.是否可以去掉ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了;
    014-
    014+ 2.是否归档这些状态!=0的数据;
    015- 原始sql:
    015+
    016-
    016+ 原始sql:
    017- SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200
    017+
    018+ SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200
    006- <p><br />select count(0) from `M_Mercadolibre_Notiftransfer_Site` -- 302093746 302216446<br /></p>
    006+ <p><br />select count(0) from `M_Mercadolibre_Notiftransfer_Site` -- 302093746 302216446</p>
    013- <p>是否可以去掉<span>ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了</span></p>
    013+ <p>1.是否可以去掉<span>ORDER BY ,同步每次取200条,同步完成后修改status=0 到status=1,下次取200条就可以了;</span></p>
    014- <p><br /></p>
    014+ <p><span>2.是否归档这些状态!=0的数据;</span></p>
    015- <p>原始sql:</p>
    015+ <p><br /></p>
    016- <p><br /></p>
    016+ <p>原始sql:</p>
    017- <p>SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200</p>
    017+ <p><br /></p>
    018+ <p>SELECT `Id` AS `Id` , `UserId` AS `UserId` , `ApplicationId` AS `ApplicationId` , 2 AS `Type` , `SiteId` AS `Resource` , `Status` AS `Status` , `SentTime` AS `Sent` , `SentTime` AS `Received` FROM `M_Mercadolibre_Notiftransfer_Site` WHERE (((( `UserId` = '678105364' ) AND ( `CreateTime` &gt; timestamp('2023-07-21 13:33:48.975197') )) AND ( `Status` = 0 )) AND NOT( `SiteId` IS NULL OR `SiteId`='')) ORDER BY Id DESC LIMIT 0,200</p>
  5. 2023-08-17 11:46:42, 由 程伟 指派给 姚杰远。
    修改了 指派给,旧值为 "chengwei",新值为 "yaojieyuan"。
  6. 2023-08-29 11:51:49, 由 陈少军 添加备注。
    美客多增量同步服务已经没有使用了,其他业务替代了此功能
  7. 2023-08-29 11:52:10, 由 陈少军 完成。
    修改了 总计消耗,旧值为 "0",新值为 "1"。
    修改了 指派给 ,旧值为 "yaojieyuan",新值为 "chenshaojun"。
    修改了 实际完成,旧值为 "",新值为 "2023-08-29 11:51:54"。
    修改了 任务状态,旧值为 "wait",新值为 "done"。
    修改了 实际开始,旧值为 "0000-00-00 00:00:00",新值为 "2023-08-29 11:52:10"。
    修改了 预计剩余,旧值为 "1",新值为 "0"。
    修改了 由谁完成,旧值为 "",新值为 "chenshaojun"。
    增量同步服务已经没有使用了
  8. 2023-10-31 14:53:17, 由 周杰 关闭。
    修改了 任务状态,旧值为 "done",新值为 "closed"。
    修改了 指派给 ,旧值为 "chenshaojun",新值为 "closed"。
    修改了 由谁关闭,旧值为 "",新值为 "zhoujie"。
    修改了 关闭时间,旧值为 "0000-00-00 00:00:00",新值为 "2023-10-31 14:53:17"。
    修改了 关闭原因,旧值为 "",新值为 "done"。
所属迭代 系统管理部 - 系统服务优化
所属模块 /
相关需求 暂无
指派给 Closed 于 2023-10-31 14:53:17
任务类型 后端
任务标签 初始
开发组 有品开发组
任务状态 已关闭
进度 100%
优先级 P2
关键词
抄送给 许瑞丰
由谁创建 陈少军 于 2023-08-04 15:44:32
由谁完成 陈少军 于 2023-08-29 11:51:54
由谁取消 暂无
由谁关闭 周杰 于 2023-10-31 14:53:17
关闭原因 已完成
最后编辑 周杰 于 2023-10-31 14:53:17
团队 最初预计 总计消耗 预计剩余
工时信息
最初预计 1工时
总计消耗 1工时
预计剩余 0工时
预计开始 2023-08-04
实际开始 2023-08-29
截止日期 2023-08-07