Very slow delete on mysql base with subquery

前端 未结 4 546
星月不相逢
星月不相逢 2021-01-04 12:35

This mysql query is running for around 10 hours and has not finished. Something is horribly wrong.

Two tables (text and spam) are here. Spam stores the ids of spam e

4条回答
  •  醉梦人生
    2021-01-04 13:18

    Your choice of where id in (select ...) will always perform poorly.

    Instead, use a normal join which will be very efficient:

    DELETE `text` 
    FROM spam
    join `text` on `text`.old_id = spam.textid;
    

    Notice selection from spam first, then joining to text, which will give the best performance.

提交回复
热议问题