Foxhound is the better* Database Monitor for SQL Anywhere.
*better: More thorough, more relevant, more effective.
...more Alerts, more All Clears, more details, more control in your hands.
|
[Home] | [Table of Contents] | [Previous Section] | [Next Section] |
Breck Carter
Last modified: February 12, 1998
mail to: bcarter@bcarter.com
The special index you get automatically with every primary key and unique constraint might not help in certain situations. If this happens then maybe it's time to explicitly create a second index on the primary key.
An explicit index can help when the structure of the automatic index is all wrong; e.g., when the columns are placed in the wrong order for certain sorting or searching criteria or the default ASC sort sequence in a multi-column primary key doesn't help with a particular ORDER BY clause.
Figure 15A shows that a primary key ORDER BY clause containing both ASC and DESC keywords takes longer than clauses with two ASC or two DESC keywords unless a second index is created to match the ORDER BY sort order. In this case it doesn't matter whether the index is declared UNIQUE or not. SQL Anywhere will use the UNIQUE index if both exist, however, so it's still OK to follow the Rule of Thumb "If an index is truly unique then declare it so."
Figure 15A - ASC Assumed For Primary Key Index
|
Another situation where an explicit index might help is when a huge number of child table rows exist for each parent row. A large "fan-out" from primary-to-foreign key values can cause the special primary-and-foreign-key index to grow fat and slow. For example, if there are 1000 rows in a child table for every parent row then a query based on the primary key must deal with 1000 index entries for every different primary key value.
Figure 15B shows that a primary key query can take twice as long when the fan-out is 1000 to 1 unless an explicit index is created. In this case the index must be declared as UNIQUE or SQL Anywhere will ignore it in favor of the slower but unique primary key index. This proves the Rule of Thumb "When an index is truly unique then declare it so."
Figure 15B - Foreign Key Fan-Out
|
The performance improvement might not be worth the effort of creating a second primary key index. If your database is lightly loaded, if you're using 4K pages or if you're running with a large cache you might not notice any problem at all. It's important to keep in mind the Rule of Thumb: "If it's fast enough then don't make it faster" or "If it ain't broke don't fix it."
[Home] | [Table of Contents] | [Previous Section] | [Next Section] |