I have a below query which runs perfectly but then i run it on the complete data the Table (Export_SKU_Data_v2) get's locked. The lock is Row-X lock. Surprisingly the count is only somewhere around 30,000 rows and i don't think the issue is with performance. The issue is definitely with the query.
update Export_SKU_Data_v2 tgt
set tgt.seo_url
= (select src.seo_url--,src.sku_id,src.site_id
from (
WITH prd_sites AS
(
select wo.Product_id, WO.Site_id
FROM
(select decode(substr(translation_id, 1, 1), '2', 'BuyBuyCaby', '3', 'CedCathCanada', null) site_id,
product_id
from bbb_prod_site_translations
where translation_id in ('2_en_US_webOffered_Y', '3_en_US_webOffered_Y')
)wo,
(select decode(substr(translation_id, 1, 1), '2', 'BuyBuyCaby', '3', 'BedCathCanada', null) site_id,
product_id
from bbb_prod_site_translations
where translation_id in ('2_en_US_prodDisable_N', '3_en_US_prodDisable_N')
)da
Where wo.product_id = da.product_id and wo.site_id = da.site_id
UNION
Select Product_id, 'BedCathUS' from bbb_product
where web_offered_flag= 1 and disable_flag = 0
)select distinct sku_id,site_id,seo_url as seo_url from (
select k.sku_id,bp.product_id,bp.web_offered_flag,bp.disable_flag,bp.seo_url,site_id,
dense_rank() over(partition by k.sku_id,site_id order by bp.product_id desc) as rnk
from (
select bs.sku_id,count(*)
from bbb_sku bs
inner join DCS_PRD_CHLDSKU dpcs on bs.sku_id=dpcs.sku_id
group by bs.sku_id
having count(*)>1
) k inner join DCS_PRD_CHLDSKU dpcs1 on k.sku_id=dpcs1.sku_id
inner join bbb_product bp on dpcs1.product_id=bp.product_id
inner join prd_sites pst on bp.product_id=pst.product_id
where bp.seo_url is not null
) tab where rnk=1
)src where tgt.sku_id = src.sku_id and tgt.site_id=src.site_id )
where tgt.seo_url is null ;--and tgt.sku_id='10920540';
Note : Please allow me to ask if this is the correct way to update a table based on the above logic. The logic is pretty simple and i am not able to find where i'm screwing it up.