1

Please help me in tuning the performance of below query or suggest any alternate logic.

Select FNAME, MNAME, SURNAME, DOB, ADDRESS, PHONE 
from INDIVIDUAL_DATA
WHERE DOB = V_DOB
AND (SURNAME = V_SURNAME
OR (SURNAME LIKE '%' || ' ' || V_SURNAME)
OR (SURNAME LIKE V_SURNAME || ' ' || '%')
OR (SURNAME LIKE '%' || ' ' ||
V_SURNAME || ' ' || '%'));

V_SURNAME is variable having surname input and V_DOB is having input for DOB(Date Of Birth). I have created an index using SURNAME and DOB column. This query is part of an Stored Procedure. and this query will be the first query which executes on invoking the Stored Procedure.

I have around 7 Million records in DB2 database on which this query will be executed.We are facing performance issue, its taking much time. I suspect because of Like Predicate with OR operator is the cause of issue. This logic is implemented to perform Pattern search. Please have a look into below test cases :

case 1.

DOB= 1992-10-10 and SURNAME = 'ALEX MATHEWS'
        V_DOB = '1992-10-10' and SURNAME = 'ALEX'

this should find a positive match.

case 2.

DOB= 1965-05-10 and SURNAME = 'FRANKLIN JERRY'    
        V_DOB = '1965-05-10' and V_SURNAME = 'FRANK'

This should not be fetched. its a negative case.

Gaurav verma
  • 79
  • 1
  • 6

1 Answers1

0

Try the LOCATE function:

AND LOCATE(' '||V_SURNAME||' ', ' '||SURNAME||' ') > 0

DOB column should be the leading column of the index.

aygul
  • 3,227
  • 12
  • 38
  • 42
Manoj
  • 1