反馈人:王凯
问题1:
数据库:zhcxkj_center_listing_comprehensive查询时间:46.2186
扫描行数:2269870
发送行数:200
指纹SQL: SELECT id , source_sku , source_id , pf_listing_id , pf_global_listing_id FROM ? WHERE ( source_id = ? AND status IN ( ? , ? ) AND is_deleted = ? ) ORDER BY id ASC limit ? ;
真实SQL:SELECT id,source_sku,source_id,pf_listing_id,pf_global_listing_id FROM t_listing_mercadolibre WHERE (source_id = 10833 AND status IN (1,3) AND is_deleted = 0) ORDER BY id ASC limit 200;
无人工修改
AISQL修改建议: 优化后的SQL语句
SELECT id, source_sku, source_id, pf_listing_id, pf_global_listing_id
FROM t_listing_mercadolibre
WHERE source_id = 10833 AND status IN (1, 3) AND is_deleted = 0
ORDER BY id ASC
LIMIT 200;
建议创建以下复合索引以提升查询性能:
CREATE INDEX idx_listing_mercadolibre_optim ON t_listing_mercadolibre(source_id, status, is_deleted, id);
这个复合索引能够覆盖WHERE条件和ORDER BY子句,可以显著提高查询效率。
explain表:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | t_listing_mercadolibre | None | index | uk_source_id_country_code_pf_listing_logistic_type_platform_type,idx_status,idx_source_id_update_time,idx_source_site_status,IDX_is_deleted_source_id_status_id | PRIMARY | 8 | None | 38139 | 0.1 | Using where |
额外建议:
索引建议:
取出表 【t_listing_mercadolibre】 where条件字段 【status】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。
取出表 【t_listing_mercadolibre】 where条件字段 【is_deleted】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。
→ 【t_listing_mercadolibre】表 【source_id,id】字段,联合索引已经存在,无需添加任何索引。
【t_listing_mercadolibre】表 【source_id,id】字段,索引分析:
+------------------------+--------------------------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+========================+================================+===============+===============+
| t_listing_mercadolibre | IDX_is_deleted_source_id_statu | id | 8278215 |
| | s_id | | |
+------------------------+--------------------------------+---------------+---------------+
| t_listing_mercadolibre | IDX_is_deleted_source_id_statu | source_id | 18240 |
| | s_id | | |
+------------------------+--------------------------------+---------------+---------------+
| t_listing_mercadolibre | idx_sku | source_id | 4267993 |
+------------------------+--------------------------------+---------------+---------------+
| t_listing_mercadolibre | idx_source_id_update_time | source_id | 15164 |
+------------------------+--------------------------------+---------------+---------------+
| t_listing_mercadolibre | idx_source_site_status | source_id | 20112 |
+------------------------+--------------------------------+---------------+---------------+
| t_listing_mercadolibre | PRIMARY | id | 8278215 |
+------------------------+--------------------------------+---------------+---------------+
| t_listing_mercadolibre | uk_source_id_country_code_pf_l | source_id | 13723 |
| | isting_logistic_type_platform_ | | |
| | type | | |
+------------------------+--------------------------------+---------------+---------------+
问题2:
数据库:zhcxkj_center_listing_comprehensive
查询时间:14.3059
扫描行数:336699
发送行数:1
指纹SQL: SELECT COUNT ( * ) FROM ? WHERE ( source_id = ? AND country_code = ? AND logistic_type = ? AND status IN ( ? ) ) ;
真实SQL:SELECT COUNT( * ) FROM t_listing_mercadolibre WHERE (source_id = 28058 AND country_code = MLB AND logistic_type = remote AND status IN (3));
王凯,人工修改过
AISQL修改建议:CREATE INDEX idx_listing_optim ON t_listing_mercadolibre(source_id, country_code, logistic_type, status);
explain表:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | t_listing_mercadolibre | None | ref | uk_source_id_country_code_pf_listing_logistic_type_platform_type,idx_status,idx_source_id_update_time,idx_source_site_status | idx_source_site_status | 56 | const,const,const | 618074 | 10 | Using where |
额外建议:
索引建议:
已解决 后续要去掉oder by Id