Please, next time enclose your code into CODE tags like...
Questions:Code:SELECT rp.person_nr, rp.regimen_sequence, rp.regimen_type_code FROM REGIMEN_PRES rp, PERSON p WHERE regimen_type_code = 'CD' AND prescription_status_code= 'FNSH' AND rp.person_nr = p.person_nr and p.email not like '%test%' AND regimen_sequence = (SELECT MAX(regimen_sequence) FROM REGIMEN_PRES r WHERE r.person_nr = p.person_nr AND regimen_type_code = 'CD') AND p.person_nr IN (SELECT a.person_nr FROM JOB_QUEUE b, REGIMEN_PRES rp, PERSON a WHERE a.person_nr = b.person_nr AND a.person_nr = rp.person_nr AND b.job_queue_type_nr = 4 AND b.status_code = 'FNSH' AND (a.status_code = 'ACTV' or a.status_code = 'CHNG')) ORDER BY p.person_nr;
1- Do you have up-to-date statistics on affected tables and indexes?
2- Could you publish your indexes DDL?
Comments:
Your code has everything it needs to perform badly,
a) you have two in-line views -which will execute once per each base row, one of them in an IN clause.
b) you have one of the ugliest predicates you can think about "not like %*%"




Reply With Quote