1.问题描述
智能刊登慢sql, 大量查询,3秒
2.问题分析解决方案
先查id,在join查询 其他字段,速度非常快
SELECT a.Id, `CustomerId`,`IsGlobal`,`OrderSourceId`,`Sku`,`CustomSku`,`IsMain`,`ProductId`,`SubProductId`,`SellerSku`,`Name`,`Color`,`Size`,`MainImage`,`Price`,`OriginalPrice`,`InflatedPrice`,`InflatedOriginalPrice`,`StockLocationId`,`StockType`,`Inventory`,`CurrentStock`,`ReservedStock`,`StockLocationId1`,`Inventory1`,`CurrentStock1`,`ReservedStock1`,`TierIndex`,`PromotionId`,`CreateTime`,`UpdateTime`,`Status`,`EditStatus`,`LastModifierId`,`LastModifier`,`LastModificationTime`,`CreatorId`,`Creator`,`CreationTime`
from M_ShopeeV2_Listing_Sub a join
(
select Id FROM `M_ShopeeV2_Listing_Sub`
WHERE `CustomerId` = 1 AND `OrderSourceId` = 14260 AND `Sku` IS NULL OR `Sku`='' AND `LastModificationTime` >= timestamp('2023-03-25 10:24:05.401569')
ORDER BY Id Asc LIMIT 0,500
) b on a.Id=b.Id
-- 1 秒
3.慢sql
SELECT `CustomerId`,`IsGlobal`,`OrderSourceId`,`Sku`,`CustomSku`,`IsMain`,`ProductId`,`SubProductId`,`SellerSku`,`Name`,`Color`,`Size`,`MainImage`,`Price`,`OriginalPrice`,`InflatedPrice`,`InflatedOriginalPrice`,`StockLocationId`,`StockType`,`Inventory`,`CurrentStock`,`ReservedStock`,`StockLocationId1`,`Inventory1`,`CurrentStock1`,`ReservedStock1`,`TierIndex`,`PromotionId`,`CreateTime`,`UpdateTime`,`Status`,`EditStatus`,`LastModifierId`,`LastModifier`,`LastModificationTime`,`CreatorId`,`Creator`,`CreationTime`,`Id`
FROM `M_ShopeeV2_Listing_Sub`
WHERE (((( `CustomerId` = 1 ) AND ( `OrderSourceId` = 14260 )) AND ( `Sku` IS NULL OR `Sku`='')) AND ( `LastModificationTime` >= timestamp('2023-03-25 10:24:05.401569') ))
ORDER BY Id Asc LIMIT 0,500
-- 15秒
1.修改查询sub写法