| 执行次数:8543 | 平均时间:28.428 | 最大时间:219.630 |
优化后为:30秒
建议优化为:
drop temporary table if exists tabReport;
create temporary table tabReport as
SELECT
`CustomerId` AS `CustomerId`,
`OrderSourceId` AS `OrderSourceId`,
`ProductId` AS `ProductId`,
SUM( `ListingImpressionTotal` ) AS `ListingImpressionTotal`
FROM
`Sys_Ebay_Traffic_Report`
WHERE
( `Date` >= 20230317 )
AND (
`OrderSourceId` IN ( 10227 ))
GROUP BY
`CustomerId`,
`OrderSourceId`,
`ProductId`
HAVING
( SUM( `ListingImpressionTotal` ) <= 20 ) ;
create index idx_ProductId_OrderSourceId on tabReport(ProductId,OrderSourceId);
drop temporary table if exists tabListing;
create temporary table tabListing as
SELECT
s.*
FROM
(
SELECT
`CustomerId` AS `CustomerId`,
`Sku` AS `Sku`,
`RealSku` AS `RealSku`
FROM
`P_Product`
WHERE
(((
`CustomerId` = 1
)
AND ( `StartBatch` >= 1 ))
AND ( `StartBatch` <= 200 ))
) p
INNER JOIN (
SELECT
*
FROM
`M_Ebay_Listing`
WHERE
(((((((((
`CustomerId` = 1
)
AND NOT ( `Sku` IS NULL OR `Sku` = '' ))
AND (
`OrderSourceId` IN ( 10227 ))
)
AND ( `PublishTime` >= TIMESTAMP ( '2023-03-16 00:00:00' ) ))
AND ( `PublishTime` <= TIMESTAMP ( '2023-03-24 00:00:00' ) ))
AND (
`OnlineStatus` IN ( 1 ))
)
AND ( 'UK' = `SiteCode` ))
AND ( `IsAutoPublish` = 1 ))
AND ( 'CN' = `Country` ))
) s ON ((
`p`.`CustomerId` = `s`.`CustomerId`
)
AND ( `p`.`Sku` = `s`.`Sku` )) ;
create index idx_ProductId_OrderSourceId on tabListing(ProductId,OrderSourceId);
SELECT
s.*
FROM
tabReport tr
INNER JOIN tabListing s ON (((
`tr`.`CustomerId` = `s`.`CustomerId`
)
AND ( `tr`.`OrderSourceId` = `s`.`OrderSourceId` ))
AND ( `tr`.`ProductId` = `s`.`ProductId` ))
LIMIT 7700,
100;