1

对于一个大表(100 万条记录),我有一个这样的更新查询:

update direct_words set weight = (weight / 4) where knowledge_id = :a 
and phrase_id in (select phrase_id from phrases where knowledge_id =:b 
and phrase_class <> 6);

我有几个索引,但一个是针对字段的:

knowledge_id;phrase_id

这在 SQLite 下运行非常快(2 秒或更短),但对于 MySQL,相同的查询大约需要 37 秒。我究竟做错了什么?

4

1 回答 1

7

尝试使用执行它JOIN

update  direct_words a
        INNER JOIN phrases b
            ON a.phrase_id = b.phrase_id
set     a.weight = (a.weight / 4) 
where   a.knowledge_id = :a AND
        b.knowledge_id = :b AND
        b.phrase_class <> 6
于 2013-01-11T09:22:44.090 回答