You can:
- Use an analytic function instead of sub-queries.
- Remove the
TRUNC
from around TRUNC(creation_date)
as if the truncated date is less than TRUNC(SYSDATE) - 2
then it will also always be true without truncating. This would let the optimizer use an index on the creation_date
column (rather than requiring a function-based index on TRUNC(creation_date)
).
Which would give you:
SELECT *
FROM (
SELECT x.*,
MAX(
CASE
WHEN status = 'PROCESSED'
AND file_id = 'CBS1330'
THEN request_id
END
) OVER () AS max_processed_cbs,
MAX(
CASE
WHEN status = 'PROCESSED'
AND file_id = 'CCI1330'
THEN request_id
END
) OVER () AS max_processed_cci
FROM xxcpb_i45_06_interface_r x
WHERE file_id IN ('CBS1330', 'CCI1330')
)
WHERE creation_date < TRUNC(SYSDATE) - 2
AND ( (file_id = 'CBS1330' AND request_id < max_processed_cbs)
OR (file_id = 'CCI1330' AND request_id < max_processed_cci)
);
Then you can consider adding indexes on the columns you are using.