sql server programming:
I've been up all night writing some new codesmith templates and was just looking over the execution plans on some of my queries and I noticed this one was doing 3 index seeks and 1 indes scan. Does anyone see what would be causing the index scan? Select [dbo].[LinkCategory].[LinkCategoryId], [dbo].[LinkCategory].[ParentLinkCategoryId], [dbo].[LinkCategory].[Name], [dbo].[LinkCategory].[Directory], [dbo].[LinkCategory].[FullDirectoryPath], [dbo].[LinkCategory].[HeaderCopyId], [dbo].[LinkCategory].[FooterCopyId], [dbo].[LinkCategory].[_Descriptor], [dbo].[LinkCategory].[_Rank], [dbo].[LinkCategory].[_Created], [dbo].[LinkCategory].[_Updated], [dbo].[LinkCategory].[_UpdatedBy], [dbo].[LinkCategory].[_UpdatedWith], [dbo].[LinkCategory].[_Inactive], [ParentLinkCategory].[LinkCategoryId] [ParentLinkCategory_LinkCategoryId], [ParentLinkCategory].[ParentLinkCategoryId] [ParentLinkCategory_ParentLinkCategoryId], [ParentLinkCategory].[Name] [ParentLinkCategory_Name], [ParentLinkCategory].[Directory] [ParentLinkCategory_Directory], [ParentLinkCategory].[FullDirectoryPath] [ParentLinkCategory_FullDirectoryPath], [ParentLinkCategory].[HeaderCopyId] [ParentLinkCategory_HeaderCopyId], [ParentLinkCategory].[FooterCopyId] [ParentLinkCategory_FooterCopyId], [ParentLinkCategory].[_Descriptor] [ParentLinkCategory__Descriptor], [ParentLinkCategory].[_Rank] [ParentLinkCategory__Rank], [ParentLinkCategory].[_Created] [ParentLinkCategory__Created], [ParentLinkCategory].[_Updated] [ParentLinkCategory__Updated], [ParentLinkCategory].[_UpdatedBy] [ParentLinkCategory__UpdatedBy], [ParentLinkCategory].[_UpdatedWith] [ParentLinkCategory__UpdatedWith], [ParentLinkCategory].[_Inactive] [ParentLinkCategory__Inactive], [HeaderCopy].[CopyId] [HeaderCopy_CopyId], [HeaderCopy].[Text] [HeaderCopy_Text], [HeaderCopy].[_Descriptor] [HeaderCopy__Descriptor], [HeaderCopy].[_Rank] [HeaderCopy__Rank], [HeaderCopy].[_Created] [HeaderCopy__Created], [HeaderCopy].[_Updated] [HeaderCopy__Updated], [HeaderCopy].[_UpdatedBy] [HeaderCopy__UpdatedBy], [HeaderCopy].[_UpdatedWith] [HeaderCopy__UpdatedWith], [HeaderCopy].[_Inactive] [HeaderCopy__Inactive], [FooterCopy].[CopyId] [FooterCopy_CopyId], [FooterCopy].[Text] [FooterCopy_Text], [FooterCopy].[_Descriptor] [FooterCopy__Descriptor], [FooterCopy].[_Rank] [FooterCopy__Rank], [FooterCopy].[_Created] [FooterCopy__Created], [FooterCopy].[_Updated] [FooterCopy__Updated], [FooterCopy].[_UpdatedBy] [FooterCopy__UpdatedBy], [FooterCopy].[_UpdatedWith] [FooterCopy__UpdatedWith], [FooterCopy].[_Inactive] [FooterCopy__Inactive] From [dbo].[LinkCategory] Left Outer Join [dbo].[LinkCategory] [ParentLinkCategory] (nolock) On [dbo].[LinkCategory].[ParentLinkCategoryId] = [ParentLinkCategory]. [ParentLinkCategoryId] Left Outer Join [dbo].[Copy] [HeaderCopy] (nolock) On [dbo]. [LinkCategory].[HeaderCopyId] = [HeaderCopy].[CopyId] Left Outer Join [dbo].[Copy] [FooterCopy] (nolock) On [dbo]. [LinkCategory].[FooterCopyId] = [FooterCopy].[CopyId] Where [dbo].[LinkCategory].[LinkCategoryId] = 1
I guess it might help to include that the index scan is on the self referencing join to LinkCategory
Just a thought on this. The outermost table, LinkCategory, is only limited by the WHERE clause test for LinkCategoryId = 1. Unless that is best satisfied by an index lookup then the outer table - or an index on the outer table - is going to be scanned. How else would it include all rows? Roy Harvey Beacon Falls, CT [quoted text, click to view] On Sun, 17 Jun 2007 23:47:20 -0000, chad.mccune@gmail.com wrote: >I've been up all night writing some new codesmith templates and was >just looking over the execution plans on some of my queries and I >noticed this one was doing 3 index seeks and 1 indes scan. Does >anyone see what would be causing the index scan? > > Select > [dbo].[LinkCategory].[LinkCategoryId], > [dbo].[LinkCategory].[ParentLinkCategoryId], > [dbo].[LinkCategory].[Name], > [dbo].[LinkCategory].[Directory], > [dbo].[LinkCategory].[FullDirectoryPath], > [dbo].[LinkCategory].[HeaderCopyId], > [dbo].[LinkCategory].[FooterCopyId], > [dbo].[LinkCategory].[_Descriptor], > [dbo].[LinkCategory].[_Rank], > [dbo].[LinkCategory].[_Created], > [dbo].[LinkCategory].[_Updated], > [dbo].[LinkCategory].[_UpdatedBy], > [dbo].[LinkCategory].[_UpdatedWith], > [dbo].[LinkCategory].[_Inactive], > [ParentLinkCategory].[LinkCategoryId] >[ParentLinkCategory_LinkCategoryId], > [ParentLinkCategory].[ParentLinkCategoryId] >[ParentLinkCategory_ParentLinkCategoryId], > [ParentLinkCategory].[Name] [ParentLinkCategory_Name], > [ParentLinkCategory].[Directory] [ParentLinkCategory_Directory], > [ParentLinkCategory].[FullDirectoryPath] >[ParentLinkCategory_FullDirectoryPath], > [ParentLinkCategory].[HeaderCopyId] >[ParentLinkCategory_HeaderCopyId], > [ParentLinkCategory].[FooterCopyId] >[ParentLinkCategory_FooterCopyId], > [ParentLinkCategory].[_Descriptor] >[ParentLinkCategory__Descriptor], > [ParentLinkCategory].[_Rank] [ParentLinkCategory__Rank], > [ParentLinkCategory].[_Created] [ParentLinkCategory__Created], > [ParentLinkCategory].[_Updated] [ParentLinkCategory__Updated], > [ParentLinkCategory].[_UpdatedBy] [ParentLinkCategory__UpdatedBy], > [ParentLinkCategory].[_UpdatedWith] >[ParentLinkCategory__UpdatedWith], > [ParentLinkCategory].[_Inactive] [ParentLinkCategory__Inactive], > [HeaderCopy].[CopyId] [HeaderCopy_CopyId], > [HeaderCopy].[Text] [HeaderCopy_Text], > [HeaderCopy].[_Descriptor] [HeaderCopy__Descriptor], > [HeaderCopy].[_Rank] [HeaderCopy__Rank], > [HeaderCopy].[_Created] [HeaderCopy__Created], > [HeaderCopy].[_Updated] [HeaderCopy__Updated], > [HeaderCopy].[_UpdatedBy] [HeaderCopy__UpdatedBy], > [HeaderCopy].[_UpdatedWith] [HeaderCopy__UpdatedWith], > [HeaderCopy].[_Inactive] [HeaderCopy__Inactive], > [FooterCopy].[CopyId] [FooterCopy_CopyId], > [FooterCopy].[Text] [FooterCopy_Text], > [FooterCopy].[_Descriptor] [FooterCopy__Descriptor], > [FooterCopy].[_Rank] [FooterCopy__Rank], > [FooterCopy].[_Created] [FooterCopy__Created], > [FooterCopy].[_Updated] [FooterCopy__Updated], > [FooterCopy].[_UpdatedBy] [FooterCopy__UpdatedBy], > [FooterCopy].[_UpdatedWith] [FooterCopy__UpdatedWith], > [FooterCopy].[_Inactive] [FooterCopy__Inactive] > From > [dbo].[LinkCategory] > Left Outer Join [dbo].[LinkCategory] [ParentLinkCategory] (nolock) >On [dbo].[LinkCategory].[ParentLinkCategoryId] = [ParentLinkCategory]. >[ParentLinkCategoryId] > Left Outer Join [dbo].[Copy] [HeaderCopy] (nolock) On [dbo]. >[LinkCategory].[HeaderCopyId] = [HeaderCopy].[CopyId] > Left Outer Join [dbo].[Copy] [FooterCopy] (nolock) On [dbo]. >[LinkCategory].[FooterCopyId] = [FooterCopy].[CopyId] > Where
(chad.mccune@gmail.com) writes: [quoted text, click to view] > I've been up all night writing some new codesmith templates and was > just looking over the execution plans on some of my queries and I > noticed this one was doing 3 index seeks and 1 indes scan. Does > anyone see what would be causing the index scan?
What sort of join do you have? The optimizer could prefer a merge join or a hash join over a nested-loops join, not necessarily a bad thing, as it means that it reads the index only once. Without seeing the plan or knowing the table and indexes, it's difficult to say much more. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at
Don't see what you're looking for? Try a search.
|