views:

401

answers:

2

I am working on optimizing a SQL query that goes against a very wide table in a legacy system. I am not able to narrow the table at this point for various reasons.

My query is running slowly because it does an Index Seek on an Index I've created, and then uses a Bookmark Lookup to find the additional columns it needs that do not exist in the Index. The bookmark lookup takes 42% of the query time (according to the query optimizer).

The table has 38 columns, some of which are nvarchars, so I cannot make a covering index that includes all the columns. I have tried to take advantage of index intersection by creating indexes that cover all the columns, however those "covering" indexes are not picked up by the execution plan and are not used.

Also, since 28 of the 38 columns are pulled out via this query, I'd have 28/38 of the columns in the table stored in these covering indexes, so I'm not sure how much this would help.

Do you think a Bookmark Lookup is as good as it is going to get, or what would another option be?

(I should specify that this is SQL Server 2000)

+1  A: 

You could create an index with included columns as another option

example from BOL, this is for 2005 and up

CREATE NONCLUSTERED INDEX IX_Address_PostalCode
    ON Person.Address (PostalCode)
    INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID);

To answer this part "I have tried to take advantage of index intersection by creating indexes that cover all the columns, however those "covering" indexes are not picked up by the execution plan and are not used." An index can only be used when the query is created in a way that it is sargable, in other words if you use function on the left side of the operator or leave out the first column of the index in your WHERE clause then the index won't be used. If the selectivity of the index is low then also the index won't be used

Check out SQL Server covering indexes for some more info

SQLMenace
Sorry - I should have specified that this is SQL 2000.
Sam Schutte
+1  A: 

OH,

the covering index with include should work. Another option might be to create a clustered indexed view containing only the columns you need.

Regards,
Lieven

Lieven