My select query is running for 15 hours and still running so I cancelled it. How can I optimize my query?
CREATE TABLE W_PURCH_RCPT_FS_tmp
AS
SELECT RCV.TRANSACTION_ID,
PO.RELEASE_DATE,
NVL (ASL.PROCESSING_LEAD_TIME, MTL.FULL_LEAD_TIME)
AS PROCESSING_LEAD_TIME
FROM obia_ui.PO_ASL_ATTRIBUTES@betsy.world@dsn_310 ASL,
obia_ui.MTL_SYSTEM_ITEMS_B@betsy.world@dsn_310 MTL,
obia_ui.RCV_TRANSACTIONS@betsy.world@dsn_310 RCV,
obia_ui.PO_RELEASES_ALL@betsy.world@dsn_310 PO,
obia_ui.PO_LINES_ALL@betsy.world@dsn_310 LINES,
obia_ui.PO_LINE_LOCATIONS_ALL@betsy.world@dsn_310 LOC,
obia_ui.PO_HEADERS_ALL@betsy.world@dsn_310 HEAD
WHERE RCV.CREATION_DATE > '30-JUN-2016'
AND MTL.INVENTORY_ITEM_ID = LINES.ITEM_ID
AND MTL.ORGANIZATION_ID = LOC.SHIP_TO_ORGANIZATION_ID
AND LINES.PO_LINE_ID = LOC.PO_LINE_ID
AND ASL.USING_ORGANIZATION_ID = LOC.SHIP_TO_ORGANIZATION_ID
AND ASL.ITEM_ID = LINES.ITEM_ID
AND ASL.VENDOR_ID = HEAD.VENDOR_ID
AND ASL.VENDOR_SITE_ID = HEAD.VENDOR_SITE_ID
AND RCV.TRANSACTION_ID = PO.PO_RELEASE_ID
;
I expect that query to finish shorter.
First of all you have to master explain plan concept to optimize a query in Oracle. After understanding explain plans I would suggest to go for table by table. Starting from the first table check how it performs on an explain plan. By this way you can figure out the indexes that need to be created. Sometimes there's no way to create a useful index. In that case splitting the data into smaller chunks (tables) may help. Also Oracle has a parallel query running capabilities. You can take advantage of this feature too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.