Can you please provide recommendation on rewriting this query in optimized way.?
This query uses 'rollup group by' which is using lot of TEMP space (crossed 1 TB of temp space and ran out of temp tablespace) and not completing it.
SQL monitor report is attached below. thanks.
SQL_FULLTEXT
-----------------------------------------------------------------------------
SELECT type, COUNT( eventid ) AS selectedEventCategoryCount FROM ( SELECT
INSTRUMENT_ID, EVENT_ID, eventId, eventRevisionId, actionType, announcementDate,
announcementStatus, countryOfIncCode, cusip, declarationDate, earlyDeadlineExpiryDate,
effectiveDate, entryDate, status, subtype, type, expirationDate, homeMarketCode,
homeMarketCountry, instrumentName, securityType, isin, recordDate, relatedEventId,
ticker, sedol, sedols, OFFERED_COMPANY_ID, OFFERING_COMPANY_ID, dividendStatus, marketExDate,
marketPaymentDate, marketEffectiveDate, marketsOptionNumber
, selectedEventCategoryCount
FROM (SELECT CAM.*, DIVIDEND.STATUS
as dividendStatus,
MARKETS.EX_DATE as marketExDate,
MARKETS.PAYMENT_DATE as marketPaymentDate,
MARKETS.MARKET_EFFECTIVE_DATE as marketEffectiveDate,
MARKETS.OPTION_NUMBER as marketsOptionNumber, 0 as selectedEventCategoryCount
FROM ( SELECT ROW_NUMBER() OVER(PARTITION BY CAM.EVENT_ID
ORDER BY CAM.EVENT_REVISION_ID DESC) as rowNumber, CAM.INSTRUMENT_ID,
CAM.EVENT_ID,
CAM.EVENT_ID as eventId,
CAM.EVENT_REVISION_ID as eventRevisionId,
CAM.ACTION_TYPE as actionType,
CAM.ANNOUNCEMENT_DATE as announcementDate,
CAM.ANNOUNCEMENT_STATUS as announcementStatus,
CAM.COUNTRY_OF_INC_CODE as countryOfIncCode,
CAM.CUSIP as cusip,
CAM.DECLARATION_DATE as declarationDate,
CAM.EARLY_DEADLINE_EXPIRY_DATE as earlyDeadlineExpiryDate,
CAM.EFFECTIVE_DATE as effectiveDate,
CAM.ENTRY_DATE as entryDate,
CAM.EVENT_STATUS as status,
CAM.EVENT_SUBTYPE as subtype,
CAM.EVENT_TYPE as type,
CAM.EXPIRATION_DATE as expirationDate,
CAM.HOME_MARKET_CODE as homeMarketCode,
CAM.HOME_MARKET_COUNTRY as homeMarketCountry,
CAM.INSTRUMENT_NAME as instrumentName,
CAM.SECURITY_TYPE as securityType,
CAM.ISIN as isin,
CAM.RECORD_DATE as recordDate,
CAM.RELATED_EVENT_ID as relatedEventId,
CAM.TICKER as ticker,
CAM.SEDOL as sedol,
CAM.SEDOLS as sedols,
CAM.OFFERED_COMPANY_ID,
CAM.OFFERING_COMPANY_ID FROM CA.CAM WHERE
CAM.EVENT_ID > 0 AND CAM.EVENT_STATUS != :1 )
CAM LEFT JOIN CA.DIVIDEND ON CAM.EVENT_ID
= DIVIDEND.EVENT_ID AND DIVIDEND.STATUS IS NOT NULL
LEFT JOIN CA.MARKETS ON MARKETS.EVENT_ID = CAM.EVENT_ID )
rollup GROUP BY INSTRUMENT_ID, EVENT_ID, eventId, eventRevisionId, actionType,
announcementDate, announcementStatus, countryOfIncCode, cusip, declarationDate,
earlyDeadlineExpiryDate, effectiveDate, entryDate, status, subtype, type,
expirationDate, homeMarketCode, homeMarketCountry, instrumentName, securityType, isin,
recordDate, relatedEventId, ticker, sedol, sedols, OFFERED_COMPANY_ID, OFFERING_COMPANY_ID,
dividendStatus, marketExDate, marketPaymentDate, marketEffectiveDate, marketsOptionNumber,
selectedEventCategoryCount)
GROUP BY type
Global Information
------------------------------
Status : EXECUTING
Instance ID : 4
Session : SVC_QUERY (2819:27773)
SQL ID : 5r16uhcbnxn2s
SQL Execution ID : 67108865
Execution Started : 08/27/2024 08:51:46
First Refresh Time : 08/27/2024 08:51:50
Last Refresh Time : 08/27/2024 20:33:19
Duration : 42095s
Module/Action : list-service
Service : READ_SVC
Program : list-service
Binds
========================================================================================================================
| Name | Position | Type | Value |
========================================================================================================================
| :1 | 1 | VARCHAR2(128) | Deleted Announcement |
========================================================================================================================
Global Stats
=======================================================================================================================================================================
| Elapsed | Cpu | IO | Application | Concurrency | Cluster | Other | Buffer | Read | Read | Write | Write | Uncompressed | Offload | Offload |
| Time(s) | Time(s) | Waits(s) | Waits(s) | Waits(s) | Waits(s) | Waits(s) | Gets | Reqs | Bytes | Reqs | Bytes | Bytes | Elig Bytes | Returned Bytes |
=======================================================================================================================================================================
| 42096 | 6233 | 10467 | 0.00 | 3041 | 7275 | 15080 | 78M | 128K | 90GB | 973K | 1TB | 25GB | 71GB | 1TB |
=======================================================================================================================================================================
SQL Plan Monitoring Details (Plan Hash Value=1566660356)
=======================================================================================================================================================================================================================================================
| Id | Operation | Name | Rows | Cost | Time | Start | Execs | Rows | Read | Read | Write | Write | Mem | Temp | Activity | Activity Detail | Progress |
| | | | (Estim) | | Active(s) | Active | | (Actual) | Reqs | Bytes | Reqs | Bytes | | | (%) | (# samples) | |
=======================================================================================================================================================================================================================================================
| 0 | SELECT STATEMENT | | | | 26087 | +15466 | 1 | 0 | | | | | | | 37.25 | gc buffer busy acquire (2976) | |
| | | | | | | | | | | | | | | | | gc buffer busy release (128) | |
| | | | | | | | | | | | | | | | | gc current block 2-way (243) | |
| | | | | | | | | | | | | | | | | gc current block 3-way (590) | |
| | | | | | | | | | | | | | | | | gc current block busy (1461) | |
| | | | | | | | | | | | | | | | | gc current block congested (2) | |
| | | | | | | | | | | | | | | | | gc current grant 2-way (2) | |
| | | | | | | | | | | | | | | | | gc current grant 3-way (4) | |
| | | | | | | | | | | | | | | | | gc current grant busy (8) | |
| | | | | | | | | | | | | | | | | gc current request (7) | |
| | | | | | | | | | | | | | | | | gc current retry (6) | |
| | | | | | | | | | | | | | | | | buffer busy waits (2043) | |
| | | | | | | | | | | | | | | | | latch: cache buffers chains (2) | |
| | | | | | | | | | | | | | | | | enq: SS - contention (533) | |
| | | | | | | | | | | | | | | | | log file switch completion (1) | |
| | | | | | | | | | | | | | | | | write complete waits (1) | |
| | | | | | | | | | | | | | | | | Cpu (550) | |
| | | | | | | | | | | | | | | | | DFS lock handle (457) | |
| | | | | | | | | | | | | | | | | cell single block physical read: RDMA (1) | |
| | | | | | | | | | | | | | | | | enq: TS - contention (17) | |
| | | | | | | | | | | | | | | | | ges message buffer allocation (13) | |
| | | | | | | | | | | | | | | | | latch free (3) | |
| | | | | | | | | | | | | | | | | cell single block physical read: flash cache (1) | |
| | | | | | | | | | | | | | | | | local write wait (845) | |
| | | | | | | | | | | | | | | | | read by other session (5) | |
| 1 | HASH GROUP BY | | 13 | 21M | 24923 | +16340 | 1 | 0 | | | | | | | 0.16 | ASM file metadata operation (3) | |
| | | | | | | | | | | | | | | | | Sync ASM rebalance (40) | |
| 2 | VIEW | VM_NWVW_0 | 264M | 21M | | | 1 | | | | | | | | | | |
| -> 3 | HASH GROUP BY | | 264M | 21M | 42026 | +71 | 1 | 0 | | | 948K | 919GB | 2GB | 926GB | 60.57 | statement suspended, wait error to be cleared (11045) | |
| | | | | | | | | | | | | | | | | Cpu (796) | |
| | | | | | | | | | | | | | | | | ASM IO for non-blocking poll (7) | |
| | | | | | | | | | | | | | | | | direct path write temp (4248) | |
| 4 | HASH JOIN RIGHT OUTER | | 264M | 7M | 42051 | +4 | 1 | 4G | 19568 | 19GB | 22055 | 21GB | 109MB | 25GB | 2.02 | Cpu (501) | 74% |
| | | | | | | | | | | | | | | | | direct path read temp (37) | |
| 5 | TABLE ACCESS STORAGE FULL | MARKETS | 137M | 604K | 31 | +4 | 1 | 137M | 17858 | 17GB | | | . | . | | | 100% |
| 6 | HASH JOIN RIGHT OUTER | | 150M | 4M | 8047 | +34 | 1 | 165M | | | | | . | . | | | |
| 7 | TABLE ACCESS STORAGE FULL | DIVIDEND | 5M | 113K | 4 | +34 | 1 | 5M | 3275 | 3GB | 3665 | 4GB | . | . | | | |
| 8 | TABLE ACCESS STORAGE FULL | CAM | 149M | 2M | 8044 | +37 | 1 | 149M | 78156 | 51GB | | | . | . | | | 100% |
=======================================================================================================================================================================================================================================================