需要加速where not exists查询

g0czyy6m  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(298)

我相信这会导致5分钟到20分钟的延迟,这取决于记录的数量。我需要把它翻译成一个左连接,但需要一些帮助才能到达那里。

qry_arr = array(':bill_type' => "INT");
$sql = "update ".$billing_table." c set c.bill_type = :bill_type";
$sql .= " WHERE  NOT EXISTS (SELECT s.abbreviation FROM   state s WHERE  s.abbreviation = c.out_location)";
$sql .= " and c.out_location != 'UNKNOWN' and c.out_location != ''";
vx6bjr1n

vx6bjr1n1#

UPDATE $billing_table c
LEFT JOIN state s ON s.abbreviation = c.out_location
SET c.bill_type = :bill_type
WHERE s.abbreviation IS NULL
AND c.out_location NOT IN ('UNKNOWN', '')

这与 SELECT 对于不匹配的行。仅当值不存在时才查看返回行。只要替换一下 SELECT ... FROMUPDATE ,然后插入 SET 前面的子句 WHERE .
确保你有索引 out_location 以及 abbreviation .

相关问题