Very slow delete on mysql base with subquery

前端 未结 4 544
星月不相逢
星月不相逢 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 12:56

    of corse it will take a lot of time because it execute the subquery for every record but by using INNER JOIN directly this query is executed only one time lets think that the query will take

    10 ms for 50000 rec  full time = 50000 * 10 ms ---> 8.333 minutes !! at least don't forget the condition and deleting time .....
    

    but using join the query will be executed only one time :

    DELETE t FROM tname.text t INNER JOIN (SELECT textid FROM spam) sq on t.old_id = sq.textid ;
    

提交回复
热议问题