データ (~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 を独自の exists サブ句に分割するだけで、パフォーマンスが 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 がどのインデックスよりも優れていることは知っていますが、この高いコストがどこから来るのか疑問に思っています。どちらのクエリも意味的には同等のようです。