Correct index utilization in SQL queries on DB2
Hi,
I am building an underlying query that ought to be able to locate the unique record on the PERSON table which consists of the following columns: EID, SSN, LAST_NAME, FIRST_NAME, DOB
I am utilizing the "3 out of 4" technique which means that combination of any 3 out of 4 incoming parameters should be able to uniquely identify a record. In other words, the query below should produce 0 ot 1 record which is the expected outcome. The table has 5 indexes:
* a compound index on SSN, LAST_NAME, FIRST_NAME, DOB
* separate indexes on each of the columns above.
I need to be able to optimize the following query (or possibly, re-write it) to prevent or minimize the table scans:
This query performs table scan that I must avoid in order to get the best results. This query is to be used in as a base for Web Service, hence the performance is essential.
Any suggestions or help would be greatly appreciated.
Best regards,
levka
Hi,
I am building an underlying query that ought to be able to locate the unique record on the PERSON table which consists of the following columns: EID, SSN, LAST_NAME, FIRST_NAME, DOB
I am utilizing the "3 out of 4" technique which means that combination of any 3 out of 4 incoming parameters should be able to uniquely identify a record. In other words, the query below should produce 0 ot 1 record which is the expected outcome. The table has 5 indexes:
* a compound index on SSN, LAST_NAME, FIRST_NAME, DOB
* separate indexes on each of the columns above.
I need to be able to optimize the following query (or possibly, re-write it) to prevent or minimize the table scans:
Code:
SELECT EID
FROM myTABLE WHERE
( rtrim(SSN) = '010101010' AND soundex(LAST_NAME) = soundex('Doe') AND soundex(FIRST_NAME) = soundex('John' ))
or ( rtrim(SSN) = '010101010' AND DOB = cast('09/10/1981' as date) AND soundex(LAST_NAME) = soundex('Doe' ))
or ( rtrim(SSN) = '010101010' AND DOB = cast('09/10/1981' as date) AND soundex(FIRST_NAME) = soundex('John' ))
or ( DOB = cast('09/10/1981' as date) AND soundex(LAST_NAME) = soundex('Doe') AND soundex(FIRST_NAME) = soundex('John' ));
Any suggestions or help would be greatly appreciated.
Best regards,
levka