select * from table1 where ID in (
select min(a.ID) from (select * from table1) a group by id_x, id_y, col_z having count(*) > 1)
以上查询在2.2秒内运行,返回四个结果。现在,当我将select *
更改为delete
时,它会无限期挂起。
delete from table1 where ID in (
select min(a.ID) from (select * from table1) a group by id_x, id_y, col_z having count(*) > 1)
如果我在别名选择查询中移动group by
子句的位置,它将不再挂起。
delete from table1 where ID in (
select a.ID from (select min(ID) from table1 group by id_x, id_y, col_z having count(*) > 1) a)
为什么挂起?即使(select * from table1)
拉动了数百万条记录,查询似乎也没有停止执行数小时。有人可以解释是什么困扰了查询吗?这使我感到困惑,因为选择查询工作正常,而删除查询挂起。