1.问题分析
华为云慢sql top 20,查询时间208.374 秒
2.解决方案
索引优化建议:
- 建议在数据表 irobotbox_marketpublish.M_Ebay_Listing_Sub 的 OrderSourceId,EditStatus,CustomerId,QuantitySold,ProductId 列上添加如下索引,以提高查询性能:
ALTER TABLE `irobotbox_marketpublish`.`M_Ebay_Listing_Sub` ADD INDEX `idx_OrderSourceId_EditStatus_CustomerId_QuantitySold_ProductId` (`OrderSourceId`, `EditStatus`, `CustomerId`, `QuantitySold`, `ProductId`)
注意:在业务高峰期,变更表结构存在风险,请谨慎操作!表数据比较多,下班业务低峰执行
3.慢sql
SELECT `ProductId` AS `ProductId`, SUM(IFNULL(`QuantitySold`, 0)) AS `YearSales`
FROM `M_Ebay_Listing_Sub`
WHERE `CustomerId` = 1
AND `OrderSourceId` = 10469
AND `QuantitySold` > 0
AND `EditStatus` = 1
AND NOT `ProductId` IN ('364125638437', '364090255207', '364122775869')
GROUP BY `ProductId`
ORDER BY `YearSales` DESC
LIMIT 0, 100