简体   繁体   English

如果在ORACLE中使用两个连接字段,则FULL OUTER JOIN卡住了

[英]FULL OUTER JOIN stuck if two join fields is using in ORACLE

I have issues with FULL OUTER JOIN Query: 我对FULL OUTER JOIN查询有疑问:

SELECT
  count(e.id)
FROM 
  eligibility e 
FULL OUTER JOIN
  tr_entry t
    ON t.correlation_id2 = e.correlation_id2
    OR t.correlation_id = e.correlation_id
WHERE (
        (t.correlation_id IS NULL AND t.correlation_id2 IS NULL)
    OR
        (e.correlation_id IS NULL AND e.correlation_id2 IS NULL)
    ) 
    and e.PAIRING_DATE is NULL
    AND t.PAIRING_DATE IS NULL
;

Query just stuck and I have to restart Oracle. 查询只是卡住了,我必须重新启动Oracle。 On small dataset all is ok, but when a dataset is big (more than 1 million records in eligibility table) DB is stuck. 在小型数据集上,一切都可以,但是当数据集很大时(资格表中的记录超过100万条),数据库将卡住。 Which index I have to use on both table? 我必须在两个表上使用哪个索引?

Your comment: 你的评论:

Yes, I'm trying to find just all eligibility records that have no match in tr_entry 是的,我正在尝试查找所有在tr_entry中不匹配的资格记录

So why a full outer join? 那么为什么要进行完全外部联接? That makes no sense. 这是没有意义的。 You should use a NOT EXISTS clause instead: 您应该改用NOT EXISTS子句:

select *
from eligibility e
where not exists
(
  select *
  from tr_entry t
  where t.correlation_id  = e.correlation_id
     or t.correlation_id2 = e.correlation_id2
);

I don't know how the pairing_date columns come into play, so simply put them in the query as you want them :-) 我不知道pairing_date列如何发挥作用,因此只需将它们放入查询中即可:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM