我有以下语句可以在我的数据中找到明确的名称(约 100 万个条目):
select Prename, Surname from person p1
where Prename is not null and Surname is not null
and not exists (
select * from person p2 where (p1.Surname = p2.Surname OR p1.Surname = p2.Altname)
and p2.Prename LIKE CONCAT(CONCAT('%', p1.Prename), '%') and p2.id <> p1.id
) and inv_date IS NULL
Oracle 显示 1477315000 的巨大成本,并且执行在 5 分钟后没有结束。只需将 OR 拆分为一个自己的存在子条款即可将性能提高到 0.5 秒,并将成本提高到 45000:
select Prename, Surname from person p1
where Prename is not null and Surname is not null
and not exists (
select * from person p2 where p1.Surname = p2.Surname and
p2.Prename LIKE CONCAT(CONCAT('%', p1.Prename), '%') and p2.id <> p1.id
) and not exists (
select * from person p2 where p1.Surname = p2.Altname and
p2.Prename LIKE CONCAT(CONCAT('%', p1.Prename), '%') and p2.id <> p1.id
) and inv_date IS NULL
把它调整到最好不是我的问题,因为它只是一个很少执行的查询,而且我知道 CONTACT 超过了任何索引,但我只是想知道这么高的成本是从哪里来的。这两个查询在语义上似乎与我等效。