Good query performance requires planning.
Carefully plan the design of the following:
For help in identifying performance issues, see the chapters "Ensuring Data Integrity," "Maintaining Databases," "Maintaining Storage Structures," and "Using the Query Optimizer."
Other important design issues are:
A thorough performance analysis must include each item in the following list. Areas are listed in the order of greatest gain. For example, if your database design is flawed, perfect server configuration cannot help you avoid query performance problems.
Choosing the correct table storage structure for your needs can improve concurrency and query performance. Remember that there is no substitute for testing and benchmarking your queries.
For tips on choosing storage structures and advantages and disadvantages of the various storage structures, see the chapter "Choosing Storage Structures and Secondary Indexes." For information on modifying and compressing storage structures and a discussion of overflow, see the chapter "Maintaining Storage Structures."
Key design is a complex subject. For additional information on keys, see the chapter "Choosing Storage Structures and Secondary Indexes."
Good keys have the following features:
Always document reasons for maintaining non-unique keys.
All keyed storage structures can enforce unique keys. They are:
Bad keys have the following features:
Updating the index can slow performance.
A mix of high and low duplication can cause inconsistent query performance.
Multi-column keys have special issues. If used improperly in your query, the key cannot be used and the search does a full-table scan.
Keep the following in mind:
When you use a short surrogate or internal key to replace a bad key, or because there is no good key, consider the performance trade-offs. The set processing of data includes the overhead of deriving the key.
Surrogate key types include:
Universal (a social security number or zip code are examples)
These are local to an organization, like an employee number.
Query design is a complex subject. Following these tips will improve the performance of your queries:
Can large table scans be avoided?
Consider using set autocommit on.