重现步骤
反馈人:袁慧斌
数据库:zhcxkj-center-warehouse
查询时间:22.222
扫描行数:399.682
发送行数:185.545
指纹SQL: select DISTINCT tb . id from ( SELECT tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id , min ( rfs . is_over ) AS is_over FROM ? tafsi JOIN rb_fba_shipmentdetail rfs ON rfs . shipment_id = tafsi . shipment_id AND rfs . seller_sku = tafsi . msku AND rfs . order_source_id = tafsi . source_id where tafsi . is_completed = ? and tafsi . is_deleted = ? GROUP BY tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id ) tb where tb . is_over = ? ORDER BY tb . id LIMIT ? ;
真实SQL:select DISTINCT tb.id from ( SELECT tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id, min( rfs.is_over ) AS is_over FROM t_amz_fba_shipment_item tafsi JOIN rb_fba_shipmentdetail rfs ON rfs.shipment_id = tafsi.shipment_id AND rfs.seller_sku = tafsi.msku AND rfs.order_source_id = tafsi.source_id where tafsi.is_completed=0 and tafsi.is_deleted = 0 GROUP BY tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id ) tb where tb.is_over=1 ORDER BY tb.id LIMIT 1000;
无人工修改
AISQL修改建议:我帮您优化这个SQL查询,以下是优化后的版本:


SELECT DISTINCT tafsi.id
FROM t_amz_fba_shipment_item tafsi
JOIN (
SELECT shipment_id, seller_sku, order_source_id, MIN(is_over) AS is_over
FROM rb_fba_shipmentdetail
GROUP BY shipment_id, seller_sku, order_source_id
HAVING MIN(is_over) = 1
) rfs ON rfs.shipment_id = tafsi.shipment_id
AND rfs.seller_sku = tafsi.msku
AND rfs.order_source_id = tafsi.source_id
WHERE tafsi.is_completed = 0
AND tafsi.is_deleted = 0
ORDER BY tafsi.id
LIMIT 1000;


这个优化方案做了以下改进:
1. 将子查询中的过滤条件 is_over=1 提前到子查询内部,减少中间结果集
2. 简化了GROUP BY子句,去掉了不必要的字段
3. 直接在主查询中使用DISTINCT而不是在子查询结果上使用
4. 保持了相同的业务逻辑但减少了数据处理的量级
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 192096 100 Using temporary; Using filesort
2 DERIVED tafsi None ref idx_shipment_id,idx_souce_id,idx_msku,idx_is_completed,idx_shipment_id_msku_source_id,idx_source_id_deliverying_time idx_is_completed 2 const 1661362 10 Using where; Using temporary
2 DERIVED rfs None ref idx_shipment_id,idx_shipment_id_seller_sku_order_source_id idx_shipment_id_seller_sku_order_source_id 410 zhcxkj-center-warehouse.tafsi.shipment_id,zhcxkj-center-warehouse.tafsi.msku,zhcxkj-center-warehouse.tafsi.source_id 1 100 Using index condition

额外建议:
索引建议:
取出表 【t_amz_fba_shipment_item】 where条件字段 【is_completed】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。

取出表 【t_amz_fba_shipment_item】 where条件字段 【is_deleted】 100000 条记录,重复的数据有:【99999】 条,没有必要为该字段创建索引。

→ 【t_amz_fba_shipment_item】表 【id】字段,索引已经存在,无需添加任何索引。

【t_amz_fba_shipment_item】表 【id】字段,索引分析:
+-------------------------+--------------+---------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+=========================+==============+===============+===============+
| t_amz_fba_shipment_item | PRIMARY | id | 4798309 |
+-------------------------+--------------+---------------+---------------+

取出表 【rb_fba_shipmentdetail】 where条件字段 【is_over】 100000 条记录,重复的数据有:【99975】 条,没有必要为该字段创建索引。

→ 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,联合索引已经存在,无需添加任何索引。

【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,索引分析:
+-----------------------+--------------------------------+-----------------+---------------+
| TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
+=======================+================================+=================+===============+
| rb_fba_shipmentdetail | idx_shipment_id | shipment_id | 1119473 |
+-----------------------+--------------------------------+-----------------+---------------+
| rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | order_source_id | 6788002 |
| | er_source_id | | |
+-----------------------+--------------------------------+-----------------+---------------+
| rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | shipment_id | 1189995 |
| | er_source_id | | |
+-----------------------+--------------------------------+-----------------+---------------+
| rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | seller_sku | 7322662 |
| | er_source_id | | |
+-----------------------+--------------------------------+-----------------+---------------+


历史记录  
  1. 2025-08-06 12:25:34, 由 陈莉珍 创建。
  2. 2025-08-07 09:16:06, 由 鞠智明 指派给 陈莉珍。
    修改了 指派给,旧值为 "juzhiming",新值为 "chenlizhen"。
    备货仓的
  3. 2025-08-07 20:24:49, 由 陈莉珍 指派给 谢业福。
    修改了 指派给,旧值为 "chenlizhen",新值为 "xieyefu"。
  4. 2025-08-08 14:29:03, 由 谢业福 指派给 陈莉珍。
    修改了 指派给,旧值为 "xieyefu",新值为 "chenlizhen"。
    这个不清楚哪里的业务,不是这边的
  5. 2025-08-08 14:29:36, 由 谢业福 指派给 陈莉珍。
    这个不清楚哪里的业务,不是这边的
  6. 2025-08-11 08:53:03, 由 陈莉珍 解决,方案为 非BUG-纯属误判 。
    修改了 解决方案,旧值为 "",新值为 "feibug"。
    修改了 解决日期,旧值为 "",新值为 "2025-08-11 08:52:51"。
    修改了 Bug状态 ,旧值为 "active",新值为 "resolved"。
    修改了 是否确认,旧值为 "0",新值为 "1"。
    修改了 解决者 ,旧值为 "",新值为 "chenlizhen"。
  7. 2025-08-11 08:53:40, 由 陈莉珍 编辑。
    修改了 所属模块 ,旧值为 "0",新值为 "1863"。
    修改了 业务部门 ,旧值为 "0",新值为 "2"。
    修改了 开发责任人,旧值为 "",新值为 "yuanhuibin"。
    修改了 测试责任人,旧值为 "",新值为 "yuanhuibin"。
    修改了 解决时效 ,旧值为 "0",新值为 "68.45"。
    修改了 重现步骤 ,区别为:
    001- 反馈人:袁慧斌
    001+ 反馈人:袁慧斌 数据库:zhcxkj-center-warehouse 查询时间:22.222 扫描行数:399.682 发送行数:185.545 指纹SQL: select DISTINCT tb . id from ( SELECT tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id , min ( rfs . is_over ) AS is_over FROM ? tafsi JOIN rb_fba_shipmentdetail rfs ON rfs . shipment_id = tafsi . shipment_id AND rfs . seller_sku = tafsi . msku AND rfs . order_source_id = tafsi . source_id where tafsi . is_completed = ? and tafsi . is_deleted = ? GROUP BY tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id ) tb where tb . is_over = ? ORDER BY tb . id LIMIT ? ; 真实SQL:select DISTINCT tb.id from ( SELECT tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id, min( rfs.is_over ) AS is_over FROM t_amz_fba_shipment_item tafsi JOIN rb_fba_shipmentdetail rfs ON rfs.shipment_id = tafsi.shipment_id AND rfs.seller_sku = tafsi.msku AND rfs.order_source_id = tafsi.source_id where tafsi.is_completed=0 and tafsi.is_deleted = 0 GROUP BY tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id ) tb where tb.is_over=1 ORDER BY tb.id LIMIT 1000; 无人工修改 AISQL修改建议:我帮您优化这个SQL查询,以下是优化后的版本: SELECT DISTINCT tafsi.id FROM t_amz_fba_shipment_item tafsi JOIN ( SELECT shipment_id, seller_sku, order_source_id, MIN(is_over) AS is_over FROM rb_fba_shipmentdetail GROUP BY shipment_id, seller_sku, order_source_id HAVING MIN(is_over) = 1 ) rfs ON rfs.shipment_id = tafsi.shipment_id AND rfs.seller_sku = tafsi.msku AND rfs.order_source_id = tafsi.source_id WHERE tafsi.is_completed = 0 AND tafsi.is_deleted = 0 ORDER BY tafsi.id LIMIT 1000; 这个优化方案做了以下改进: 1. 将子查询中的过滤条件 is_over=1 提前到子查询内部,减少中间结果集 2. 简化了GROUP BY子句,去掉了不必要的字段 3. 直接在主查询中使用DISTINCT而不是在子查询结果上使用 4. 保持了相同的业务逻辑但减少了数据处理的量级 explain表:id
    002- 数据库:zhcxkj-center-warehouse
    002+ select_type
    003- 查询时间:22.222
    003+ table
    004- 扫描行数:399.682
    004+ partitions
    005- 发送行数:185.545
    005+ type
    006- 指纹SQL: select DISTINCT tb . id from ( SELECT tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id , min ( rfs . is_over ) AS is_over FROM ? tafsi JOIN rb_fba_shipmentdetail rfs ON rfs . shipment_id = tafsi . shipment_id AND rfs . seller_sku = tafsi . msku AND rfs . order_source_id = tafsi . source_id where tafsi . is_completed = ? and tafsi . is_deleted = ? GROUP BY tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id ) tb where tb . is_over = ? ORDER BY tb . id LIMIT ? ;
    006+ possible_keys
    007- 真实SQL:select DISTINCT tb.id from ( SELECT tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id, min( rfs.is_over ) AS is_over FROM t_amz_fba_shipment_item tafsi JOIN rb_fba_shipmentdetail rfs ON rfs.shipment_id = tafsi.shipment_id AND rfs.seller_sku = tafsi.msku AND rfs.order_source_id = tafsi.source_id where tafsi.is_completed=0 and tafsi.is_deleted = 0 GROUP BY tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id ) tb where tb.is_over=1 ORDER BY tb.id LIMIT 1000;
    007+ key
    008- 无人工修改
    008+ key_len
    009- AISQL修改建议:我帮您优化这个SQL查询,以下是优化后的版本:
    009+ ref
    010-
    010+ rows
    011-
    011+ filtered
    012- SELECT DISTINCT tafsi.id
    012+ Extra
    013- FROM t_amz_fba_shipment_item tafsi
    013+ 1
    014- JOIN (
    014+ PRIMARY
    015- SELECT shipment_id, seller_sku, order_source_id, MIN(is_over) AS is_over
    015+ &lt;derived2&gt;
    016- FROM rb_fba_shipmentdetail
    016+ None
    017- GROUP BY shipment_id, seller_sku, order_source_id
    017+ ALL
    018- HAVING MIN(is_over) = 1
    018+ None
    019- ) rfs ON rfs.shipment_id = tafsi.shipment_id
    019+ None
    020- AND rfs.seller_sku = tafsi.msku
    020+ None
    021- AND rfs.order_source_id = tafsi.source_id
    021+ None
    022- WHERE tafsi.is_completed = 0
    022+ 192096
    023- AND tafsi.is_deleted = 0
    023+ 100
    024- ORDER BY tafsi.id
    024+ Using temporary; Using filesort
    025- LIMIT 1000;
    025+ 2
    026-
    026+ DERIVED
    027-
    027+ tafsi
    028- 这个优化方案做了以下改进:
    028+ None
    029- 1. 将子查询中的过滤条件 is_over=1 提前到子查询内部,减少中间结果集
    029+ ref
    030- 2. 简化了GROUP BY子句,去掉了不必要的字段
    030+ idx_shipment_id,idx_souce_id,idx_msku,idx_is_completed,idx_shipment_id_msku_source_id,idx_source_id_deliverying_time
    031- 3. 直接在主查询中使用DISTINCT而不是在子查询结果上使用
    031+ idx_is_completed
    032- 4. 保持了相同的业务逻辑但减少了数据处理的量级
    032+ 2
    033- explain表:
    033+ const
    034-
    034+ 1661362
    035-
    035+ 10
    036-
    036+ Using where; Using temporary
    037-
    037+ 2
    038-
    038+ DERIVED
    039-
    039+ rfs
    040-
    040+ None
    041-
    041+ ref
    042-
    042+ idx_shipment_id,idx_shipment_id_seller_sku_order_source_id
    043-
    043+ idx_shipment_id_seller_sku_order_source_id
    044-
    044+ 410
    045-
    045+ zhcxkj-center-warehouse.tafsi.shipment_id,zhcxkj-center-warehouse.tafsi.msku,zhcxkj-center-warehouse.tafsi.source_id
    046- id
    046+ 1
    047-
    047+ 100
    048-
    048+ Using index condition
    049- select_type
    049+
    050-
    050+ 额外建议: 索引建议: 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_completed】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_deleted】 100000 条记录,重复的数据有:【99999】 条,没有必要为该字段创建索引。→ 【t_amz_fba_shipment_item】表 【id】字段,索引已经存在,无需添加任何索引。 【t_amz_fba_shipment_item】表 【id】字段,索引分析: +-------------------------+--------------+---------------+---------------+ | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY | +=========================+==============+===============+===============+ | t_amz_fba_shipment_item | PRIMARY | id | 4798309 | +-------------------------+--------------+---------------+---------------+ 取出表 【rb_fba_shipmentdetail】 where条件字段 【is_over】 100000 条记录,重复的数据有:【99975】 条,没有必要为该字段创建索引。→ 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,联合索引已经存在,无需添加任何索引。 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,索引分析: +-----------------------+--------------------------------+-----------------+---------------+ | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY | +=======================+================================+=================+===============+ | rb_fba_shipmentdetail | idx_shipment_id | shipment_id | 1119473 | +-----------------------+--------------------------------+-----------------+---------------+ | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | order_source_id | 6788002 | | | er_source_id | | | +-----------------------+--------------------------------+-----------------+---------------+ | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | shipment_id | 1189995 | | | er_source_id | | | +-----------------------+--------------------------------+-----------------+---------------+ | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | seller_sku | 7322662 | | | er_source_id | | | +-----------------------+--------------------------------+-----------------+---------------+
    051-
    052- table
    053-
    054-
    055- partitions
    056-
    057-
    058- type
    059-
    060-
    061- possible_keys
    062-
    063-
    064- key
    065-
    066-
    067- key_len
    068-
    069-
    070- ref
    071-
    072-
    073- rows
    074-
    075-
    076- filtered
    077-
    078-
    079- Extra
    080-
    081-
    082-
    083-
    084-
    085-
    086- 1
    087-
    088-
    089- PRIMARY
    090-
    091-
    092- &lt;derived2&gt;
    093-
    094-
    095- None
    096-
    097-
    098- ALL
    099-
    100-
    101- None
    102-
    103-
    104- None
    105-
    106-
    107- None
    108-
    109-
    110- None
    111-
    112-
    113- 192096
    114-
    115-
    116- 100
    117-
    118-
    119- Using temporary; Using filesort
    120-
    121-
    122-
    123-
    124- 2
    125-
    126-
    127- DERIVED
    128-
    129-
    130- tafsi
    131-
    132-
    133- None
    134-
    135-
    136- ref
    137-
    138-
    139- idx_shipment_id,idx_souce_id,idx_msku,idx_is_completed,idx_shipment_id_msku_source_id,idx_source_id_deliverying_time
    140-
    141-
    142- idx_is_completed
    143-
    144-
    145- 2
    146-
    147-
    148- const
    149-
    150-
    151- 1661362
    152-
    153-
    154- 10
    155-
    156-
    157- Using where; Using temporary
    158-
    159-
    160-
    161-
    162- 2
    163-
    164-
    165- DERIVED
    166-
    167-
    168- rfs
    169-
    170-
    171- None
    172-
    173-
    174- ref
    175-
    176-
    177- idx_shipment_id,idx_shipment_id_seller_sku_order_source_id
    178-
    179-
    180- idx_shipment_id_seller_sku_order_source_id
    181-
    182-
    183- 410
    184-
    185-
    186- zhcxkj-center-warehouse.tafsi.shipment_id,zhcxkj-center-warehouse.tafsi.msku,zhcxkj-center-warehouse.tafsi.source_id
    187-
    188-
    189- 1
    190-
    191-
    192- 100
    193-
    194-
    195- Using index condition
    196-
    197-
    198-
    199-
    200-
    201- 额外建议:
    202- 索引建议:
    203- 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_completed】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。
    204-
    205- 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_deleted】 100000 条记录,重复的数据有:【99999】 条,没有必要为该字段创建索引。
    206-
    207- → 【t_amz_fba_shipment_item】表 【id】字段,索引已经存在,无需添加任何索引。
    208-
    209- 【t_amz_fba_shipment_item】表 【id】字段,索引分析:
    210- +-------------------------+--------------+---------------+---------------+
    211- | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
    212- +=========================+==============+===============+===============+
    213- | t_amz_fba_shipment_item | PRIMARY | id | 4798309 |
    214- +-------------------------+--------------+---------------+---------------+
    215-
    216- 取出表 【rb_fba_shipmentdetail】 where条件字段 【is_over】 100000 条记录,重复的数据有:【99975】 条,没有必要为该字段创建索引。
    217-
    218- → 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,联合索引已经存在,无需添加任何索引。
    219-
    220- 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,索引分析:
    221- +-----------------------+--------------------------------+-----------------+---------------+
    222- | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |
    223- +=======================+================================+=================+===============+
    224- | rb_fba_shipmentdetail | idx_shipment_id | shipment_id | 1119473 |
    225- +-----------------------+--------------------------------+-----------------+---------------+
    226- | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | order_source_id | 6788002 |
    227- | | er_source_id | | |
    228- +-----------------------+--------------------------------+-----------------+---------------+
    229- | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | shipment_id | 1189995 |
    230- | | er_source_id | | |
    231- +-----------------------+--------------------------------+-----------------+---------------+
    232- | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | seller_sku | 7322662 |
    233- | | er_source_id | | |
    234- +-----------------------+--------------------------------+-----------------+---------------+
    235-
    236-
    001- 反馈人:袁慧斌<br />
    001+ 反馈人:袁慧斌<br /> 数据库:zhcxkj-center-warehouse<br /> 查询时间:22.222<br /> 扫描行数:399.682<br /> 发送行数:185.545<br /> 指纹SQL: select DISTINCT tb . id from ( SELECT tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id , min ( rfs . is_over ) AS is_over FROM ? tafsi JOIN rb_fba_shipmentdetail rfs ON rfs . shipment_id = tafsi . shipment_id AND rfs . seller_sku = tafsi . msku AND rfs . order_source_id = tafsi . source_id where tafsi . is_completed = ? and tafsi . is_deleted = ? GROUP BY tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id ) tb where tb . is_over = ? ORDER BY tb . id LIMIT ? ;<br /> 真实SQL:select DISTINCT tb.id from ( SELECT tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id, min( rfs.is_over ) AS is_over FROM t_amz_fba_shipment_item tafsi JOIN rb_fba_shipmentdetail rfs ON rfs.shipment_id = tafsi.shipment_id AND rfs.seller_sku = tafsi.msku AND rfs.order_source_id = tafsi.source_id where tafsi.is_completed=0 and tafsi.is_deleted = 0 GROUP BY tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id ) tb where tb.is_over=1 ORDER BY tb.id LIMIT 1000;<br /> 无人工修改<br /> AISQL修改建议:我帮您优化这个SQL查询,以下是优化后的版本:<br /><br /><br /> SELECT DISTINCT tafsi.id<br /> FROM t_amz_fba_shipment_item tafsi<br /> JOIN (<br /> SELECT shipment_id, seller_sku, order_source_id, MIN(is_over) AS is_over<br /> FROM rb_fba_shipmentdetail<br /> GROUP BY shipment_id, seller_sku, order_source_id<br /> HAVING MIN(is_over) = 1<br /> ) rfs ON rfs.shipment_id = tafsi.shipment_id<br /> AND rfs.seller_sku = tafsi.msku<br /> AND rfs.order_source_id = tafsi.source_id<br /> WHERE tafsi.is_completed = 0<br /> AND tafsi.is_deleted = 0<br /> ORDER BY tafsi.id<br /> LIMIT 1000;<br /><br /><br /> 这个优化方案做了以下改进:<br /> 1. 将子查询中的过滤条件 is_over=1 提前到子查询内部,减少中间结果集<br /> 2. 简化了GROUP BY子句,去掉了不必要的字段<br /> 3. 直接在主查询中使用DISTINCT而不是在子查询结果上使用<br /> 4. 保持了相同的业务逻辑但减少了数据处理的量级<br /> explain表:<br /><br /><br /><br /><br /><br /><br /><br /><br /><table><tbody><tr><th>id</th>
    002- 数据库:zhcxkj-center-warehouse<br />
    002+ <th>select_type</th>
    003- 查询时间:22.222<br />
    003+ <th>table</th>
    004- 扫描行数:399.682<br />
    004+ <th>partitions</th>
    005- 发送行数:185.545<br />
    005+ <th>type</th>
    006- 指纹SQL: select DISTINCT tb . id from ( SELECT tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id , min ( rfs . is_over ) AS is_over FROM ? tafsi JOIN rb_fba_shipmentdetail rfs ON rfs . shipment_id = tafsi . shipment_id AND rfs . seller_sku = tafsi . msku AND rfs . order_source_id = tafsi . source_id where tafsi . is_completed = ? and tafsi . is_deleted = ? GROUP BY tafsi . id , rfs . shipment_id , rfs . seller_sku , rfs . order_source_id ) tb where tb . is_over = ? ORDER BY tb . id LIMIT ? ;<br />
    006+ <th>possible_keys</th>
    007- 真实SQL:select DISTINCT tb.id from ( SELECT tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id, min( rfs.is_over ) AS is_over FROM t_amz_fba_shipment_item tafsi JOIN rb_fba_shipmentdetail rfs ON rfs.shipment_id = tafsi.shipment_id AND rfs.seller_sku = tafsi.msku AND rfs.order_source_id = tafsi.source_id where tafsi.is_completed=0 and tafsi.is_deleted = 0 GROUP BY tafsi.id, rfs.shipment_id, rfs.seller_sku, rfs.order_source_id ) tb where tb.is_over=1 ORDER BY tb.id LIMIT 1000;<br />
    007+ <th>key</th>
    008- 无人工修改<br />
    008+ <th>key_len</th>
    009- AISQL修改建议:我帮您优化这个SQL查询,以下是优化后的版本:<br />
    009+ <th>ref</th>
    010- <br />
    010+ <th>rows</th>
    011- <br />
    011+ <th>filtered</th>
    012- SELECT DISTINCT tafsi.id<br />
    012+ <th>Extra</th>
    013- FROM t_amz_fba_shipment_item tafsi<br />
    013+ </tr></tbody><tbody><tr><td>1</td>
    014- JOIN (<br />
    014+ <td>PRIMARY</td>
    015- SELECT shipment_id, seller_sku, order_source_id, MIN(is_over) AS is_over<br />
    015+ <td>&lt;derived2&gt;</td>
    016- FROM rb_fba_shipmentdetail<br />
    016+ <td>None</td>
    017- GROUP BY shipment_id, seller_sku, order_source_id<br />
    017+ <td>ALL</td>
    018- HAVING MIN(is_over) = 1<br />
    018+ <td>None</td>
    019- ) rfs ON rfs.shipment_id = tafsi.shipment_id<br />
    019+ <td>None</td>
    020- AND rfs.seller_sku = tafsi.msku<br />
    020+ <td>None</td>
    021- AND rfs.order_source_id = tafsi.source_id<br />
    021+ <td>None</td>
    022- WHERE tafsi.is_completed = 0<br />
    022+ <td>192096</td>
    023- AND tafsi.is_deleted = 0<br />
    023+ <td>100</td>
    024- ORDER BY tafsi.id<br />
    024+ <td>Using temporary; Using filesort</td>
    025- LIMIT 1000;<br />
    025+ </tr><tr><td>2</td>
    026- <br />
    026+ <td>DERIVED</td>
    027- <br />
    027+ <td>tafsi</td>
    028- 这个优化方案做了以下改进:<br />
    028+ <td>None</td>
    029- 1. 将子查询中的过滤条件 is_over=1 提前到子查询内部,减少中间结果集<br />
    029+ <td>ref</td>
    030- 2. 简化了GROUP BY子句,去掉了不必要的字段<br />
    030+ <td>idx_shipment_id,idx_souce_id,idx_msku,idx_is_completed,idx_shipment_id_msku_source_id,idx_source_id_deliverying_time</td>
    031- 3. 直接在主查询中使用DISTINCT而不是在子查询结果上使用<br />
    031+ <td>idx_is_completed</td>
    032- 4. 保持了相同的业务逻辑但减少了数据处理的量级<br />
    032+ <td>2</td>
    033- explain表:<br />
    033+ <td>const</td>
    034- <br />
    034+ <td>1661362</td>
    035- <br />
    035+ <td>10</td>
    036- <br />
    036+ <td>Using where; Using temporary</td>
    037- <br />
    037+ </tr><tr><td>2</td>
    038- <br />
    038+ <td>DERIVED</td>
    039- <br />
    039+ <td>rfs</td>
    040- <br />
    040+ <td>None</td>
    041- <br />
    041+ <td>ref</td>
    042- <table>
    042+ <td>idx_shipment_id,idx_shipment_id_seller_sku_order_source_id</td>
    043- <tbody>
    043+ <td>idx_shipment_id_seller_sku_order_source_id</td>
    044- <tr>
    044+ <td>410</td>
    045- <th>
    045+ <td>zhcxkj-center-warehouse.tafsi.shipment_id,zhcxkj-center-warehouse.tafsi.msku,zhcxkj-center-warehouse.tafsi.source_id</td>
    046- id
    046+ <td>1</td>
    047- </th>
    047+ <td>100</td>
    048- <th>
    048+ <td>Using index condition</td>
    049- select_type
    049+ </tr></tbody></table><br />
    050- </th>
    050+ 额外建议:<br /> 索引建议:<br /> 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_completed】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。<br /><br /> 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_deleted】 100000 条记录,重复的数据有:【99999】 条,没有必要为该字段创建索引。<br /><br /><span style="color:#008000;font-weight:bold;">→ 【t_amz_fba_shipment_item】表 【id】字段,索引已经存在,无需添加任何索引。</span><br /><br /> 【t_amz_fba_shipment_item】表 【id】字段,索引分析:<br /> +-------------------------+--------------+---------------+---------------+<br /> | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |<br /> +=========================+==============+===============+===============+<br /> | t_amz_fba_shipment_item | PRIMARY | id | 4798309 |<br /> +-------------------------+--------------+---------------+---------------+<br /><br /> 取出表 【rb_fba_shipmentdetail】 where条件字段 【is_over】 100000 条记录,重复的数据有:【99975】 条,没有必要为该字段创建索引。<br /><br /><span style="color:#008000;font-weight:bold;">→ 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,联合索引已经存在,无需添加任何索引。</span><br /><br /> 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,索引分析:<br /> +-----------------------+--------------------------------+-----------------+---------------+<br /> | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |<br /> +=======================+================================+=================+===============+<br /> | rb_fba_shipmentdetail | idx_shipment_id | shipment_id | 1119473 |<br /> +-----------------------+--------------------------------+-----------------+---------------+<br /> | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | order_source_id | 6788002 |<br /> | | er_source_id | | |<br /> +-----------------------+--------------------------------+-----------------+---------------+<br /> | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | shipment_id | 1189995 |<br /> | | er_source_id | | |<br /> +-----------------------+--------------------------------+-----------------+---------------+<br /> | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | seller_sku | 7322662 |<br /> | | er_source_id | | |<br /> +-----------------------+--------------------------------+-----------------+---------------+<br /><br /><br />
    051- <th>
    052- table
    053- </th>
    054- <th>
    055- partitions
    056- </th>
    057- <th>
    058- type
    059- </th>
    060- <th>
    061- possible_keys
    062- </th>
    063- <th>
    064- key
    065- </th>
    066- <th>
    067- key_len
    068- </th>
    069- <th>
    070- ref
    071- </th>
    072- <th>
    073- rows
    074- </th>
    075- <th>
    076- filtered
    077- </th>
    078- <th>
    079- Extra
    080- </th>
    081- </tr>
    082- </tbody>
    083- <tbody>
    084- <tr>
    085- <td>
    086- 1
    087- </td>
    088- <td>
    089- PRIMARY
    090- </td>
    091- <td>
    092- &lt;derived2&gt;
    093- </td>
    094- <td>
    095- None
    096- </td>
    097- <td>
    098- ALL
    099- </td>
    100- <td>
    101- None
    102- </td>
    103- <td>
    104- None
    105- </td>
    106- <td>
    107- None
    108- </td>
    109- <td>
    110- None
    111- </td>
    112- <td>
    113- 192096
    114- </td>
    115- <td>
    116- 100
    117- </td>
    118- <td>
    119- Using temporary; Using filesort
    120- </td>
    121- </tr>
    122- <tr>
    123- <td>
    124- 2
    125- </td>
    126- <td>
    127- DERIVED
    128- </td>
    129- <td>
    130- tafsi
    131- </td>
    132- <td>
    133- None
    134- </td>
    135- <td>
    136- ref
    137- </td>
    138- <td>
    139- idx_shipment_id,idx_souce_id,idx_msku,idx_is_completed,idx_shipment_id_msku_source_id,idx_source_id_deliverying_time
    140- </td>
    141- <td>
    142- idx_is_completed
    143- </td>
    144- <td>
    145- 2
    146- </td>
    147- <td>
    148- const
    149- </td>
    150- <td>
    151- 1661362
    152- </td>
    153- <td>
    154- 10
    155- </td>
    156- <td>
    157- Using where; Using temporary
    158- </td>
    159- </tr>
    160- <tr>
    161- <td>
    162- 2
    163- </td>
    164- <td>
    165- DERIVED
    166- </td>
    167- <td>
    168- rfs
    169- </td>
    170- <td>
    171- None
    172- </td>
    173- <td>
    174- ref
    175- </td>
    176- <td>
    177- idx_shipment_id,idx_shipment_id_seller_sku_order_source_id
    178- </td>
    179- <td>
    180- idx_shipment_id_seller_sku_order_source_id
    181- </td>
    182- <td>
    183- 410
    184- </td>
    185- <td>
    186- zhcxkj-center-warehouse.tafsi.shipment_id,zhcxkj-center-warehouse.tafsi.msku,zhcxkj-center-warehouse.tafsi.source_id
    187- </td>
    188- <td>
    189- 1
    190- </td>
    191- <td>
    192- 100
    193- </td>
    194- <td>
    195- Using index condition
    196- </td>
    197- </tr>
    198- </tbody>
    199- </table>
    200- <br />
    201- 额外建议:<br />
    202- 索引建议:<br />
    203- 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_completed】 100000 条记录,重复的数据有:【100000】 条,没有必要为该字段创建索引。<br />
    204- <br />
    205- 取出表 【t_amz_fba_shipment_item】 where条件字段 【is_deleted】 100000 条记录,重复的数据有:【99999】 条,没有必要为该字段创建索引。<br />
    206- <br />
    207- <span style="color:green;font-weight:bold;">→ 【t_amz_fba_shipment_item】表 【id】字段,索引已经存在,无需添加任何索引。</span><br />
    208- <br />
    209- 【t_amz_fba_shipment_item】表 【id】字段,索引分析:<br />
    210- +-------------------------+--------------+---------------+---------------+<br />
    211- | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |<br />
    212- +=========================+==============+===============+===============+<br />
    213- | t_amz_fba_shipment_item | PRIMARY | id | 4798309 |<br />
    214- +-------------------------+--------------+---------------+---------------+<br />
    215- <br />
    216- 取出表 【rb_fba_shipmentdetail】 where条件字段 【is_over】 100000 条记录,重复的数据有:【99975】 条,没有必要为该字段创建索引。<br />
    217- <br />
    218- <span style="color:green;font-weight:bold;">→ 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,联合索引已经存在,无需添加任何索引。</span><br />
    219- <br />
    220- 【rb_fba_shipmentdetail】表 【shipment_id,seller_sku,order_source_id】字段,索引分析:<br />
    221- +-----------------------+--------------------------------+-----------------+---------------+<br />
    222- | TABLE_NAME | INDEX_NAME | COLUMN_NAME | CARDINALITY |<br />
    223- +=======================+================================+=================+===============+<br />
    224- | rb_fba_shipmentdetail | idx_shipment_id | shipment_id | 1119473 |<br />
    225- +-----------------------+--------------------------------+-----------------+---------------+<br />
    226- | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | order_source_id | 6788002 |<br />
    227- | | er_source_id | | |<br />
    228- +-----------------------+--------------------------------+-----------------+---------------+<br />
    229- | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | shipment_id | 1189995 |<br />
    230- | | er_source_id | | |<br />
    231- +-----------------------+--------------------------------+-----------------+---------------+<br />
    232- | rb_fba_shipmentdetail | idx_shipment_id_seller_sku_ord | seller_sku | 7322662 |<br />
    233- | | er_source_id | | |<br />
    234- +-----------------------+--------------------------------+-----------------+---------------+<br />
    235- <br />
    236- <br />
  8. 2025-08-11 08:53:43, 由 陈莉珍 关闭。
    修改了 Bug状态 ,旧值为 "resolved",新值为 "closed"。
    修改了 指派给 ,旧值为 "chenlizhen",新值为 "closed"。
    修改了 由谁关闭,旧值为 "",新值为 "chenlizhen"。
    修改了 关闭日期,旧值为 "",新值为 "2025-08-11 08:53:43"。
所属项目 技术中心-需求池
所属模块 系统运维   性能优化
所属计划
所属迭代
Bug类型
严重程度 一般
优先级 P2
Bug状态 已关闭
业务部门 总经办
影响功能
开发责任人 袁慧斌
测试责任人 袁慧斌
解决时效 68.45
激活次数 0
激活日期
是否确认 是
当前指派 Closed 于 2025-08-11 08:53:43
截止日期 0000-00-00
上线时间 2025-08-07 09:00:00
上线时效 20.57
操作系统
浏览器
关键词
抄送给
所属迭代
相关需求
相关任务
由谁创建 陈莉珍 于 2025-08-06 12:25:34
影响环境 生产环境-业务反馈
由谁解决 陈莉珍 于 2025-08-11 08:52:51
解决版本
解决方案 非BUG-纯属误判
由谁关闭 陈莉珍 于 2025-08-11 08:53:43
最后修改 陈莉珍 于 2025-08-11 08:53:43
相关Bug