0
select 
    m.* 
from 
    MEDICALHIERARCHY_LEAF_LEVEL_V_5_0_LC_1 m 
inner join  
    (select synid 
     from SYNID_PROFILE_MAP_5 
     where upper(map_type) = upper('primary') 
       and upper(map_to_profile) = upper('Diagnostic Tests & Exams'))
map on m.name = map.synid 
where 
    m.Depth is null

Above query is taking 5-20 seconds depending on data. What can further improved in it for better tuning.

SAJAL MATHUR
  • 67
  • 1
  • 2
  • 15
  • 3
    You are the only one who knows the data... so you are the only one able to improve it. We don't know volumetry, indexes, execution plans... How do you want us to help on this without this information!? – James Aug 08 '18 at 06:44
  • @jamie Drq I wanted to know what alternative can i use to improve it(e.g what can be alternative for upper as upper itself is a function which slows it down) – SAJAL MATHUR Aug 08 '18 at 06:51
  • if you do really want to improve that query, the information that I asked you is crucial, trust me – James Aug 08 '18 at 06:54
  • 1
    What **RDBMS** are you using? Please add a relevant tag to your question – marc_s Aug 08 '18 at 07:21
  • @marc_s I am using oracle – SAJAL MATHUR Oct 03 '18 at 15:20

4 Answers4

2

You can start by fixing basics like:

UPPER(map_to_profile)=UPPER('Diagnostic Tests & Exams'))

Unless you use a case sensitive colaltion, the upper does exactly one thing: make sure indices are not used and the query may slow down. Do not use a case sensitive collation when you do not want a case sensitive collation.

And then remove the useless upper.

TomTom
  • 61,059
  • 10
  • 88
  • 148
1

Try this one

Select m.* from MEDICALHIERARCHY_LEAF_LEVEL_V_5_0_LC_1 m inner join  
(select synid from SYNID_PROFILE_MAP_5 where  UPPER(map_type) = 
'PRIMARY' and UPPER(map_to_profile)='DIAGNOSTIC TESTS & EXAMS')
map on m.name=map.synid where m.Depth is null

Avoid * in m.* instead of this use column name

Hassan Tariq
  • 730
  • 7
  • 15
0

Try removing subquery:

SELECT m.* 
FROM MEDICALHIERARCHY_LEAF_LEVEL_V_5_0_LC_1 m INNER JOIN  
SYNID_PROFILE_MAP_5 map ON (CASE WHEN m.Depth is null THEN m.name end)=(CASE WHEN UPPER(map_type) = 
UPPER('primary') and UPPER(map_to_profile)=UPPER('Diagnostic Tests & Exams') THEN map.synid end)

You may want to put m.Depth is null in WHERE clause depending on your join condition

akshay
  • 777
  • 4
  • 15
0

Try this code (although I'm in dark without knowing the real data):

SELECT m.*
  FROM MEDICALHIERARCHY_LEAF_LEVEL_V_5_0_LC_1 m
 WHERE m.DEPTH IS NULL
   AND m.name = (SELECT synid
                   FROM SYNID_PROFILE_MAP_5
                  WHERE UPPER (map_type) = 'PRIMARY'
                    AND UPPER (map_to_profile) = 'DIAGNOSTIC TESTS & EXAMS')

I removed unnecessary UPPER functions and removed your JOIN to WHERE clause (as it doesn't contribute to your select), while setting m.DEPTH IS NULL as first filter.

Goran Kutlaca
  • 2,014
  • 1
  • 12
  • 18