如何优化一下下面的SQL运行速度? SELECT DISTINCT p.sID AS sID, p.SNAME AS sName, mainOrg.sFName AS sFName
FROM SA_OPPerson p JOIN SA_OPOrg mainOrg ON p.SMAINORGID = mainOrg.sID
WHERE ( p.sID IN ('-') ) OR (p.sID IN (SELECT pm.SPERSONID AS sPersonID
FROM SA_OPOrg org JOIN SA_OPOrg orgC ON orgC.sFID LIKE org.sFID || '%' JOIN SA_OPOrg pm ON orgC.sID = pm.sParent
WHERE org.sID IN ('-', 'E93A43058AD540C191CEDC9B6C79E940', 'PSN01', 'A3226FBBBB864D92A5FBE925572BBA06') ))
ORDER BY mainOrg.sFName ASC, p.SNAME ASC
分享到:
------解决方案--------------------
具体的优化你要提供执行计划的,如下先给你改一下,再试试,你看一下你耗时的是不是在排序上了?
SELECT p.sID AS sID, p.SNAME AS sName, mainOrg.sFName AS sFName
FROM SA_OPPerson p
JOIN SA_OPOrg mainOrg ON p.SMAINORGID = mainOrg.sID
WHERE p.sID IN(SELECT pm.SPERSONID AS sPersonID
FROM SA_OPOrg org
JOIN SA_OPOrg orgC ON orgC.sFID LIKE org.sFID ------解决方案-------------------- '%'
JOIN SA_OPOrg pm ON orgC.sID = pm.sParent
WHERE org.sID IN ('-', 'E93A43058AD540C191CEDC9B6C79E940', 'PSN01',
'A3226FBBBB864D92A5FBE925572BBA06')
union all
select '-' sPersonID from dual)
group by p.sID, p.SNAME, mainOrg.sFName
ORDER BY mainOrg.sFName ASC,