如果delete语句带有查询,写法不对会导致不走索引。

简单粗暴的办法:拆两条sql,一条查询,一条delete

=======================

【不走索引的写法】

DELETE FROM goods_item_combo_group_item_history
WHERE group_id IN (SELECT id
    FROM goods_item_combo_group_history
    WHERE lease_code = 'schjyzzh'
      AND item_code = 'YL180606110506793'
      AND gmt_modified = '2018-06-07 23:18:51')

【走索引的写法】

DELETE goods_item_combo_group_item_history
        FROM goods_item_combo_group_item_history, goods_item_combo_group_history
        WHERE goods_item_combo_group_item_history.group_id = goods_item_combo_group_history.id
        AND goods_item_combo_group_history.lease_code = #{leaseCode}
        AND goods_item_combo_group_history.item_code = #{itemCode}
        AND goods_item_combo_group_history.gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}

 

相关文章:

  • 2021-10-23
  • 2021-05-13
  • 2021-12-01
  • 2022-12-23
  • 2021-09-01
  • 2021-12-02
  • 2022-12-23
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2021-11-17
  • 2021-07-04
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案