[dba-SQLServer] Adding indexes programmatically

John W. Colby jwcolby at colbyconsulting.com
Mon Dec 13 15:54:07 CST 2004


>So your not actually indexing every field, as you first stated..  

I am building a set of 30 or so tables, with related fields pulled from the
big table.  The big table has 640 fields and SQL Server can only create 240
indexes.  I am indeed indexing every field in every one of the smaller
"related field" tables with the sole exception of the address table.  So no,
I am not indexing every field, but I am indexing about 600 out of 640
fields.

>FYI, having an index will not necessarily avoid a table scan. Unfortunately
its just not that simple.

I am aware of that.  However it is a simple fact that without an index you
WILL use a table scan.  So while the presence of an index will not guarantee
that a table scan will not be performed, the absence of an index does in
fact guarantee that a table scan will be performed.


John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Haslett,
Andrew
Sent: Monday, December 13, 2004 4:27 PM
To: 'dba-sqlserver at databaseadvisors.com'
Subject: RE: [dba-SQLServer] Adding indexes programmatically


So your not actually indexing every field, as you first stated..  

FYI, having an index will not necessarily avoid a table scan. Unfortunately
its just not that simple.

Anyway, suit yourself  - good luck.

-----Original Message-----
From: John W. Colby [mailto:jwcolby at colbyconsulting.com] 
Sent: Tuesday, 14 December 2004 3:22 AM
To: dba-sqlserver at databaseadvisors.com
Subject: RE: [dba-SQLServer] Adding indexes programmatically

In this case performance will ALWAYS improve.  Remember that this is a bulk
mail database, 640 fields of address info (indexes not needed except on zip)
and demographics.  All the client ever wants is COUNTS of records with
specific demographics.  

In order to count records you use an index or a table scan.  There are 64
MILLION records.  A table scan is not an option.  If a field is going to be
used in a where clause to count records, it absolutely must must must have
an index.  I have run a test and it takes approximately 1 minute 30 seconds
to get a count of records using a where on an indexed field.  It takes OVER
24 hours to get the same count with no index.  Imagine having to do a where
on 7 fields with no index.

"Yea, I can count that for you, I'll send it in a week ok?"

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Haslett,
Andrew
Sent: Monday, December 13, 2004 6:01 AM
To: 'dba-sqlserver at databaseadvisors.com'
Subject: RE: [dba-SQLServer] Adding indexes programmatically


Are you sure you need to index every field?

There's quite a bit more to it compared to Access where you generally just
put an index on every field you think you might search on. Overall
performance isn't generally going to improve by adding an index on every
field..

Numerous factors come into play such as performance, placement (physically)
of indexes, types, disk space etc.  especially considering  the size of your
database..

There's a reason there's a course on this stuff.  Probably 3 days of the 5
day admin course covers indexes and its close to the most boring stuff I've
ever sat through!!

Easiest method is to usually let the wizard decide what indexes you need.  

-----Original Message-----
From: John W. Colby [mailto:jwcolby at colbyconsulting.com]
Sent: Sunday, 12 December 2004 4:05 PM
To: SQLServer
Subject: [dba-SQLServer] Adding indexes programmatically

Does anyone have code to add indexes to every field in a table?  I am
breaking the nVLDB table down into subsets of related fields in smaller
tables and need to index each field.  The PK field is just that, an integer
and unique.  The rest are just text fields and non-unique.

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/


_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com

IMPORTANT - PLEASE READ ******************** This email and any files
transmitted with it are confidential and may contain information protected
by law from disclosure. 
If you have received this message in error, please notify the sender
immediately and delete this email from your system. 
No warranty is given that this email or files, if attached to this email,
are free from computer viruses or other defects. They are provided on the
basis the user assumes all responsibility for loss, damage or consequence
resulting directly or indirectly from their use, whether caused by the
negligence of the sender or not.
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com




_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com

IMPORTANT - PLEASE READ ******************** 
This email and any files transmitted with it are confidential and may 
contain information protected by law from disclosure. 
If you have received this message in error, please notify the sender 
immediately and delete this email from your system. 
No warranty is given that this email or files, if attached to this 
email, are free from computer viruses or other defects. They 
are provided on the basis the user assumes all responsibility for 
loss, damage or consequence resulting directly or indirectly from 
their use, whether caused by the negligence of the sender or not.
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com







More information about the dba-SQLServer mailing list