Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I work on sql server 2017 i face issue when run simple query it take 32 second to run two rows

so it is very slow according to number of rows returned and size of row not big

my execution plan is

https://www.brentozar.com/pastetheplan/?id=HyaIx0I6Y

script table

What I have tried:

SQL
CREATE TABLE [Parts].[TradeCodeControl](
     [TradeCodeControlID] [int] IDENTITY(1,1) NOT NULL,
     [VersionYear] [int] NULL,
     [Version] [float] NULL,
     [CodeTypeID] [int] NULL,
     [RevisionID] [bigint] NULL,
     [Code] [varchar](20) NULL,
     [ZPLID] [int] NULL,
     [ZfeatureKey] [bigint] NULL,
     [ZValue] [nvarchar](2500) NULL,
     [ZfeatureType] [nvarchar](200) NULL,
     [Comment] [nvarchar](3000) NULL,
     [ModifiedDate] [datetime] NULL,
     [CreatedDate] [datetime] NOT NULL,
     [Modifiedby] [int] NULL,
     [CreatedBy] [int] NULL,
     [OrderSequence] [tinyint] NULL,
  CONSTRAINT [PK__TradeCod__49C7EB212E609428] PRIMARY KEY CLUSTERED 
 (
     [TradeCodeControlID] ASC
 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
 ) ON [PRIMARY]
    
 GO
    
 SET ANSI_PADDING ON
 GO
    
 ALTER TABLE [Parts].[TradeCodeControl] ADD  CONSTRAINT [DF__TradeCode__Creat__2439A564]  DEFAULT (getdate()) FOR [CreatedDate]
 GO
Posted
Updated 23-Jan-22 8:48am

You should have a secondary Index on (ZPLID, ZFeatureKey, ZValue,Code,CodeTypeID,RevisionID) which should solve your performance issue
 
Share this answer
 
Comments
ahmed_sa 20-Jan-22 7:46am    
why you say index for all these column
if i put index on zplid column will be correct or muest create on all these columns
Richard Deeming 20-Jan-22 8:27am    
Your plan clearly shows that 83% of the cost involves looking up the Code, CodeTypeID, and RevisionID columns from the table. Add them as included columns in your IX_ZPLID index, and that cost goes away.

CREATE INDEX (Transact-SQL) - SQL Server | Microsoft Docs[^]
ahmed_sa 20-Jan-22 9:06am    
so please are this correc
CREATE NONCLUSTERED INDEX IDX_ZPLID
ON ExtractReports.dbo.TPls ( ZPLID)
INCLUDE ( Code, CodeTypeID, RevisionID );
pity that you still don't understand that when you are asked to supply the info it means all of it - the explain plan you posted shows you have other indexes - so you need to put ALL of your indexes - both on source and on destination tables.

you also have given us a estimated plan - those are worthless as your real execution plan can be totally different and highlight a different issue.

it may even be that you need to change your PK to be non clustered and that your clustered index should instead be on a different set of columns - but without you telling us how this table is used, how it is normally accessible and what are the most common queries we can't help you properly and any index suggestion (or others) may not be the correct answer to your problem.
 
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