数据库:zhcxkj_center_listing_comprehensive
查询时间:78.2022
执行次数: 44
扫描行数:2811500
发送行数:200
指纹SQL: SELECT tml . id , tml . id listingId , tlvm . id variantId , tml . source_id , tml . source_name , tlvm . sku , tml . title , tlvm . source_sku , tml . pf_listing_id , tml . stock , tml . platform_atrributes , tml . sale_price , tml . currency , tml . category_id , tml . publisher_id , tml . publisher_name , tml . sales_id , tml . sales_name , tml . publish_time , tml . pf_online_time , tml . pf_offline_time , tml . pf_update_time , tml . country_code , tml . fail_msg , tml . image , tml . category_name , tml . status , tml . create_by , tml . create_time , tml . update_by , tml . update_time , tml . logistic_type , tml . listing_type , tml . pf_global_listing_id , tml . inventory_id , tml . sub_status , tml . is_deleted FROM ? tml INNER JOIN t_listing_variant_mercadolibre tlvm ON tml . source_id = tlvm . source_id AND tml . pf_listing_id = tlvm . pf_listing_id WHERE tml . id > ? and tml . is_deleted = ? and tml . source_id = ? and tml . status in ( ? ) limit ? ;
真实SQL:SELECT tml.id, tml.id listingId, tlvm.id variantId, tml.source_id, tml.source_name, tlvm.sku, tml.title, tlvm.source_sku, tml.pf_listing_id, tml.stock, tml.platform_atrributes, tml.sale_price, tml.currency, tml.category_id, tml.publisher_id, tml.publisher_name, tml.sales_id, tml.sales_name, tml.publish_time, tml.pf_online_time, tml.pf_offline_time, tml.pf_update_time, tml.country_code, tml.fail_msg, tml.image, tml.category_name, tml.status, tml.create_by, tml.create_time, tml.update_by, tml.update_time, tml.logistic_type, tml.listing_type, tml.pf_global_listing_id, tml.inventory_id, tml.sub_status, tml.is_deleted FROM t_listing_mercadolibre tml INNER JOIN t_listing_variant_mercadolibre tlvm ON tml.source_id = tlvm.source_id AND tml.pf_listing_id = tlvm.pf_listing_id WHERE tml.id > 1468731 and tml.is_deleted = 0 and tml.source_id = 18088 and tml.status in ( 3 ) limit 200;
无人工修改
AISQL修改建议:以下是优化后的SQL语句:
SELECT tml.id AS listingId,
tlvm.id AS variantId,
tml.source_id,
tml.source_name,
tlvm.sku,
tml.title,
tlvm.source_sku,
tml.pf_listing_id,
tml.stock,
tml.platform_atrributes,
tml.sale_price,
tml.currency,
tml.category_id,
tml.publisher_id,
tml.publisher_name,
tml.sales_id,
tml.sales_name,
tml.publish_time,
tml.pf_online_time,
tml.pf_offline_time,
tml.pf_update_time,
tml.country_code,
tml.fail_msg,
tml.image,
tml.category_name,
tml.status,
tml.create_by,
tml.create_time,
tml.update_by,
tml.update_time,
tml.logistic_type,
tml.listing_type,
tml.pf_global_listing_id,
tml.inventory_id,
tml.sub_status,
tml.is_deleted
FROM t_listing_mercadolibre tml
STRAIGHT_JOIN t_listing_variant_mercadolibre tlvm ON tml.source_id = tlvm.source_id
AND tml.pf_listing_id = tlvm.pf_listing_id
WHERE tml.id > 1468731
AND tml.is_deleted = 0
AND tml.source_id = 18088
AND tml.status = 3
LIMIT 200;
优化说明:
1. 将INNER JOIN改为STRAIGHT_JOIN强制按FROM子句顺序执行,避免优化器选择次优执行计划
2. tml.status IN (3)简化为tml.status = 3,因为IN列表只有一个值
3. 移除了重复的tml.id列,并为列添加了明确的别名
4. 确保两个表的连接字段(source_id和pf_listing_id)上都有索引
如需进一步优化,建议考虑:
1. 在tml表的(source_id, status, is_deleted, id)上创建复合索引
2. 在tlvm表的(source_id, pf_listing_id)上创建复合索引
explain表:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | tml | None | range | PRIMARY,uk_source_id_country_code_pf_listing_logistic_type_platform_type,idx_pf_listing_id,idx_status,idx_source_id_update_time,idx_source_site_status,idx_listing_mercadolibre_optim,idx_pflistingid_sourceid_status_logistictype | PRIMARY | 8 | None | 8484028 | 0.03 | Using where |
| 1 | SIMPLE | tlvm | None | ref | uk_source_id_pf_listing_id_source_sku,idx_pf_listing_id | uk_source_id_pf_listing_id_source_sku | 266 | const,zhcxkj_center_listing_comprehensive.tml.pf_listing_id | 1 | 100 | None |
额外建议:
索引建议:
取出表 【t_listing_mercadolibre】 where条件表达式 【is_deleted = 0】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。
取出表 【t_listing_mercadolibre】 where条件表达式 【source_id = 18088】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。
取出表 【t_listing_mercadolibre】 where条件字段 【status】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。
→ 【t_listing_mercadolibre】表 【id】字段,索引已经存在,无需添加任何索引。
【t_listing_mercadolibre】表 【id】字段,索引分析:
+------------------------+--------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+========================+==============+===============+===============+
| t_listing_mercadolibre | PRIMARY | id | 16943040 |
+------------------------+--------------+---------------+---------------+
→ 【t_listing_variant_mercadolibre】 表,无需添加任何索引。
