0

我有一个名为 as 的表event_extra,用于根据某些条件查找重复项,我编写了以下自联接查询,但是当记录更多(100 万)时,它会花费很多时间。

表字段如下

evt_id
extra1
extra2
extra3
extra4
extra5
extra6
extra7
extra8
extra9

这张桌子Unique index上有evt_id

自加入查询

select cde1.evt_id,
       cde1.extra1,
       cde1.extra2,
       cde1.extra3,
       cde1.extra4,
       cde1.extra5,
       cde1.extra6,
       cde2.evt_id as evt_id2,
       cde1.extra7,
       cde1.extra8,
       cde1.extra9,
  from event_extra cde2
  join event_extra cde1
    on (( cde1.extra4 = cde2.extra4 and cde1.extra7 = cde2.extra7) or
       (cde1.extra4 = cde2.extra5 and cde1.extra7 = cde2.extra8) or
       (cde1.extra4 = cde2.extra6 and cde1.extra7 = cde2.extra9) or
       (cde1.extra5 = cde2.extra4 and cde1.extra8 = cde2.extra7) or
       (cde1.extra5 = cde2.extra5 and cde1.extra8 = cde2.extra8) or
       (cde1.extra5 = cde2.extra6 and cde1.extra8 = cde2.extra9) or
       (cde1.extra6 = cde2.extra4 and cde1.extra9 = cde2.extra7) or
       (cde1.extra6 = cde2.extra5 and cde1.extra9 = cde2.extra8) or
       (cde1.extra6 = cde2.extra6 and cde1.extra9 = cde2.extra9))
   and ((to_number(cde1.extra3) >= to_number(cde2.extra1) and
       (to_number(cde1.extra3) <= to_number(cde2.extra2))) or
       ((to_number(cde1.extra1) >= to_number(cde2.extra2)) and
       (to_number(cde1.extra1) <= to_number(cde2.extra3))) or
       ((to_number(cde1.extra2) >= to_number(cde2.extra1)) and
       (to_number(cde1.extra2) <= to_number(cde2.extra3))))
   and cde1.evt_id > cde2.evt_id
 order by cde1.evt_id;

是否有任何其他方法可以提高上述查询的性能?

Database Version: Oracle11g
4

1 回答 1

1

查看查询必然会运行缓慢的条件。此外,您再次使用 order by this 会使事情变得更糟。您可以做的是删除 order by 并在临时表中选择此输出,然后对该表执行操作和选择。另外,尝试在列上放置索引。

于 2014-06-23T07:19:42.003 回答