我有一个删除语句,用于删除数据库中的20000条记录。这20000条记录中的每一行都满足两个条件:id = x和new_tracking_number = y。详情如下:
DELETE FROM tracking_number_pool WHERE (
(id=88 AND new_tracking_number='LPT99') OR
(id=87 AND new_tracking_number='LPT98') OR
(id=86 AND new_tracking_number='LPT97') OR
(id=85 AND new_tracking_number='LPT96') OR
(id=84 AND new_tracking_number='LPT95') OR
...
(id=72 AND new_tracking_number='LPT83')
);
当我在生产环境中运行上面的delete语句时,完成执行需要很长时间。我想知道如何提高删除操作的效率。
答案 0 :(得分:0)
你可以尝试
DELETE FROM
tracking_number_pool
WHERE (id, new_tracking_number) in (
(78319988, 'LPT0000001699999'),
(78319986, 'LPT0000001699997'),
..
)