性能影响..查询运行时间过长

时间:2016-11-18 15:07:20

标签: sql oracle11g database-performance

我写了下面的查询,但是运行时间过长..我怎样才能优化这个?谁能想到如何使用不存在的逻辑重写这个逻辑?

SELECT s.sid
FROM book s
WHERE active    =1
AND (read_only IS NULL
OR read_only    = 0)
AND cdate      IS NULL
AND NOT EXISTS
  (SELECT 1
  FROM contract con
  WHERE ((con.pid=s.sid)
  OR (con.bsid   =s.sid)
  OR (con.ssid   =s.sid)
  AND (con.cosid <5))
  )
AND NOT EXISTS
  (SELECT 1 FROM pns WHERE staid=2 AND pns.abid=s.sid
  )
AND NOT EXISTS
  (SELECT 1 FROM contract_ct WHERE contract_ct.cpid=s.sid
  )
AND NOT EXISTS
  (SELECT 1 FROM cosa WHERE cosa.csid=s.sid
  );  

1 个答案:

答案 0 :(得分:0)

我认为你的括号错了。

AND NOT EXISTS
  (SELECT 1
  FROM contract con
  WHERE ((con.pid=s.sid)
  OR (con.bsid   =s.sid)
  OR (con.ssid   =s.sid)
  AND (con.cosid <5))
  )

你的意思不是 -

and not exists
    (
        select      1
        from        contract con
        where       (    con.pid  = s.sid
                      or con.bsid = s.sid
                      or con.ssid = s.sid
                    )
                and con.cosid < 5
    )