Please help me merge query is taking more time [message #604853] |
Sat, 04 January 2014 12:40 |
|
ramya_162
Messages: 107 Registered: August 2013 Location: Banglore
|
Senior Member |
|
|
Hi Experts,
This merge statement is taking nearly 2 hours.
If I run the select I am getting the output in 1 minute.
SELECT QI.QI_ID, QI.QI_OFFERNO, QI_BUILDNO, QI.QI_UPDATE_TIME, GHS.TEAM, GHS.TEAM_ID
FROM QUANTITY_ITEM QI
INNER JOIN ITEM_MASTER IEM ON QI.QI_ID = IEM.ORG_ID
INNER JOIN GOODS_DELV GHS ON IEM.REGION_ID = GHS.REGION_ID AND QI.QI_CC_Channel = GHS.Channel
WHERE QI.QI_INSIDE_SALES_TEAM IS NULL
AND QI.IS_PROCESSED = 'N'
AND QI.QI_ID = 888
This merge is updating 75000 records.
MERGE INTO QUANTITY_ITEM QI
USING
(
SELECT QI.QI_ID, QI.QI_OFFERNO, QI_BUILDNO, QI.QI_UPDATE_TIME, GHS.TEAM, GHS.TEAM_ID
FROM QUANTITY_ITEM QI
INNER JOIN ITEM_MASTER IEM ON QI.QI_ID = IEM.ORG_ID
INNER JOIN GOODS_DELV GHS ON IEM.REGION_ID = GHS.REGION_ID AND QI.QI_CC_Channel = GHS.Channel
WHERE QI.QI_INSIDE_SALES_TEAM IS NULL
AND QI.IS_PROCESSED = 'N'
AND QI.QI_ID = 888
) GOOD_INFO
ON(
QI.QI_ID = GOOD_INFO.QI_ID
AND QI.QI_OFFERNO = GOOD_INFO.QI_OFFERNO
AND QI.QI_BUILDNO = GOOD_INFO.QI_BUILDNO
AND QI.QI_UPDATE_TIME = GOOD_INFO.QI_UPDATE_TIME
AND QI.IS_PROCESSED = 'N'
)
WHEN MATCHED THEN
UPDATE SET QI.QI_INSIDE_SALES_TEAM = GOOD_INFO.TEAM,
QI.QI_GOOD_INFO_ID = GOOD_INFO.TEAM_ID
WHERE QI.QI_INSIDE_SALES_TEAM IS NULL
AND QI.IS_PROCESSED = 'N'
AND QI.QI_ID = 888;
Please help me why the merge statement is taking more time to update 75000 records.
Thanks.
|
|
|
|
|
|
|
|
|
|
|
|
Re: Please help me merge query is taking more time [message #604915 is a reply to message #604868] |
Mon, 06 January 2014 02:44 |
cookiemonster
Messages: 13961 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
ramya_162 wrote on Sun, 05 January 2014 06:18Hi,
In the merge statement I have used the table QUANTITY_ITEM out side and inside the join.Is it correct .
Is it really required the QUANTITY_ITEM in the join also.
Please help me.
Thanks.
How do you think we're going to know if the sql is correct if you don't tell us what you want it to?
You have to explain the logic you are trying to apply.
|
|
|