oracle subquery in keyword is slow on 12c

醉酒当歌 提交于 2019-12-13 16:09:47

问题


compared to 11g, 12c (currently using 12.1.0.2 version) in keyword is so slow.

SELECT * FROM 
    DATA_TABLE WHERE
    OID IN (
        SELECT OID FROM ID_TABLE WHERE (condition)
    )

result

  • 11g : under 1 sec

  • 12c : over 10 sec

below query is fast enough in both 11g and 12c (to let you know real problem is 'in subquery' query

SELECT OID FROM ID_TABLE WHERE (condition)

I can solve this problem with changing query as below

SELECT * FROM 
    DATA_TABLE D,
    (
        SELECT OID FROM ID_TABLE WHERE (condition)
    ) O
WHERE D.OID = O.OID

result

  • 11g : under 1 sec

  • 12c : under 1 sec

OR

SELECT * FROM 
    DATA_TABLE WHERE
    OID IN (
        "AA", "BB", "CC", "DD, "EE"
    )

result

  • 11g : under 1 sec

  • 12c : under 1 sec

Problem is only on 'in sub query'. INDEX is well made both table. Have Anyone solved this problem?


回答1:


You would have to provide the explain plans to better assess why one is performing better than the other. But, in general, you can get better, or at least, more predictible results for this type of query by changing the IN condition to an EXISTS condition instead:

select *
  from data_table t1
 where exists (select null
                 from id_table t2
                where t2.oid = t1.oid
                  and (other conditions))


来源:https://stackoverflow.com/questions/34609799/oracle-subquery-in-keyword-is-slow-on-12c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!