I certainly didn't know Access would create indexes based on column
names. That seems weird indeed. But it probably explains why these
indexes are there. Whoever built Northwind may not have known there were
there.
You can *see* this then you are in table design mode...if you type in a
field name..and choose the type as number *and* the field name ends in
id...notice how the "index" property is set...you can if you please at
this point set the field to no index. So, this is NOT a invisible
occurrence...but just simply a default that access has, and you can EASILY
see this during the field design/creating process when in table design
mode.
Isn't it true that having extra indexes can also be a bad thing? It
takes time to change the index whenever a new row is added, a row is
deleted, or when the subject column is updated. This is NOT so good for
performance.
Yes...have to 100% agree. Just throwing up a index on every field with
blind eyes is just as bad (or worse!!) as a approach of not having any
indexes at all!!
So, that default is just a guess that MOST fields that are number type,
and end in ID likely are VERY good candidates to be indexed...but, not
always...
This decision to index or not....often comes down to the black art of
performance. For example, if we were NEVER to search, or build reports by
productID, or category, then those indexes would most certainly be not
needed, and would be a performance liability here. (however, those fields
are part of relationships...and thus they *really* do need to be
indexed!).
In the case of relational data joins, again the query processor can, and
*often* will use the index on the foreign key field.
Having met you in the past, I am aware that a considerable amount of your
work is with sql server. It turns out that missing a index here or there
when using sql server is not so bad from a network point of view. If you
search for a productID with sql server, and no index is present, then sql
server will perform a table scan to get that match. However, during this
scan, NO NETWORK LOAD occurs. Only AFTER sql server finds the records,
does it send them down the wire. However, the sql server disk drive
certainly did get a workout..and more load was placed on the server.
So, often missing a index here, or there does not really effect *NETWORK*
traffic and performance very much with sql server.
With a file share/jet on a network, then this is a much more critical
issue.
So, sql server can do the search locally, and THEN send the records. With
a file share/jet system, that index is REALLY important, since without the
index, all records will travel across the network when searching. With a
index, only those matching records will travel. down the network wire.
So, good indexing is much more needed when you don't have sql server. In
fact, you have to be MORE aggressive in the use of indexes for a file
share as compared to sql server...
is quite reasonable. The amount of performance gained with an index
would depend on what proportion of the table is filtered. If a filter
includes 80% of the table, then a table scan is not so inefficient -
you're going to have to read 80% of the rows anyway. If the filter
includes 1% of the table, an index could be a big boost. Makes sense
here.
Yup..agreed...
Now, the question is, are these indexes used somewhere in Northwind,
justifying their existence? Well, you might come along and filter by
just about any column in the database, right? So, let's start out with
all the columns indexed, just for good measure. Somehow, that's the
impression I'm getting here. Not really a good idea.
Well, they did not index all of the fields. Another *Very* important point
here is that those fields are part of a relationship.
If you build a form based on Suppliers, and then have a sub-form to
display/show all of the products, how will access retrieve ONLY just the
records that belong to a given SupplerID? We load one suppler...but have a
sub-form of products. In this case, with a with NO index on the
[Products].[SupplerID] field, then table scans will occur. So, a index is
very impoarant here.
In addition to sub-forms, the issue of building a relational sql join from
Suppliers to products also *really* needs a index to perform a join with
any amount of performance. We might restive two Suppliers...and want to
see all of their products. JET (and sql server) can thus restive the two
records..and then based on the index field...grab the child records here
(say, the 12, or 15 products). Without a index on the products.SupplerID
field....jet (or sql server) can't just retrieve the few needed records.
In fact, one the BEST performance gains you can get in ms-access is to
ensure that ALL Forign key fields are indexed for relations. I index ALL
of these in my applications.
I'll be sure none of my numeric columns ends in ID. That's for sure. I
like to control the design of my tables, not have it taken from me.
As mentioned, this is only a default presented *during* table design mode.
You can see/choose the index setting. So, it is more a default during
design mode, and NOT a hidden default that you don't know about...(
Try creating a test mdb file...and start a new table in design mode. .I
believe access also scans for "code" and a few other types of keywords
that will "default" the index setting to change from none to
"indexed:....but, note it is ALWAYS in plain view to see, and this ONLY
occurs when you are adding a new field.........it is never done under the
covers hidden...
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.members.shaw.ca/AlbertKallal