反馈人:王凯
问题1:
数据库:zhcxkj_center_datasync_comprehensive查询时间:19.8114
扫描行数:5368810
发送行数:100
指纹SQL: SELECT id , customer_id , seller_id , source_id , global_item_id , shop_id , shop_region , item_id , item_status , create_time , update_time , is_deleted FROM ? WHERE ( source_id = ? AND id > ? AND update_time > '?' AND update_time <= '?' ) ORDER BY id ASC limit ? ;
真实SQL:SELECT id,customer_id,seller_id,source_id,global_item_id,shop_id,shop_region,item_id,item_status,create_time,update_time,is_deleted FROM t_shopee_published_item WHERE (source_id = 13927 AND id > 0 AND update_time > '2024-12-16 21:50:01' AND update_time <= '2025-08-04 15:48:52') ORDER BY id ASC limit 100;
##无人工修改##
AISQL修改建议:SELECT id, customer_id, seller_id, source_id, global_item_id, shop_id, shop_region, item_id, item_status, create_time, update_time, is_deleted FROM t_shopee_published_item FORCE INDEX(PRIMARY) WHERE source_id = 13927 AND id > 0 AND update_time > '2024-12-16 21:50:01' AND update_time <= '2025-08-04 15:48:52' ORDER BY id ASC LIMIT 100;
explain表:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | t_shopee_published_item | None | range | PRIMARY,idx_source_id,IDX_source_id_update_time,idx_update_time | PRIMARY | 8 | None | 16676088 | 0.24 | Using where |
额外建议:
索引建议:
取出表 【t_shopee_published_item】 where条件字段 【source_id】 100000 条记录,重复的数据有:【57367】 条,没有必要为该字段创建索引。
建议添加索引:ALTER TABLE t_shopee_published_item ADD INDEX idx_id_update_time(id,update_time);
【t_shopee_published_item】表 【id,update_time】字段,索引分析:
+-------------------------+---------------------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+=========================+===========================+===============+===============+
| t_shopee_published_item | IDX_source_id_update_time | update_time | 5219210 |
+-------------------------+---------------------------+---------------+---------------+
| t_shopee_published_item | idx_update_time | update_time | 2786773 |
+-------------------------+---------------------------+---------------+---------------+
| t_shopee_published_item | PRIMARY | id | 33192776 |
+-------------------------+---------------------------+---------------+---------------+
问题2:数据库:zhcxkj_center_datasync_comprehensive
查询时间:12.253
扫描行数:200
发送行数:100
指纹SQL: select b2 . id , b2 . customer_id , b2 . seller_id , b2 . source_id , b2 . global_item_id , b2 . category_id , b2 . global_item_name , b2 . description , b2 . global_item_sku , b2 . attribute_list , b2 . price_info , b2 . image , b2 . weight , b2 . dimension , b2 . pre_order , b2 . size_chart , b2 . has_condition , b2 . global_item_status , b2 . shopee_create_time , b2 . shopee_update_time , b2 . has_model , b2 . video , b2 . brand , b2 . stock_info , b2 . description_info , b2 . description_type , b2 . update_time , b2 . is_deleted from ( select b . id FROM ? b force key ( idx_update_time_id ) WHERE b . source_id = ? and b . id > ? and b . update_time > '?' and b . update_time <= '?' order by b . id asc limit ? ) b1 join t_shopee_item_global_base_info b2 on b1 . id = b2 . id ;
真实SQL:select b2.id,b2.customer_id,b2.seller_id,b2.source_id,b2.global_item_id,b2.category_id,b2.global_item_name,b2.description,b2.global_item_sku, b2.attribute_list,b2.price_info,b2.image,b2.weight,b2.dimension,b2.pre_order,b2.size_chart,b2.has_condition,b2.global_item_status,b2.shopee_create_time, b2.shopee_update_time,b2.has_model,b2.video,b2.brand,b2.stock_info,b2.description_info,b2.description_type,b2.update_time,b2.is_deleted from (select b.id from t_shopee_item_global_base_info b force key(idx_update_time_id) WHERE b.source_id=13975 and b.id>58245533 and b.update_time > '2024-12-16 20:50:00' and b.update_time <= '2025-08-04 20:01:27' order by b.id asc limit 100 ) b1 join t_shopee_item_global_base_info b2 on b1.id=b2.id;
##无人工修改##
AISQL修改建议:SELECT b2.id,
b2.customer_id,
b2.seller_id,
b2.source_id,
b2.global_item_id,
b2.category_id,
b2.global_item_name,
b2.description,
b2.global_item_sku,
b2.attribute_list,
b2.price_info,
b2.image,
b2.weight,
b2.dimension,
b2.pre_order,
b2.size_chart,
b2.has_condition,
b2.global_item_status,
b2.shopee_create_time,
b2.shopee_update_time,
b2.has_model,
b2.video,
b2.brand,
b2.stock_info,
b2.description_info,
b2.description_type,
b2.update_time,
b2.is_deleted
FROM t_shopee_item_global_base_info b2
WHERE b2.id IN (
SELECT b.id
FROM t_shopee_item_global_base_info b
WHERE b.source_id = 13975
AND b.id > 58245533
AND b.update_time > '2024-12-16 20:50:00'
AND b.update_time <= '2025-08-04 20:01:27'
ORDER BY b.id ASC
LIMIT 100
);
explain表:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | PRIMARY | <derived2> | None | ALL | None | None | None | None | 100 | 100 | None |
| 1 | PRIMARY | b2 | None | eq_ref | PRIMARY | PRIMARY | 8 | b1.id | 1 | 100 | None |
| 2 | DERIVED | b | None | range | idx_update_time_id | idx_update_time_id | 13 | None | 10204968 | 33.33 | Using where; Using index; Using filesort |
额外建议:
索引建议:
→ 【t_shopee_item_global_base_info】表 【source_id,id,update_time】字段,联合索引已经存在,无需添加任何索引。
【t_shopee_item_global_base_info】表 【source_id,id,update_time】字段,索引分析:
+--------------------------------+--------------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+================================+====================+===============+===============+
| t_shopee_item_global_base_info | idx_source_id | source_id | 17019 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time | update_time | 993424 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time_id | source_id | 15442 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time_id | update_time | 781548 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time_id | id | 34264416 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | PRIMARY | id | 34253392 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | uk_global_item_id | source_id | 34264416 |
+--------------------------------+--------------------+---------------+---------------+
→ 【t_shopee_item_global_base_info】表 【source_id,id,update_time】字段,联合索引已经存在,无需添加任何索引。
【t_shopee_item_global_base_info】表 【source_id,id,update_time】字段,索引分析:
+--------------------------------+--------------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+================================+====================+===============+===============+
| t_shopee_item_global_base_info | idx_source_id | source_id | 17019 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time | update_time | 993424 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time_id | source_id | 15442 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time_id | update_time | 781548 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | idx_update_time_id | id | 34264416 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | PRIMARY | id | 34253392 |
+--------------------------------+--------------------+---------------+---------------+
| t_shopee_item_global_base_info | uk_global_item_id | source_id | 34264416 |
+--------------------------------+--------------------+---------------+---------------+