Tuning a small but complicated query [message #537619] |
Thu, 29 December 2011 14:55 |
|
neel_Tannu
Messages: 1 Registered: December 2011
|
Junior Member |
|
|
select distinct b.pid, d.bo_name, d.fname, d.lname,
e.ss_user_type, x.latshrtname
from rsf_suser_vw b, person c, NAME d,
rsf_suser e, item x
where
exists (select 'x' from NAME y where y.id = c.id and
(y.fname_srch like '%' and y.lname_srch like '%'))
and b.pid = c.pid
and c.id = d.id
and c.pid = e.pid
and e.sales_user_type=x.fieldvalue
and x.fieldname='SUSER_TYPE'
and
exists (select 1 from
(SELECT DISTINCT P1.HIERARCHY_NODE FROM HIERARCHYNODE P1 WHERE P1.HIERARCHY_NAME = 'GLOBE' AND
CONNECT_BY_ISLEAF = 1 START WITH P1.HIERARCHY_NODE IN (select TERRITORY_ID from TEAM WHERE
pid = '558') CONNECT BY PRIOR P1.HIERARCHY_NODE = P1.HIERARCHY_NODE_NAME
INTERSECT SELECT DISTINCT
P1.HIERARCHY_NODE FROM HIERARCHYNODE P1 WHERE P1.HIERARCHY_NAME = 'GLOBE' AND
CONNECT_BY_ISLEAF = 1 START WITH
P1.HIERARCHY_NODE = '1093' CONNECT BY PRIOR P1.HIERARCHY_NODE = P1.HIERARCHY_NODE_NAME)
where P1.territory_id);
|
|
|
Re: Tuning a small but complicated query [message #537621 is a reply to message #537619] |
Thu, 29 December 2011 15:17 |
John Watson
Messages: 8964 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Welcome to the forum - I hope you will both learn and contribute (as I try to do). Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read
I've put your code through a formatter and applied the correct tags - do you see that it is a bit easier to read now? But you haven't actually asked a question. What is the problem?
SELECT DISTINCT b.pid,
d.bo_name,
d.fname,
d.lname,
e.ss_user_type,
x.latshrtname
FROM rsf_suser_vw b,
person c,
NAME d,
rsf_suser e,
item x
WHERE EXISTS (SELECT 'x'
FROM NAME y
WHERE y.id = c.id
AND ( y.fname_srch LIKE '%'
AND y.lname_srch LIKE '%' ))
AND b.pid = c.pid
AND c.id = d.id
AND c.pid = e.pid
AND e.sales_user_type = x.fieldvalue
AND x.fieldname = 'SUSER_TYPE'
AND EXISTS (SELECT 1
FROM (SELECT DISTINCT p1.hierarchy_node
FROM hierarchynode p1
WHERE p1.hierarchy_name = 'GLOBE'
AND connect_by_isleaf = 1
START WITH p1.hierarchy_node IN (SELECT territory_id
FROM team
WHERE pid = '558')
CONNECT BY PRIOR p1.hierarchy_node =
p1.hierarchy_node_name
INTERSECT
SELECT DISTINCT p1.hierarchy_node
FROM hierarchynode p1
WHERE p1.hierarchy_name = 'GLOBE'
AND connect_by_isleaf = 1
START WITH p1.hierarchy_node = '1093'
CONNECT BY PRIOR p1.hierarchy_node =
p1.hierarchy_node_name)
WHERE p1.territory_id);
|
|
|
|