重现步骤

反馈人:李冠

仓库慢SQL,由于使用函数DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)造成索引idx_addTime_isStockOrder不命中

慢SQL为:

select a.order_code,b.id as orderListId,b.lock_num,b.pending_move_number,b.put_in_num from t_stk_order_info a         join t_stk_order_list b on b.order_code=a.order_code and b.customer_id=a.customer_id         where a.add_time >= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)         AND a.order_state IN (0,1)         AND a.order_status=0         AND a.is_stock_order = 1         AND b.purchase_type  <  2         AND b.lock_num > 0         AND (b.product_num + IFNULL(b.product_num_update,0))>0         AND b.lock_num-b.put_in_num>0         and not exists(         select 1 from rb_waitingmoving_orderdetail where order_code=a.order_code  and customer_id=a.customer_id and IFNULL(waiting_move_state,0)=0         );

解决方案:DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)   这个时间调整为代码中生成,直接以参数方式传入,如:


SELECT

 a.order_code,

 b.id AS orderListId,

 b.lock_num,

 b.pending_move_number,

 b.put_in_num

FROM

 t_stk_order_info a

 JOIN t_stk_order_list b ON b.order_code = a.order_code

 AND b.customer_id = a.customer_id

WHERE

 a.add_time >= 2025-10-15 05:28:00

 AND a.order_state IN (0, 1)

 AND a.order_status = 0

 AND a.is_stock_order = 1

 AND b.purchase_type < 2

 AND b.lock_num > 0

 AND (b.product_num + IFNULL(b.product_num_update, 0)) > 0

 AND b.lock_num - b.put_in_num > 0

 AND NOT EXISTS (SELECT 1 FROM rb_waitingmoving_orderdetail WHERE order_code = a.order_code AND customer_id = a.customer_id AND IFNULL(waiting_move_state, 0) = 0);


其他类似的SQL,建议一样优化,以及在团队中强调,避免再次出现类似的性能SQL

历史记录  
  1. 2025-10-16 09:02:03, 由 陈莉珍 创建。
  2. 2025-10-16 09:36:01, 由 程伟 指派给 唐飞飞。
    修改了 指派给,旧值为 "chengwei",新值为 "tangfeifei"。
  3. 2025-10-16 15:45:32, 由 唐飞飞 解决,方案为 性能问题 。
    修改了 解决方案,旧值为 "",新值为 "performance"。
    修改了 解决版本,旧值为 "",新值为 "trunk"。
    修改了 解决日期,旧值为 "",新值为 "2025-10-16 15:33:19"。
    修改了 指派给 ,旧值为 "tangfeifei",新值为 "chenlizhen"。
    修改了 Bug状态 ,旧值为 "active",新值为 "resolved"。
    修改了 是否确认,旧值为 "0",新值为 "1"。
    修改了 解决者 ,旧值为 "",新值为 "tangfeifei"。

    处理涉及功能:

      1、移库任务自动生成服务

      2、移库任务手动生成

    处理后的结果:

     可正常生成移库任务

     1、移库任务自动生成服务


     2、移库任务手动生成



  4. 2025-10-17 10:50:10, 由 陈莉珍 编辑。
    修改了 所属模块 ,旧值为 "0",新值为 "1932"。
    修改了 业务部门 ,旧值为 "0",新值为 "2"。
    修改了 测试责任人,旧值为 "",新值为 "tangfeifei"。
    修改了 解决时效 ,旧值为 "0",新值为 "6.52"。
    修改了 重现步骤 ,区别为:
    001-
    001+ 反馈人:李冠
    002- 反馈人:李冠
    002+ 仓库慢SQL,由于使用函数DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)造成索引idx_addTime_isStockOrder不命中
    003-
    003+ 慢SQL为:
    004-
    004+ select a.order_code,b.id as orderListId,b.lock_num,b.pending_move_number,b.put_in_num from t_stk_order_info a join t_stk_order_list b on b.order_code=a.order_code and b.customer_id=a.customer_id where a.add_time &gt;= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) AND a.order_state IN (0,1) AND a.order_status=0 AND a.is_stock_order = 1 AND b.purchase_type &lt; 2 AND b.lock_num &gt; 0 AND (b.product_num + IFNULL(b.product_num_update,0))&gt;0 AND b.lock_num-b.put_in_num&gt;0 and not exists( select 1 from rb_waitingmoving_orderdetail where order_code=a.order_code and customer_id=a.customer_id and IFNULL(waiting_move_state,0)=0 );
    005- 仓库慢SQL,由于使用函数DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)造成索引idx_addTime_isStockOrder不命中
    005+ 解决方案:DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) 这个时间调整为代码中生成,直接以参数方式传入,如:
    006-
    006+
    007-
    007+ SELECT
    008- 慢SQL为:
    008+ a.order_code,
    009-
    009+ b.id AS orderListId,
    010-
    010+ b.lock_num,
    011- select a.order_code,b.id as orderListId,b.lock_num,b.pending_move_number,b.put_in_num from t_stk_order_info a join t_stk_order_list b on b.order_code=a.order_code and b.customer_id=a.customer_id where a.add_time &gt;= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) AND a.order_state IN (0,1) AND a.order_status=0 AND a.is_stock_order = 1 AND b.purchase_type &lt; 2 AND b.lock_num &gt; 0 AND (b.product_num + IFNULL(b.product_num_update,0))&gt;0 AND b.lock_num-b.put_in_num&gt;0 and not exists( select 1 from rb_waitingmoving_orderdetail where order_code=a.order_code and customer_id=a.customer_id and IFNULL(waiting_move_state,0)=0 );
    011+ b.pending_move_number,
    012-
    012+ b.put_in_num
    013-
    013+ FROM
    014- 解决方案:DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) 这个时间调整为代码中生成,直接以参数方式传入,如:
    014+ t_stk_order_info a
    015-
    015+ JOIN t_stk_order_list b ON b.order_code = a.order_code
    016-
    016+ AND b.customer_id = a.customer_id
    017-
    017+ WHERE
    018-
    018+ a.add_time &gt;= 2025-10-15 05:28:00
    019-
    019+ AND a.order_state IN (0, 1)
    020- SELECT
    020+ AND a.order_status = 0
    021-
    021+ AND a.is_stock_order = 1
    022-
    022+ AND b.purchase_type &lt; 2
    023- a.order_code,
    023+ AND b.lock_num &gt; 0
    024-
    024+ AND (b.product_num + IFNULL(b.product_num_update, 0)) &gt; 0
    025-
    025+ AND b.lock_num - b.put_in_num &gt; 0
    026- b.id AS orderListId,
    026+ AND NOT EXISTS (SELECT 1 FROM rb_waitingmoving_orderdetail WHERE order_code = a.order_code AND customer_id = a.customer_id AND IFNULL(waiting_move_state, 0) = 0);
    027-
    027+
    028-
    028+ 其他类似的SQL,建议一样优化,以及在团队中强调,避免再次出现类似的性能SQL
    029- b.lock_num,
    030-
    031-
    032- b.pending_move_number,
    033-
    034-
    035- b.put_in_num
    036-
    037-
    038- FROM
    039-
    040-
    041- t_stk_order_info a
    042-
    043-
    044- JOIN t_stk_order_list b ON b.order_code = a.order_code
    045-
    046-
    047- AND b.customer_id = a.customer_id
    048-
    049-
    050- WHERE
    051-
    052-
    053- a.add_time &gt;= 2025-10-15 05:28:00
    054-
    055-
    056- AND a.order_state IN (0, 1)
    057-
    058-
    059- AND a.order_status = 0
    060-
    061-
    062- AND a.is_stock_order = 1
    063-
    064-
    065- AND b.purchase_type &lt; 2
    066-
    067-
    068- AND b.lock_num &gt; 0
    069-
    070-
    071- AND (b.product_num + IFNULL(b.product_num_update, 0)) &gt; 0
    072-
    073-
    074- AND b.lock_num - b.put_in_num &gt; 0
    075-
    076-
    077- AND NOT EXISTS (SELECT 1 FROM rb_waitingmoving_orderdetail WHERE order_code = a.order_code AND customer_id = a.customer_id AND IFNULL(waiting_move_state, 0) = 0);
    078-
    079-
    080-
    081-
    082-
    083- 其他类似的SQL,建议一样优化,以及在团队中强调,避免再次出现类似的性能SQL
    084-
    085-
    001- <p>
    001+ <p>反馈人:李冠</p>
    002- 反馈人:李冠
    002+ <p>仓库慢SQL,由于使用函数DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)造成索引idx_addTime_isStockOrder不命中</p>
    003- </p>
    003+ <p>慢SQL为:</p>
    004- <p>
    004+ <p>select a.order_code,b.id as orderListId,b.lock_num,b.pending_move_number,b.put_in_num from t_stk_order_info a join t_stk_order_list b on b.order_code=a.order_code and b.customer_id=a.customer_id where a.add_time &gt;= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) AND a.order_state IN (0,1) AND a.order_status=0 AND a.is_stock_order = 1 AND b.purchase_type &lt; 2 AND b.lock_num &gt; 0 AND (b.product_num + IFNULL(b.product_num_update,0))&gt;0 AND b.lock_num-b.put_in_num&gt;0 and not exists( select 1 from rb_waitingmoving_orderdetail where order_code=a.order_code and customer_id=a.customer_id and IFNULL(waiting_move_state,0)=0 );</p>
    005- 仓库慢SQL,由于使用函数DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH)造成索引idx_addTime_isStockOrder不命中
    005+ <p>解决方案:DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) 这个时间调整为代码中生成,直接以参数方式传入,如:</p>
    006- </p>
    006+ <p><br /></p>
    007- <p>
    007+ <p>SELECT</p>
    008- 慢SQL为:
    008+ <p>a.order_code,</p>
    009- </p>
    009+ <p>b.id AS orderListId,</p>
    010- <p>
    010+ <p>b.lock_num,</p>
    011- select a.order_code,b.id as orderListId,b.lock_num,b.pending_move_number,b.put_in_num from t_stk_order_info a join t_stk_order_list b on b.order_code=a.order_code and b.customer_id=a.customer_id where a.add_time &gt;= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) AND a.order_state IN (0,1) AND a.order_status=0 AND a.is_stock_order = 1 AND b.purchase_type &lt; 2 AND b.lock_num &gt; 0 AND (b.product_num + IFNULL(b.product_num_update,0))&gt;0 AND b.lock_num-b.put_in_num&gt;0 and not exists( select 1 from rb_waitingmoving_orderdetail where order_code=a.order_code and customer_id=a.customer_id and IFNULL(waiting_move_state,0)=0 );
    011+ <p>b.pending_move_number,</p>
    012- </p>
    012+ <p>b.put_in_num</p>
    013- <p>
    013+ <p>FROM</p>
    014- 解决方案:DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -12 MONTH) 这个时间调整为代码中生成,直接以参数方式传入,如:
    014+ <p>t_stk_order_info a</p>
    015- </p>
    015+ <p>JOIN t_stk_order_list b ON b.order_code = a.order_code</p>
    016- <p>
    016+ <p>AND b.customer_id = a.customer_id</p>
    017- <br />
    017+ <p>WHERE</p>
    018- </p>
    018+ <p>a.add_time &gt;= 2025-10-15 05:28:00</p>
    019- <p>
    019+ <p>AND a.order_state IN (0, 1)</p>
    020- SELECT
    020+ <p>AND a.order_status = 0</p>
    021- </p>
    021+ <p>AND a.is_stock_order = 1</p>
    022- <p>
    022+ <p>AND b.purchase_type &lt; 2</p>
    023- a.order_code,
    023+ <p>AND b.lock_num &gt; 0</p>
    024- </p>
    024+ <p>AND (b.product_num + IFNULL(b.product_num_update, 0)) &gt; 0</p>
    025- <p>
    025+ <p>AND b.lock_num - b.put_in_num &gt; 0</p>
    026- b.id AS orderListId,
    026+ <p>AND NOT EXISTS (SELECT 1 FROM rb_waitingmoving_orderdetail WHERE order_code = a.order_code AND customer_id = a.customer_id AND IFNULL(waiting_move_state, 0) = 0);</p>
    027- </p>
    027+ <p><br /></p>
    028- <p>
    028+ <p>其他类似的SQL,建议一样优化,以及在团队中强调,避免再次出现类似的性能SQL</p>
    029- b.lock_num,
    030- </p>
    031- <p>
    032- b.pending_move_number,
    033- </p>
    034- <p>
    035- b.put_in_num
    036- </p>
    037- <p>
    038- FROM
    039- </p>
    040- <p>
    041- t_stk_order_info a
    042- </p>
    043- <p>
    044- JOIN t_stk_order_list b ON b.order_code = a.order_code
    045- </p>
    046- <p>
    047- AND b.customer_id = a.customer_id
    048- </p>
    049- <p>
    050- WHERE
    051- </p>
    052- <p>
    053- a.add_time &gt;= 2025-10-15 05:28:00
    054- </p>
    055- <p>
    056- AND a.order_state IN (0, 1)
    057- </p>
    058- <p>
    059- AND a.order_status = 0
    060- </p>
    061- <p>
    062- AND a.is_stock_order = 1
    063- </p>
    064- <p>
    065- AND b.purchase_type &lt; 2
    066- </p>
    067- <p>
    068- AND b.lock_num &gt; 0
    069- </p>
    070- <p>
    071- AND (b.product_num + IFNULL(b.product_num_update, 0)) &gt; 0
    072- </p>
    073- <p>
    074- AND b.lock_num - b.put_in_num &gt; 0
    075- </p>
    076- <p>
    077- AND NOT EXISTS (SELECT 1 FROM rb_waitingmoving_orderdetail WHERE order_code = a.order_code AND customer_id = a.customer_id AND IFNULL(waiting_move_state, 0) = 0);
    078- </p>
    079- <p>
    080- <br />
    081- </p>
    082- <p>
    083- 其他类似的SQL,建议一样优化,以及在团队中强调,避免再次出现类似的性能SQL<br />
    084- <br />
    085- </p>
  5. 2025-10-17 10:50:14, 由 陈莉珍 关闭。
    修改了 Bug状态 ,旧值为 "resolved",新值为 "closed"。
    修改了 指派给 ,旧值为 "chenlizhen",新值为 "closed"。
    修改了 由谁关闭,旧值为 "",新值为 "chenlizhen"。
    修改了 关闭日期,旧值为 "",新值为 "2025-10-17 10:50:14"。
所属项目 技术中心-需求池
所属模块 供应链   仓储物流   仓储
所属计划
所属迭代
Bug类型
严重程度 一般
优先级 P1
Bug状态 已关闭
业务部门 总经办
影响功能
开发责任人 唐飞飞
测试责任人 唐飞飞
解决时效 6.52
激活次数 0
激活日期
是否确认 是
当前指派 Closed 于 2025-10-17 10:50:14
截止日期 0000-00-00
上线时间 2025-10-16 15:33:19
上线时效 6.52
操作系统
浏览器
关键词
抄送给
所属迭代
相关需求
相关任务
由谁创建 陈莉珍 于 2025-10-16 09:02:03
影响环境 生产环境-业务反馈
由谁解决 唐飞飞 于 2025-10-16 15:33:19
解决版本 主干
解决方案 性能问题
由谁关闭 陈莉珍 于 2025-10-17 10:50:14
最后修改 陈莉珍 于 2025-10-17 10:50:14
相关Bug