MySQL中使用IN子句更新时如何避免全表扫描

MySQL中使用IN子句更新时如何避免全表扫描,mysql,in-clause,full-table-scan,Mysql,In Clause,Full Table Scan,我有两个MySQL表:termlist和blacklist。它们都在字段“term”上有索引,而黑名单在字段“status”上有另一个索引 我想将termlist中的术语状态(也出现在黑名单中,状态为“A”)更新为“B”,我发出以下SQL语句: update termlist set status = 'B' where term in (select term from blacklist where status = 'A') 它会导致termlist上的全表扫描。我想使用“updatew

我有两个MySQL表:termlist和blacklist。它们都在字段“term”上有索引,而黑名单在字段“status”上有另一个索引

我想将termlist中的术语状态(也出现在黑名单中,状态为“A”)更新为“B”,我发出以下SQL语句:

update termlist set status = 'B' where term in (select term from blacklist where status = 'A')
它会导致termlist上的全表扫描。我想使用“updatewithinternaljoin”,但我不能,因为select语句中有where子句

我知道我可以从select语句创建一个临时表,然后用该临时表更新内部连接,但如果我想多次更新,这会有点乏味

是否有一条update语句可以在不进行全表扫描的情况下完成工作?

您可以使用:

update termlist t inner join blacklist b 
    on t.term=b.term
    set t.status = 'B' 
    where b.status = 'A'

显示索引信息的表架构请不要手动键入,
show create table xxx
。。。所以跳过我刚才说的。。。您想使用update with table join模式,请参阅我将使用2个临时表来尝试您的语句。如果答案正确,我会检查你的答案。