Home All Groups Group Topic Archive Search About

what kind of index to use in this situation.



Author
16 Mar 2006 2:26 PM
guoqi zheng
Dear sir,

I have got a table of about 10 fields, there is a ID (INT, Primary key)
field, but not automatically increased. I only use 5 out of 10 fields in the
WHERE or join clause. What kind of index should I create?

For example, 5 fields, A,B,C,D,E. 30% of query use A,C,E, 30% use A,B,C, 30%
use B,D,E, 10% use others...

How should I create the index... One index covering all 5 fields or seperate
index for each field?

Thanks in Advanced!

regards,

Guoqi Zheng
http://www.ureader.com

Author
16 Mar 2006 5:01 PM
SQLpro [MVP]
guoqi zheng a écrit :
> Dear sir,
>
> I have got a table of about 10 fields, there is a ID (INT, Primary key)
> field, but not automatically increased. I only use 5 out of 10 fields in the
> WHERE or join clause. What kind of index should I create?
>
> For example, 5 fields, A,B,C,D,E. 30% of query use A,C,E, 30% use A,B,C, 30%
> use B,D,E, 10% use others...

This mean 90% use a filter on A !

Set an index on A and retest... You will see later wich new column you
can index then


>
> How should I create the index... One index covering all 5 fields or seperate
> index for each field?

Multicolumns index had 3 disavantages :
1) maximize the amount of data storage
2) stats are only on the first col
3) (A, B, C) index can only be use for A or A + B or A + B + C queries
not A + C, not B + C...

A +

>
> Thanks in Advanced!
>
> regards,
>
> Guoqi Zheng
> http://www.ureader.com


--
Frédéric BROUARD, MVP SQL Server, expert bases de données et langage SQL
Le site sur le langage SQL et les SGBDR  :  http://sqlpro.developpez.com
Audit, conseil, expertise, formation, modélisation, tuning, optimisation
********************* http://www.datasapiens.com ***********************
Are all your drivers up to date? click for free checkup

Author
17 Mar 2006 1:54 AM
Doug
Indexes should be created in COLUMNS which are somewhat unique.

Male/Female is a bad column to index on.  Unique id's are usually great
index candidates.

if there is not a lot of changes to the table, then more indexes don't
actually hurt that much. If lots of changes, like a transaction table,
then minimize indexes.

Look in the where clauses. Indexes should mirror the columns in the
where clauses.

Bookmark and Share