DELETE FROM search WHERE sequence_id IN (34546);
受影响的行:0 时间:0.001秒
SELECT sequence_id FROM sequences WHERE sequence_status = 1;
好 时间:0.001秒
DELETE FROM search WHERE sequence_id IN (SELECT sequence_id FROM sequences WHERE sequence_status = 1);
受影响的行:0 时间:2868秒
我在做什么错了?
EXPLAIN DELETE FROM search WHERE sequence_id IN (SELECT sequence_id FROM sequences WHERE sequence_status = 1);
答案 0 :(得分:0)
尝试使用联接而不是IN
。
DELETE search
FROM search
INNER JOIN sequences
ON sequences.sequence_id = search.sequence_id
WHERE sequences.sequence_status = 1;
要支持该功能,请在search (sequence_id)
和sequences (sequence_id, sequence_status)
上创建一个索引。
CREATE INDEX search_sequence_id
ON search
(sequence_id);
CREATE INDEX sequences_sequence_id_sequence_status
ON sequences
(sequence_id,
sequence_status);
答案 1 :(得分:0)
IN ( SELECT ... )
的优化很差,尤其是在旧版本的MySQL / MariaDB中。避免!DELETE
/ UPDATE
曾经有一个la脚的解析器/优化器。我怀疑这就是你打的。较新的版本统一了代码,从而改善了删除/更新的优化。sequences
有多大?您有INDEX(sequence_status, sequence_id)
吗?DELETE
语法,可以 进行不同的优化。