数据库:zhcxkj_center_listing_comprehensive
查询时间:429.661
执行次数: 28
扫描行数:851453
发送行数:851453
指纹SQL: select id , customer_id , source_id , source_name , name , name_cn , gtin , spu , sku , item_id , source_sku , main_image , platform_category_id , platform_category_name , brand_id , brand , publish_status , status , product_state , tort , upc , sale_price , purchase_price , original_price , days_to_ship , first_publish_time , primary_variant , has_variant , has_new , description_type , default_local_warehouse , currency , country_code , remark , create_by , create_time , update_by , update_time , is_deleted , salesman_id , salesman , listing_person , fulfillment_type , template_id , template_name , freight_price , average_rating , transit_time , fist_online_time , is_no_sale , has_law_firm_agent , ship_methods FROM ? force index ( idx_update_time ) where ( update_time < replace ( ? , ? , ? ) AND update_time >= DATE_SUB ( replace ( ? , ? , ? ) , INTERVAL ? MINUTE ) ) ;
真实SQL:select id,customer_id,source_id,source_name,name,name_cn,gtin,spu,sku,item_id,source_sku,main_image,platform_category_id,platform_category_name,brand_id,brand,publish_status,status,product_state,tort,upc,sale_price,purchase_price,original_price,days_to_ship,first_publish_time,primary_variant,has_variant,has_new,description_type,default_local_warehouse,currency,country_code,remark,create_by,create_time,update_by,update_time,is_deleted,salesman_id,salesman,listing_person,fulfillment_type,template_id,template_name,freight_price,average_rating,transit_time,fist_online_time,is_no_sale,has_law_firm_agent,ship_methods from t_walmart_listing force index(idx_update_time) where (update_time= DATE_SUB(replace(2025-09-07 03:30:00,%, ),INTERVAL 5 MINUTE));
无人工修改
AISQL修改建议:以下是优化后的SQL语句:
SELECT id, customer_id, source_id, source_name, name, name_cn, gtin, spu, sku, item_id, source_sku, main_image, platform_category_id, platform_category_name, brand_id, brand, publish_status, status, product_state, tort, upc, sale_price, purchase_price, original_price, days_to_ship, first_publish_time, primary_variant, has_variant, has_new, description_type, default_local_warehouse, currency, country_code, remark, create_by, create_time, update_by, update_time, is_deleted, salesman_id, salesman, listing_person, fulfillment_type, template_id, template_name, freight_price, average_rating, transit_time, fist_online_time, is_no_sale, has_law_firm_agent, ship_methods
FROM t_walmart_listing
WHERE update_time >= DATE_SUB(2025-09-07 03:30:00, INTERVAL 5 MINUTE)
AND update_time < 2025-09-07 04:00:02;
优化说明:
1. 移除了不必要的replace()函数调用,直接使用日期字符串
2. 将两个时间条件合并到同一行,减少解析开销
3. 移除了FORCE INDEX提示,让优化器自行选择合适的索引(除非有明确证据表明强制索引能提升性能)
如果update_time字段已建立索引,这个查询应该能高效执行。如需进一步优化,可以考虑:
- 确保update_time字段有适当的索引
- 如果只查询部分字段,可以减少SELECT列表中的字段数量
explain表:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SIMPLE | t_walmart_listing | None | range | idx_update_time | idx_update_time | 5 | None | 11468 | 100 | Using index condition |
额外建议:
索引建议:
→ 【t_walmart_listing】表 【update_time】字段,索引已经存在,无需添加任何索引。
【t_walmart_listing】表 【update_time】字段,索引分析:
+-------------------+--------------------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+===================+==========================+===============+===============+
| t_walmart_listing | idx_sourceid_update_time | update_time | 1963251 |
+-------------------+--------------------------+---------------+---------------+
| t_walmart_listing | idx_update_time | update_time | 470805 |
+-------------------+--------------------------+---------------+---------------+
(2025-09-07>
