December 24, 2013 at 12:23 am
Hi all,
I have tables with structures like this:
/****** Object: Table [dbo].[ServiceCallJobPhoto] Script Date: 12/24/2013 12:48:50 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ServiceCallJobPhoto](
[ServiceCallJobPhotoId] [int] IDENTITY(1,1) NOT NULL,
[InstanceId] [nchar](3) NOT NULL,
[SiteId] [nchar](3) NOT NULL,
[ServiceCallJobId] [int] NULL,
[WorkDate] [datetime] NOT NULL,
[MechanicId] [int] NOT NULL,
[PhotoDescription] [nvarchar](75) NOT NULL,
[PhotoData] [nvarchar](max) NOT NULL,
[StatusFlag] [bit] NOT NULL,
[DateAdded] [datetime] NOT NULL,
[AddedBy] [nvarchar](75) NOT NULL,
[DateChanged] [datetime] NULL,
[ChangedBy] [nvarchar](75) NULL,
[LocalDateChanged] [datetime] NOT NULL,
[LocalChangedBy] [nvarchar](75) NOT NULL,
[SyncTimeStamp] [timestamp] NOT NULL,
CONSTRAINT [PK_ServiceCallJobPhoto] PRIMARY KEY CLUSTERED
(
[ServiceCallJobPhotoId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY],
CONSTRAINT [uq1_ServiceCallJobPhoto] UNIQUE NONCLUSTERED
(
[InstanceId] ASC,
[SiteId] ASC,
[ServiceCallJobId] ASC,
[MechanicId] ASC,
[WorkDate] ASC,
[PhotoDescription] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[ServiceCallJobPhoto] WITH CHECK ADD CONSTRAINT [FK_ServiceCallJobPhotoJobId] FOREIGN KEY([ServiceCallJobId])
REFERENCES [dbo].[ServiceCallJob] ([ServiceCallJobId])
GO
ALTER TABLE [dbo].[ServiceCallJobPhoto] CHECK CONSTRAINT [FK_ServiceCallJobPhotoJobId]
GO
ALTER TABLE [dbo].[ServiceCallJobPhoto] WITH CHECK ADD CONSTRAINT [FK_ServiceCallJobPhotoMechId] FOREIGN KEY([MechanicId])
REFERENCES [dbo].[Employee] ([EmployeeId])
GO
ALTER TABLE [dbo].[ServiceCallJobPhoto] CHECK CONSTRAINT [FK_ServiceCallJobPhotoMechId]
GO
As, the PK is created on an Identity Key column which is not going to be used in joins of stored prcedures.
Also, unique key is created on columns having datatype Datetime, nvarchar.
So, my concern is that as while performing joins clustered index will never be used and this leads to table scan
and also there may be performance impact due to column having datatype datetime used in keys.
What can be done to improve this?
Thanks in advance...
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
December 24, 2013 at 3:12 am
all NCI access that needs extra data will use the clustered index to fetch that data.
what columns do you expect to get used ?
Provide indexes for those columns and try to figure out if you can use included columns for index only access.
As a general guideline I suggest to provide FK indexes, unless proven they hurt your data systems performance.
As a status column datatyped bit, maybe a filtered index can reduce IO quite a bit depending on the distribution ratio .
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
December 24, 2013 at 5:47 am
ALZDBA (12/24/2013)
all NCI access that needs extra data will use the clustered index to fetch that data.what columns do you expect to get used ?
Provide indexes for those columns and try to figure out if you can use included columns for index only access.
As a general guideline I suggest to provide FK indexes, unless proven they hurt your data systems performance.
As a status column datatyped bit, maybe a filtered index can reduce IO quite a bit depending on the distribution ratio .
Should I drop unique constraint and make non clustered index only or add more column in unique constraint instead of creating another nonclustered index?
Also columns included in unique constraint if appear in non clustered index then will it make effect?
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
December 24, 2013 at 7:21 am
kapil_kk (12/24/2013)
Should I drop unique constraint and make non clustered index only or add more column in unique constraint instead of creating another nonclustered index?
If the index is there to enforce uniqueness, then it needs to be there, as-is to enforce uniqueness. Otherwise you're reducing the integrity of the database by potentially allowing duplicates.
Have you done performance tests? Is the performance of queries using this table inadequate?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 24, 2013 at 11:27 pm
GilaMonster (12/24/2013)
kapil_kk (12/24/2013)
Should I drop unique constraint and make non clustered index only or add more column in unique constraint instead of creating another nonclustered index?If the index is there to enforce uniqueness, then it needs to be there, as-is to enforce uniqueness. Otherwise you're reducing the integrity of the database by potentially allowing duplicates.
Have you done performance tests? Is the performance of queries using this table inadequate?
Yes, uniqueness are required.....
While running my stored procedure I see bookmark lookup so I thought to avoid that if I add my non clustered index columns to the unique non clustered only... due to that index also get reduced
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
December 26, 2013 at 1:43 pm
kapil_kk (12/24/2013)
GilaMonster (12/24/2013)
kapil_kk (12/24/2013)
Should I drop unique constraint and make non clustered index only or add more column in unique constraint instead of creating another nonclustered index?If the index is there to enforce uniqueness, then it needs to be there, as-is to enforce uniqueness. Otherwise you're reducing the integrity of the database by potentially allowing duplicates.
Have you done performance tests? Is the performance of queries using this table inadequate?
Yes, uniqueness are required.....
Then you can't add more columns to the unique constraint
While running my stored procedure I see bookmark lookup so I thought to avoid that if I add my non clustered index columns to the unique non clustered only... due to that index also get reduced
So there are key lookups. Are they a problem? Is the query not meeting it's performance requirements?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 27, 2013 at 3:00 am
GilaMonster (12/26/2013)
kapil_kk (12/24/2013)
GilaMonster (12/24/2013)
kapil_kk (12/24/2013)
Should I drop unique constraint and make non clustered index only or add more column in unique constraint instead of creating another nonclustered index?If the index is there to enforce uniqueness, then it needs to be there, as-is to enforce uniqueness. Otherwise you're reducing the integrity of the database by potentially allowing duplicates.
Have you done performance tests? Is the performance of queries using this table inadequate?
Yes, uniqueness are required.....
Then you can't add more columns to the unique constraint
While running my stored procedure I see bookmark lookup so I thought to avoid that if I add my non clustered index columns to the unique non clustered only... due to that index also get reduced
So there are key lookups. Are they a problem? Is the query not meeting it's performance requirements?
But if I add few column of non clustered index to unique constraint columns then also uniqueness will be retained.... so in that case can I go with this
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
December 27, 2013 at 4:28 am
kapil_kk (12/27/2013)
But if I add few column of non clustered index to unique constraint columns then also uniqueness will be retained.... so in that case can I go with this
Yes, and you'll end up with a redundant index and additional write overhead.
Once more with feeling....
Have you done performance tests? Is the performance of queries using this table inadequate? Is there a problem here at all?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply