反馈人:李冠、袁慧斌、王凯
问题1:
严重级别:严重所属项目:OZON
问题原因:慢SQL,并发高,把数据库CPU打满,严重影响策略库其它业务正常运行,SQL为:(
SELECT id,source_id,source_name,strategy_id,queue_id,sku,pf_listing_id,source_sku,title,title_id,pool_id,stock,calculation_formula_id,sale_price,country_code,currency,category_id,category_name,result_task,retry_status,status,fail_total,fail_msg,create_by,update_by,update_time,create_time,is_deleted,remark FROM t_strategy_execute_queue_evaluate_ozon
WHERE (result_task = 2743158115 AND status = 6))
解决方案:建议创建索引idx_result_task_status(result_task,status)
问题2:
数据库:zhcxkj-center-product
查询时间:12.1804
执行次数: 103
扫描行数:7024.89
发送行数:5434.26
指纹SQL:
SELECT id , customer_id , sku , title_source , status , title_name ,
language , create_log , user_log , title_repetition_value , remark ,
user_time , create_time , update_time , is_deleted , title_md5 ,
site_code , prompt_type , category1_id , title_source_id FROM ? WHERE (
sku IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,
? , ? , ? , ? ) AND status = ? AND is_deleted = ? ) ;
真实SQL:SELECT
id,customer_id,sku,title_source,status,title_name,language,create_log,user_log,title_repetition_value,remark,user_time,create_time,update_time,is_deleted,title_md5,site_code,prompt_type,category1_id,title_source_id
FROM t_product_sku_title_ozon WHERE (sku IN
(3636043,20115231,9917258,17929370,3001828,19773708,9530699,19544810,19073720,17337733,7816027,16893426,18666805,17047235,20827446,17691430,5629714,21498031,18612132,6046898,11707335,13914543,5121493,13970486,4379683,17355013,10776974,18788993,16891042,20712651,18890378,9322160,16339249,5971103,9357040,19440655,17853459,14447785,19661086,10485061,21135948,19517753,14021483,19606169,4640024,17256713,21451464,13759159,4386188,8385048,4301881,20488072,18123147,12839831,17293202,10066889,14472480,18739886,6053123,13683516,4983256,14720559,17705535,7230108,15475979,11905205,17330389,4670102,11648538,15041159,6139934,17216145,16864143,20700507,10028040,17391428,10764691,16837908,6394534,14431907,18845225,17507232,14424098,7951583,16273785,7847350,17493305,20159778,4901821,19257040,21310129,21151911,19062338,19085699,6598298,20096125,20440624,4813367,11798691,14733955,11420621,6859664,20357533,21031783,17227227,9580721,21115200,19434825,10791899,9097197,11703784,11785861,13965432,18048321,20568586,15835327,21456062,15852807,18631265,13403638,12843276,8168964,9354866,9527732,6729500,19588148,17698971,4524455,12613069,18792320,14975913,20091416,10056369,7425545,19455322,19010518,17911497,21404812,19168231,15862517,18994070,20306837,16187497,21001972,8334160,18631587,21529651,5001226,20455955,11028914,10623920,15777335,13791419,19408387,6299392,6493500,8761953,19138060,6455359,14470408,9446440,16199638,3623462,3195916,14770109,14803043,11642560,15667651,13996094,19945305,17591331,10036589,7352233,13396763,19119850,8049415,17581321,21419229,18727903,19625091,14352679,18941264,20999002,21165736,18902732,11582030,15445438,6810304,6049100,6678202,13453393,12029737,3884062,3336911,9457983,6714594,14082324,20811801,19153733,18858299)
AND status = 0 AND is_deleted = 0);
无人工修改
AISQL修改建议:SELECT id,
customer_id, sku, title_source, status, title_name, language,
create_log, user_log, title_repetition_value, remark, user_time,
create_time, update_time, is_deleted, title_md5, site_code, prompt_type,
category1_id, title_source_id
FROM t_product_sku_title_ozon
WHERE
sku IN
(3636043,20115231,9917258,17929370,3001828,19773708,9530699,19544810,19073720,17337733,7816027,16893426,18666805,17047235,20827446,17691430,5629714,21498031,18612132,6046898,11707335,13914543,5121493,13970486,4379683,17355013,10776974,18788993,16891042,20712651,18890378,9322160,16339249,5971103,9357040,19440655,17853459,14447785,19661086,10485061,21135948,19517753,14021483,19606169,4640024,17256713,21451464,13759159,4386188,8385048,4301881,20488072,18123147,12839831,17293202,10066889,14472480,18739886,6053123,13683516,4983256,14720559,17705535,7230108,15475979,11905205,17330389,4670102,11648538,15041159,6139934,17216145,16864143,20700507,10028040,17391428,10764691,16837908,6394534,14431907,18845225,17507232,14424098,7951583,16273785,7847350,17493305,20159778,4901821,19257040,21310129,21151911,19062338,19085699,6598298,20096125,20440624,4813367,11798691,14733955,11420621,6859664,20357533,21031783,17227227,9580721,21115200,19434825,10791899,9097197,11703784,11785861,13965432,18048321,20568586,15835327,21456062,15852807,18631265,13403638,12843276,8168964,9354866,9527732,6729500,19588148,17698971,4524455,12613069,18792320,14975913,20091416,10056369,7425545,19455322,19010518,17911497,21404812,19168231,15862517,18994070,20306837,16187497,21001972,8334160,18631587,21529651,5001226,20455955,11028914,10623920,15777335,13791419,19408387,6299392,6493500,8761953,19138060,6455359,14470408,9446440,16199638,3623462,3195916,14770109,14803043,11642560,15667651,13996094,19945305,17591331,10036589,7352233,13396763,19119850,8049415,17581321,21419229,18727903,19625091,14352679,18941264,20999002,21165736,18902732,11582030,15445438,6810304,6049100,6678202,13453393,12029737,3884062,3336911,9457983,6714594,14082324,20811801,19153733,18858299)
AND status = 0
AND is_deleted = 0;
优化建议:
1. 确保在sku字段上有索引(复合索引更好)
2. 如果status和is_deleted字段选择性高,可以考虑创建复合索引(sku, status, is_deleted)
3. 根据实际使用场景,考虑是否添加其他字段到复合索引中
explain表:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | t_product_sku_title_ozon | None | range | idx_sku_status_title_source_site_code,idx_status_createtime_titlesourceid | idx_sku_status_title_source_site_code | 1025 | None | 4600 | 10 | Using index condition; Using where |
额外建议:
索引建议:
取出表 【t_product_sku_title_ozon】 where条件字段 【status】 100000 条记录,重复的数据有:【57524】 条,没有必要为该字段创建索引。
取出表 【t_product_sku_title_ozon】 where条件字段 【is_deleted】 100000 条记录,重复的数据有:【78124】 条,没有必要为该字段创建索引。
→ 【t_product_sku_title_ozon】表 【sku】字段,索引已经存在,无需添加任何索引。
【t_product_sku_title_ozon】表 【sku】字段,索引分析:
+--------------------------+--------------------------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+==========================+================================+===============+===============+
| t_product_sku_title_ozon | idx_sku_status_title_source_si | sku | 812718 |
| | te_code | | |
+--------------------------+--------------------------------+---------------+---------------+
问题3:
数据库:zhcxkj-center-warehouse
查询时间:27.7234
执行次数: 288
扫描行数:2507090
发送行数:617.184
指纹SQL:
SELECT b . order_code , a . warehouse_id , b . id AS order_list_id , b .
sku , b . customer_id , ( b . product_num + IFNULL ( b .
product_num_update , ? ) ) product_num , b . pending_move_number -
IFNULL ( f . sumNumber , ? ) lock_num , d . order_source_type , a .
amazon_shipment_id , IFNULL ( e . order_build_type , ? )
order_build_type , IFNULL ( e . is_sta_com_order , ? ) is_sta_com_order ,
IFNULL ( e . interface_type , ? ) interface_type , ? as task_type , ?
as taskStatus , b . pending_move_number , IFNULL ( f . sumNumber , ? )
sumNumber FROM ? a JOIN t_stk_order_list b ON a . order_code = b .
order_code AND a . customer_id = b . customer_id JOIN rb_order_source d
ON a . order_source_id = d . id AND a . customer_id = d . customer_id
LEFT JOIN ( SELECT a . customer_id , a . origin_order_code , b .
order_list_id , SUM ( CASE WHEN a . task_status < ? then b .
sku_number else IFNULL ( b . moved_number , ? ) + IFNULL ( b .
abnormal_number , ? ) end ) sumNumber FROM ? a join
t_stk_moving_task_detail b on b . moving_task_id = a . id and b .
customer_id = a . customer_id WHERE task_type = ? AND task_status < ?
GROUP BY a . customer_id , a . origin_order_code , b . order_list_id ) f
on f . origin_order_code = a . order_code and f . order_list_id = b .
id AND f . customer_id = a . customer_id LEFT JOIN
t_stk_order_info_beikuexpand e ON a . order_code = e . order_code AND a .
customer_id = e . customer_id WHERE a . add_time >= DATE_ADD (
CURRENT_TIMESTAMP , INTERVAL ? MONTH ) AND a . is_stock_order = ? and b .
pending_move_number > ? AND b . pending_move_number - IFNULL ( f .
sumNumber , ? ) > ? ;
真实SQL:SELECT b.order_code,
a.warehouse_id, b.id AS order_list_id,
b.sku, b.customer_id, (b.product_num +
IFNULL(b.product_num_update,0)) product_num,
b.pending_move_number- IFNULL(f.sumNumber, 0) lock_num,
d.order_source_type, a.amazon_shipment_id,
IFNULL(e.order_build_type, -1) order_build_type,
IFNULL(e.is_sta_com_order, 0) is_sta_com_order,
IFNULL(e.interface_type, 0) interface_type, 3 as task_type,
0 as taskStatus, b.pending_move_number,
IFNULL(f.sumNumber, 0) sumNumber FROM t_stk_order_info a
JOIN t_stk_order_list b ON a.order_code = b.order_code AND
a.customer_id = b.customer_id JOIN rb_order_source d ON
a.order_source_id = d.id AND a.customer_id = d.customer_id LEFT
JOIN ( SELECT a.customer_id,a.origin_order_code,b.order_list_id,
SUM(CASE WHEN a.task_status < 4 then b.sku_number else
IFNULL(b.moved_number,0)+IFNULL(b.abnormal_number,0)end) sumNumber from
t_stk_moving_task a join t_stk_moving_task_detail b on
b.moving_task_id=a.id and b.customer_id=a.customer_id WHERE task_type=3
AND task_status < 5 GROUP BY
a.customer_id,a.origin_order_code,b.order_list_id )f on
f.origin_order_code=a.order_code and f.order_list_id=b.id AND
f.customer_id=a.customer_id LEFT JOIN t_stk_order_info_beikuexpand e ON
a.order_code = e.order_code AND a.customer_id = e.customer_id WHERE
a.add_time >= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)
AND a.is_stock_order = 1 and b.pending_move_number>0
AND b.pending_move_number- IFNULL(f.sumNumber, 0) > 0;
王凯,人工修改过
AISQL修改建议:扫描行数二百多万,未利用好索引
explain表:
额外建议:
索引建议: