Hi,
Production SP is performing very poor and even sometime application is getting timed out. I looked at the SP and found out that query below highlighted in BOLD is the mail cause of concerns. Any chance anyone can look and provide any inputs whats wrong in this query and why its taking huge time. Thanks in advance. (If you want script for whole SP then leave comment and i will paste here)
[IndexPageNumber] = ( SELECT TOP 1 NumberOfIndexPages FROM [EditionBrief] INNER JOIN [EditionBriefRegionalIndexPages] ON [EditionBriefRegionalIndexPages].[fkEditionBriefId] = [EditionBrief].[EditionBriefId] WHERE [fkBoxId] = [P].[ProductId] AND fkMarketingRegionsId =
CASE WHEN cntry.CountryId <> @BoxCountryId THEN mr2.MarketingRegionId WHEN (@BoxCountryId = @ItalyCountryId AND BU.UniverseId IN (@WellnessUniverseId, @GastronomyUniverseId)) THEN CASE PL.City WHEN 'Roma' THEN @RomaMarketingRegionId WHEN 'Milano' THEN @MilanoMarketingRegionId ELSE mr1.MarketingRegionId END ELSE mr1.MarketingRegionId END AND EditionBrief.fkSpecimenId = @BoxCodeS
Execution Plan
https://www.brentozar.com/pastetheplan/?id=BydkTId-I https://www.brentozar.com/pastetheplan/?id=ByeEpUu-U https://www.brentozar.com/pastetheplan/?id=HkYU0Ud-I https://www.brentozar.com/pastetheplan/?id=B1Qi0UOZI