A poorly performing database application can cost each user time, and have an impact on other applications running on the same computer or the same network. This book will help DBA's and programmers improve the performance of their databases. It is not an introduction to SQL, nor is it a tuning manual for a particular SQL implementation. It is a guide for users and programmers who want to improve SQL performance no matter what brand of SQL they use. It will provide tuning tips for common situations, such as how to change a query so it will go faster and how to shift work from the server to the client. All the ideas have been tested against the eight leading DBMS applications. Almost all large organizations and companies today run more than one type of database. This is the only book to cover database tuning for them.
Table of Contents
You Don't Know that Your DBMS Is Good….
You Know that Even Good Tools Work Better in Skilled Hands….Acknowledgments. 1. Facilis Descensus Averni.
This Subject Is Important.
The Big Eight.
Terminology and Expectations.
Generalities.2. Simple Searches.
Code for Points.
Dead Code Elimination.
Ensure You Use the Right DBMS.
The Bottom Line: General Tuning.
AND Plus OR.
The Bottom Line: Specific Tuning.
Parting Shots.3. ORDER BY.
General Sort Considerations.
The ORDER BY Clause.
To Sort or Not to Sort.
The Bottom Line: General Sorts.
Character Sort Support.
The Bottom Line: Character Sorts.
Encouraging Index Use.
The Bottom Line: Other Options.
Parting Shots.4. GROUP BY.
Optimal GROUP BY Clauses.
Alternatives to GROUP BY.
The Bottom Line: Optimal GROUP BY Clauses.
The Bottom Line: Sorting.
Set Functions and Summary Aggregates.
Multiple Aggregation Levels.
The Bottom Line: Aggregates.
Parting Shots.5. Joins.
Join Plan Strategies.
Avoid the Join Strategies
The Bottom Line: Avoiding Joins.
Three-Way Joins and Beyond.
Old Style versus ANSI Style.
Parting Shots.6. Subqueries.
Join versus Subquery.
The Bottom Line: Join versus Subquery.
IN or EXISTS?
The Bottom Line: Syntax Choices.
Parting Shots.7. Columns.
How Big Is the Size Factor?
Fixed or Variable?
The Bottom Line: The Size Factor.
Variant Character Sets.
The Bottom Line: Characters.
The Bottom Line: Temporals.
The Bottom Line: Numbers.
The Bottom Line: Bits.
The Bottom Line: LOBs.
The Bottom Line: NULLs.
Column Order Within Rows.
The Bottom Line: Column Order.
Parting Shots.8. Tables.
The Storage Hierarchy.
The Bottom Line: Storage Hierarchy.
Free Page Space.
The Bottom Line: Heaps.
The Bottom Line: Clusters.
The Normal Forms.
Breaking Normalization Rules.
The Bottom Line: Normalization.
Bottom Line: Views.
Parting Shots.9. Indexes.
Searching a B-tree.
Inserting into a B-tree.
Deleting from a B-tree.
Rebuilding a B-tree.
The Bottom Line: B-trees.
Types of Indexes.
The Bottom Line: Types of Indexes.
The Bottom Line: Bitmap Indexes.
Other Index Variations.
Index Key Values.
The Bottom Line: Index Key Values.
Parting Shots.10. Constraints.
The Bottom Line: NOT NULL Constraints.
The Bottom Line: CHECK Constraints.
The Bottom Line: FOREIGN KEY Constraints.
The Bottom Line: PRIMARY KEY Constraints.
The Bottom Line: UNIQUE Constraints.
The Bottom Line: Triggers.
The Bottom Line: Disabling Constraints.
The Bottom Line: Client Validations.
Redundant SELECT Clauses.
The Bottom Line: Redundant SELECTs.
Parting Shots.11. Stored Procedures.
Advantages of Stored Procedures.
The Bottom Line: Stored Procedures.
Parting Shots.12. ODBC.
Tracing MS Query.
The Bottom Line: SQLPrepare.
The Bottom Line: Fetch Loops.
The Bottom Line: Data-Change Statements.
The Bottom Line: Catalog Functions.
Parting Shots.13. JDBC.
Connections and DBMS Info.
The Bottom Line: Connections.
The Bottom Line: Query Prepping.
How Many Rows?
The Bottom Line: Result Sets.
The Bottom Line: Data Changes.
Parting Shots.14. Data Changes.
The Bottom Line: Logs.
The Bottom Line: INSERT.
The Bottom Line: UPDATE.
The Bottom Line: DELETE.
The Bottom Line: Ugly Updates.
FETCH and Data Changes.
The Bottom Line: FETCH and Data Changes.
COMMIT and ROLLBACK.
The Bottom Line: COMMIT and ROLLBACK.
Parting Shots.15. Locks.
What Is a Lock?
The Bottom Line: Locks.
Concurrency Problems and Isolation Levels.
READ UNCOMMITTED Transactions.
READ COMMITTED Transactions.
REPEATABLE READ Transactions.
READ ONLY or FOR UPDATE.
The Bottom Line: Isolation Levels.
The Bottom Line: Index Locks.
The Bottom Line: Hot Spots.
The Bottom Line: Optimistic Locking.
The Scan Trick.
Parting Shots.16. Clients and Servers.
The Bottom Line: Middleware.
Server Processes and Threads.
Separateness and Parallelism.
The Bottom Line: Server Processes and Threads.
What Should the Client Do?
The Bottom Line: Client Tips.
Parting Shots.17. Cost-Based Optimizers.
Statistics and Histograms.
Parting Shots.Appendix A. Further Reading. Appendix B. Glossary. Index. 0201791692T08272002
SQL Performance Tuning is a handbook of practical solutions for busy database professionals charged with managing an organization's critically important data. Covering today's most popular and widely installed database environments, this book is an indispensable resource for managing and tuning SQL across multiple platforms.
Packed with tips, techniques, and best practices, this hands-on guide covers SQL commands and queries over a wide range of conditions and environments. Every facet of the SQL environment is covered, from concurrency control to optimization-and every issue in between. The book includes an overview of each of the most widely used database management systems (DBMS) and provides tuning tips for common day-to-day situations.
Topics covered include: General and specific tuning General sort considerations and options Joins and subqueries Columns and tables Indexes, including B-trees and bitmaps Constraints and stored procedures ODBC and JDBC Data changes and concurrency control (locking) Clients, servers, and middleware
Whether you are a programmer, consultant, or user, you will find SQL Performance Tuning an indispensable guide to optimizing SQL performance across today's popular database environments.
Throughout SQL Performance Tuning, ideas and techniques are tested on a variety of popular SQL environments, including IBM DB2, Informix, Ingres, InterBase, Microsoft SQL Server, MySQL, Oracle, and Sybase ASE. The book's practical examples are written in ANSI/ISO Standard SQL: 1999.
Peter Gulutzan is a principal of Ocelot Computer Services Inc. in Alberta, Canada. Peter is a technical writer and computer programmer who has worked with SQL since 1986. With Trudy Pelzer, he has written three books, Optimizing SQL (CMP Books, 1994), Optimizing C with Assembly Code (CMP Books, 1995), and SQL-99 Complete, Really (CMP Books, 1999).
Trudy Pelzer is a principal of Ocelot Computer Services Inc. in Alberta, Canada. Trudy is a technical writer and computer programmer who has worked with SQL since 1986. With Peter Gulutzan, she has written three books, Optimizing SQL (CMP Books, 1994), Optimizing C with Assembly Code (CMP Books, 1995), and SQL-99 Complete, Really (CMP Books, 1999).