April 6, 2007 at 2:09 pm
Hi everyone,
I have a problem in query execution.
I know covering indexes can contain max. 16 columns.
In my case, I have a query, which takes data from view (View consists of 50 columns, joins and so on). When I execute that query, it shows Index scan in one table(this table consists of more than 2 millions records).
I tried to remove index scan ( which takes alot of logical records ), creating indexe but it again leads bookmark lookups. I know i need to create covering index to remove such bookmarks. But i am unable to cover all columns(because this query consists of 25 columns from that table).
How can remove such index scans, bookmark lookups ?
Let me know if you want any information.
ASAP
Thanks
AKP
April 6, 2007 at 6:03 pm
A 25 column covering index just might do it ... but I'm thinking the view is written incorrectly. Do you have calculations on the columns in the WHERE or ON clauses? If so, that could certainly cause the problems you speak of...
--Jeff Moden
Change is inevitable... Change for the better is not.
April 6, 2007 at 8:31 pm
How many of the 50 columns are you querying for and how many rows are you getting. That combined with your run time will tell us more.
Run this statement with your query and post the output message:
set statistics IO on
April 7, 2007 at 6:13 pm
Index should cover columns used in WHERE clause, not in SELECT list.
_____________
Code for TallyGenerator
April 7, 2007 at 6:54 pm
When I create a index including all columns of where clause, it shows bookmark Lookups with index seek. But this also becomes costly for query execution. What can I do ?
thanks
AKP
April 9, 2007 at 2:05 am
You rarely need an index for more than few columns. For index to be efficient, it must assure at least partial selectivity, best on most selective column.
For example, you have 1 mil. rows (not necessarily a single table), the most selective column in where selects them 2000, full where selects them 200. In such case it's most efficient to have index on "the most selective column", as sequential scan of rowset based on this index of more efficient than having a huge 25 column index.
Besides, with 25 column index you'd have to always include first index column in where and hope in would be used.
April 9, 2007 at 8:49 am
Ther is apparently some confusion about a covering index. Indeed, the select list should be covered by such an index. Usually the first term is the PK or specifically designed to be accessed in the where clause, and the covered columns follow.
From the BOL:
"Covering indexes can improve query performance because all the data needed to meet the requirements of the query exists within the index itself. That is, only the index pages, and not the data pages of the table or clustered index, are required to retrieve the requested data; therefore, reducing overall disk I/O. For example, a query of columns a and b on a table that has a composite index created on columns a, b, and c can retrieve the specified data from the index alone."
The limit of 16 columns in an index makes the use of a covering index for more than 16 columns not an option in SQL 2000.
In SQL 2005, you can include non-indexed columns that will be stored in the leaf level of the index's B-Tree, which is actually an improvement over using regular indexes to achieve the desired effect.
It may be possible to create two covering indexes and join the table twice, picking the appropriate set of columns from each instance of the table, but I don't have any experience doing anything like that.
jg
April 9, 2007 at 10:21 am
Well put Jeff.
I think to help this chap we need the follow:
* the query
* current run time
* desired run time
* the amount of data being returned.
* the output of from set statistics I/O ON
I'm guessing the chap is new to tuning and general advice on indexing isn't helping him.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply