Quote:
|
quote:So the new question is, (as silly as it sounds)...do I ever need to put indexes on table joins?
|
Thats actually an interesting question Rohan, given that Microsoft - in much of its query performance optimization lit - recommends explicitly indexing fields on both sides of a join.
Not a good thing to do in Access. Since Access creates a hidden index on all foreign key fields when you establish a relationship, if you explicitly create one, that means all you've done is duplicate an index. Now the Jet engine has twice as much work to do every time data in an indexed field changes (inserts, updates, deletes). If you insert a field into your table with 21 indexes, Jet now has to write to the index buffer 42 times instead of 21 times. Besides, Jet will use the implict index over the explicit index when queries are run anyway. The explicit index is simply ignored.
Here is a portion of the query plan that the Jet query optimizer produces when I run a simple query based on the Customers and Orders tables in Northwind:
--- temp query ---
- Inputs to Query -
Table 'MSysRelationships'
- End inputs to Query -
01) Restrict rows of table MSysRelationships
using rushmore
for expression "(szObject=wszTableName) OR (szReferencedObject=wszTableName)"
--- temp query ---
- Inputs to Query -
Table 'Customers'
Table 'Orders'
Using index 'CustomersOrders'
Having Indexes:
CustomersOrders 830 entries, 4 pages, 89 values
which has 1 column, fixed
CustomerID 830 entries, 4 pages, 89 values
which has 1 column, fixed
- End inputs to Query -
01) Inner Join table 'Customers' to table 'Orders'
using index 'Orders!CustomersOrders'
join expression "Customers.CustomerID=Orders.CustomerID"
"CustomersOrders" is the implicit index that Access creates on the CustomerID field in the Orders table, and that Jet uses to perform the query. "CustomerID" is the duplicate explicit index, which is not used. The indexes are identical: 830 entries, 4 pages, 89 values
A word of caution. Its possible to over-index a table. Jet automatically updates the indexes on a table every time a record is added or deleted, or any time the data in an indexed field changes. Don't be surprised if you perform, say, a bulk update operation (update 1000 records) on your 21 index table and it takes a while. Jet is busy writing to the index buffer 2100 times.
Indexes should be used cautiously,e.g. primary key fields, frequently sorted fields, and feilds that serve as query criteria. That's about it.
HTH,
Bob