给定:
表A~400k行表B~150k行
两个表都有相同的GUID,但我需要在A中标记B中所有缺少的GUID,这两个GUID都有索引。
查询:
update table_a
left join table_b b on table_a.guid = b.guid
set missing = true
where b.guid is null;
这个查询可以工作,但在我的机器上花了4、5个小时。有什么方法可以让这个查询运行得更快吗?
它快多了。它只测试行是否为西行。
UPDATE table_a ta
SET missing = true
WHERE NOT EXISTS ( SELECT 1 from table_b tb WHERE ta.guid = tb.guid );
尝试:
update table_a
set missing = true
where guid not in (select guid from table_b)