Cost-Based Oracle Fundamentals

Book description

The question, "Why isn't Oracle using my index?" must be one of the most popular (or perhaps unpopular) questions ever asked on the Oracle help forums. You've picked exactly the right columns, you've got them in the ideal order, you've computed statistics, you've checked for null columns—and the optimizer flatly refuses to use your index unless you hint it. What could possibly be going wrong?

If you've suffered the frustration of watching the optimizer do something completely bizarre when the best execution plan is totally obvious, or spent hours or days trying to make the optimizer do what you want it to do, then this is the book you need. You'll come to know how the optimizer thinks, understand why it makes mistakes, and recognize the data patterns that make it go awry. With this information at your fingertips, you will save an enormous amount of time on designing and trouble-shooting your SQL.

The cost-based optimizer is simply a piece of code that contains a model of how Oracle databases work. By applying this model to the statistics about your data, the optimizer tries to efficiently convert your query into an executable plan. Unfortunately, the model can't be perfect, your statistics can't be perfect, and the resulting execution plan may be far from perfect.

In Cost-Based Oracle Fundamentals, the first book in a series of three, Jonathan Lewis—one of the foremost authorities in this field—describes the most commonly used parts of the model, what the optimizer does with your statistics, and why things go wrong. With this information, you'll be in a position to fix entire problem areas, not just single SQL statements, by adjusting the model or creating more truthful statistics.

Table of contents

  1. Title Page
  2. Contents at a Glance
  3. Contents
  4. Foreword
  5. About the Author
  6. About the Technical Reviewers
  7. Acknowledgments
  8. Introduction
    1. Why Bother?
    2. What's in This Book
    3. What's Not in This Book
    4. What's in Future Books
    5. Organization
    6. The Obligatory Dire Warning
    7. Conclusion
    8. With Apologies to the Late Douglas Adams
    9. Test Cases
  9. CHAPTER 1: What Do You Mean by Cost?
    1. Optimizer Options
    2. So What Is the Cost?
    3. Transformation and Costing
    4. WYSIWYG?
    5. Summary
    6. Test Cases
  10. CHAPTER 2: Tablescans
    1. Getting Started
    2. Onwards and Upwards
    3. The BCHR Is Dead! Long Live the BCHR!
    4. Parallel Execution
    5. Index Fast Full Scan
    6. Partitioning
    7. Summary
    8. Test Cases
  11. CHAPTER 3: Single Table Selectivity
    1. Getting Started
    2. Null Values
    3. Using Lists
    4. Range Predicates
    5. Two Predicates
    6. Problems with Multiple Predicates
    7. Summary
    8. Test Cases
  12. CHAPTER 4: Simple B-tree Access
    1. Basics of Index Costing
    2. Getting Started
    3. CPU Costing
    4. Loose Ends
    5. Summary
    6. Test Cases
  13. CHAPTER 5: The Clustering Factor
    1. Baseline Example
    2. Column Order
    3. Extra Columns
    4. Correcting the Statistics
    5. Loose Ends
    6. Summary
    7. Test Cases
  14. CHAPTER 6: Selectivity Issues
    1. Different Data Types
    2. Leading Zeros
    3. Deadly Defaults
    4. Discrete Dangers
    5. Surprising sysdate
    6. Function Figures
    7. Correlated Columns
    8. Transitive Closure
    9. Constraint-Generated Predicates
    10. Summary
    11. Test Cases
  15. CHAPTER 7: Histograms
    1. Getting Started
    2. Generic Histograms
    3. Frequency Histograms
    4. "Height Balanced" Histograms
    5. Data Problems Revisited
    6. Summary
    7. Test Cases
  16. CHAPTER 8: Bitmap Indexes
    1. Getting Started
    2. Bitmap Combinations
    3. CPU Costing
    4. Interesting Cases
    5. Summary
    6. Test Cases
  17. CHAPTER 9: Query Transformation
    1. Getting Started
    2. Filtering
    3. General Subqueries
    4. Star Transformation Joins
    5. Star Joins
    6. The Future
    7. Summary
    8. Test Cases
  18. CHAPTER 10: Join Cardinality
    1. Basic Join Cardinality
    2. Join Cardinality for Real SQL
    3. Extensions and Anomalies
    4. Three Tables
    5. Nulls
    6. Implementation Issues
    7. Difficult Bits!
    8. Features
    9. An Alternative Viewpoint
    10. Summary
    11. Test Cases
  19. CHAPTER 11: Nested Loops
    1. Basic Mechanism
    2. Worked Example
    3. Sanity Checks
    4. Summary
    5. Test Cases
  20. CHAPTER 12: Hash Joins
    1. Getting Started
    2. Trace Files
    3. Headaches
    4. Comparisons
    5. Multitable Joins
    6. Summary
    7. Test Cases
  21. CHAPTER 13: Sorting and Merge Joins
    1. Getting Started
    2. Cost of Sorts
    3. Comparisons
    4. Merge Joins
    5. Aggregates and Others
    6. Final Warning
    7. Summary
    8. Test Cases
  22. CHAPTER 14: The 10053 Trace File
    1. The Query
    2. The Execution Plan
    3. The Environment
    4. The Trace File
    5. Join Evaluation Summary
    6. Test Cases
  23. APPENDIX A: Upgrade Headaches
    1. dbms_stats
    2. Frequency Histograms
    3. CPU Costing
    4. Rounding Errors
    5. Bind Variable Peeking
    6. Nulls Across Joins
    7. B-tree to Bitmap Conversions
    8. Index Skip-Scans
    9. AND-Equal
    10. Index Hash Join
    11. In-List Fixed
    12. Transitive Closure
    13. sysdate Arithmetic Fixed
    14. Indexing Nulls
    15. pga_aggregate_target
    16. Sorting
    17. Grouping
    18. Sanity Checks
    19. Going Outside the Limits
    20. Type Hacking
    21. optimizer_mode
    22. Descending Indexes
    23. Complex View Merging
    24. Unnest Subquery
    25. Scalar and Filter Subqueries
    26. Parallel Query Changes x 2
    27. Dynamic Sampling
    28. Temporary Tables
    29. Dictionary Stats
  24. APPENDIX B: Optimizer Parameters
    1. optimizer_features_enable
    2. The 10053 Trace File
    3. v$sql_optimizer_env
  25. Index

Product information

  • Title: Cost-Based Oracle Fundamentals
  • Author(s): Jonathan Lewis
  • Release date: November 2005
  • Publisher(s): Apress
  • ISBN: 9781590596364