You are on page 1of 7

OPRFSEV &

OPRFSODNEW SQL
Tuning
Recommendation 21-06

26th Feb 2021


P Technology Consulting Services
Kevin Lim
1
SQL on PAYLOAD
• Query on PAYLOAD
– The same SQL is executed in OPRFSEV and OPRFSODNEW
SELECT TRUNC(CREATED_DT) as EVEN,
ST_CD,
COUNT(*) as "Total Data"
FROM PAYLOAD
WHERE ST_CD!='2'
AND CREATED_DT >= trunc(to_date('17-FEB-2021'))
AND CREATED_DT < trunc(to_date('24-FEB-2021'))
GROUP BY TRUNC(CREATED_DT), ST_CD
ORDER BY TRUNC(CREATED_DT)

2
SQL on PAYLOAD
• Execution plan
– Index fast full scan
• IDX_PAYLOAD_STCD_RETRY for ST_CD
• PK_PAYLOAD for CREATED_DT
– Hash join 2 indexes

3
Analysis
• ST_CD != '2'
– Cannot use index with range scan
– Oracle decided to use index fast full scan instead of table full
scan
– 99.99% of data has ST_CD as 2
– Few records meet ST_CD <> '2'
• ST_CD and CREATED_DT
– Only 2 columns are used in the SQL
– But there is no index covering both indexes
– 2 indexes on each column are used

4
Recommendations 1/2
• Change the SQL as below
– To enable index range scan
SELECT EVEN,
ST_CD,
SUM(CNTS) as "Total Data"
FROM ( SELECT TRUNC(CREATED_DT) as EVEN,
ST_CD,
COUNT(*) as CNTS
FROM PAYLOAD
WHERE ST_CD < '2'
AND CREATED_DT >= TRUNC(TO_DATE('17-FEB-2021'))
AND CREATED_DT < TRUNC(TO_DATE('24-FEB-2021'))
GROUP BY TRUNC(CREATED_DT), ST_CD
UNION ALL
SELECT TRUNC(CREATED_DT) as EVEN,
ST_CD,
COUNT(*) as CNTS
FROM PAYLOAD
WHERE ST_CD > '2'
AND CREATED_DT >= TRUNC(TO_DATE('17-FEB-2021'))
AND CREATED_DT < TRUNC(TO_DATE('24-FEB-2021'))
GROUP BY TRUNC(CREATED_DT), ST_CD
)
5 GROUP BY EVEN, ST_CD
ORDER BY EVEN
Recommendations 2/2
• Create a new index on PAYLOAD
(ST_CD, CREATED_DT)

• Recommendations need to be applied to both DBs


– OPRFSEV and OPRFSODNEW

6
Thank You.
P Technology Consulting Services

You might also like