Разделите запрос таким образом, чтобы в нем было условие AND
, чтобы получить прирост производительности, как показано ниже.
SELECT BATCH_ID,
BU_CODE,
BU_TYPE,
BATCH_TYPE,
BATCH_GROUP_ID,
STATUS,
UPD_DTIME
FROM BATCH_T
WHERE UPD_DTIME >= SYSDATE - 5
UNION ALL
SELECT BATCH_ID,
BU_CODE,
BU_TYPE,
BATCH_TYPE,
BATCH_GROUP_ID,
STATUS,
UPD_DTIME
FROM BATCH_T
WHERE (BU_CODE, BU_TYPE, BATCH_TYPE, UPD_DTIME) IN
(SELECT BU_CODE,
BU_TYPE,
BATCH_TYPE,
MAX(UPD_DTIME)
FROM BATCH_T
WHERE STATUS = 'CLOSED'
GROUP BY BU_CODE,
BU_TYPE,
BATCH_TYPE
) AND NOT UPD_DTIME >= SYSDATE - 5;