Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I work on sql server 2012 query I face issue : when run query return 10 rows for only one part

it take 50 second I try to run it in another time may be pc have more load

but it take same time 50 second to return 10 rows for only one part .

I have may be 10000 part and records may be 15 million so I need to enhance performance to be best

so what I do to make query run in small time

this is my query

Paste The Plan - Brent Ozar Unlimited®[^]

EDIT: OPs query copied from link above
SQL
Select  distinct top 100 [Is Match]= case when isnull(NAVO.Name ,'') = DUFP.Value or (isnull(NAVO.Name ,'') = N'N/A' And DUFP.Value =N'-') then cast(1 as bit) else cast(0 as bit) end 
,DDD.ColumnName [Flat Feature],DUFP.FeatureName [Sourcing Feature],NAVO.Name [Flat Value],DUFP.Value [Sourcing value]
,C.CompanyName,p.PartNumber,dd.DataDefinition [PL]
, isnull(AVOS.Name,'') ApprovalStatus 
,isnull(rl.local_url,'') [local url],isnull( l.local_url,'') [DataSheet] ,isnull(NAVOUrl.Name ,'') [Data Sheet Type]
,isnull(NV.DKValue,'') [DK Value],FM.StatusId,FM.SplitFlag,FM.DkFeatureId,FM.separator,FM.separatororder
--test
,NPP.PartID , DUFP.ZpartID,starformat,Endformat into #finalTable 

from #getDeliveryConfiguration FM with(nolock)  
join [Excel_DK].dbo.Excel_DK DUFP with(nolock) on DUFP.FeatureName =FM.DK_Feature 
join [Z2DataCore].[Parts].[Nop_Part] p with(nolock) on DUFP.ZpartID =p.PartID
join [Z2DataCompanyManagement].[CompanyManagers].[Company] C with(nolock) on p.CompanyID = C.CompanyID

left join [Z2DataCore].[parts].[Nop_PartParamtric] NPP with(nolock) on NPP.PartID = DUFP.ZpartID 
left join [Z2DataCore].[dbo].[Core_DataDefinitionDetails] DDD with(nolock) on FM.Z_FeatureID=DDD.ColumnNumber

 join [Z2DataCore].[Parts].[Nop_PartParamtricAttribute] NPPA with(nolock) on NPP.[PartParamtricID] =NPPA. [PartParamtricID] and DDD.ColumnNumber= NPPA.[Key]
left join [Z2DataCore].[dbo].[Nop_AcceptedValuesOption] NAVO with(nolock) on NPPA.Value =NAVO. AcceptedValuesOptionID 
left join [Z2DataCore].[dbo].Nop_AcceptedValuesOption AVOS with(nolock) on AVOs.AcceptedValuesOptionID= NPPA.ApprovalID/*[ApprovalStatus]*/ and AVOS.AcceptedValuesID=2941
LEFT JOIN Z2URLSystem.zsrc.Local_URL l with(nolock) ON l.rec_id = NPPA.SourceURLID 

left JOIN [Z2DataCore].Parts.Nop_PartsFamilyAttribute fa with(nolock) ON fa.PartFamilyID = p.PartsFamilyID AND fa.[Key] = 20281007


left JOIN [Z2DataCore].dbo.Core_DataDefinition dd with(nolock) ON dd.ZproductCategoryID = fa.Value
LEFT JOIN [Z2DataCore].Parts.Nop_PartsFamilyAttribute Nfa with(nolock) ON Nfa.PartFamilyID = p.PartsFamilyID AND Nfa.[Key]=1400040081 

LEFT JOIN Z2URLSystem.zsrc.Revision r with(nolock) ON r.rec_id = Nfa.Value
LEFT JOIN Z2URLSystem.zsrc.Local_URL rl with(nolock) ON rl.rec_id = r.local_id
Left join [Z2DataCore].[dbo].[Nop_AcceptedValuesOption] NAVOUrl with(nolock) on NPPA.SourceURLType =NAVOUrl. AcceptedValuesOptionID

 left join [Z2DataCore].dbo.Core_DataDefinitiondeTails CDD with(nolock) on CDD.ColumnNumber=NPPA.[Key] and CDD.FeatureType in(2044,2043)
left outer join [Z2DataCore].dbo.Core_DataDefinition CD with(nolock) on CD.ID=CDD.DataDefinitionID
left join [Z2DataCore].[dbo].[NormalizationValue] NV with(nolock) on NAVO.AcceptedValuesOptionID=NV.AcceptedValuesOptionId and NV.ProductID=CD.ZNumber
   where C.CompanyName=@companyName And DUFP.PartNumber=@partNumber

order by DUFP.FeatureName


What I have tried:

CREATE NONCLUSTERED INDEX index1 
ON [dbo].[Excel_DK] ([PartNumber]) INCLUDE ([ZPartId],[FeatureName],[Value])
Posted
Updated 22-Jul-20 5:58am
v2
Comments
CHill60 22-Jul-20 4:37am    
I think you have gone seriously too far with normalization if you need to join 19 tables to get your data!
I'm not prepared to try to untangle all of that without some help from you - sample data for each of the tables and some expected results for example
ahmed_sa 22-Jul-20 6:41am    
so what I do to enhance performance of that long query
CHill60 22-Jul-20 11:48am    
I didn't notice this - if you use the "Reply" link to a post then the member gets a notification straight away.
Richard MacCutchan 22-Jul-20 7:37am    
Eighteen joins! No wonder it takes a long time. Try doing that manually when all the files are in different drawers of the filing cabinet.

19 tables (18 joins), with a where clause and a sort. That's why it takes 50 seconds.
 
Share this answer
 
Comments
ahmed_sa 22-Jul-20 6:40am    
so what I do to do that fast
#realJSOP 22-Jul-20 18:58pm    
You can examine the execution plan to find the bottlenecks, and expect to have to create several nixes.
Simplify your database schema - which you still haven't shared with us (I'm not going to make any explicit suggestions until you provide the tables with some sample data)

Read up on how to tune your queries - you've already found Brent's site, but there are articles here too e.g.
SQL Tuning Tutorial - Understanding a Database Execution Plan (1)[^]

Consider breaking down the query into multiple queries and use more temporary tables - add all the "fluff" (things like company name, urls) at the very end when you have done the bulk of the searching work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900