IBM DB2 for I Indexing Methods and Strategies Learn How to Use DB2 Indexes to Boost Performance
Total Page:16
File Type:pdf, Size:1020Kb
IBM DB2 for i indexing methods and strategies Learn how to use DB2 indexes to boost performance Michael Cain Kent Milligan DB2 for i Center of Excellence IBM Systems and Technology Group Lab Services and Training July 2011 © Copyright IBM Corporation, 2011 Table of contents Abstract........................................................................................................................................1 Introduction .................................................................................................................................1 The basics....................................................................................................................................3 Database index introduction .................................................................................................................... 3 DB2 for i indexing technology .................................................................................................................. 4 Radix indexes.................................................................................................................... 4 Encoded vector indexes .................................................................................................... 6 Bitmap indexes - the limitations ....................................................................................................... 6 EVI structure details......................................................................................................................... 7 EVI runtime usage............................................................................................................................ 8 Derived and sparse indexes............................................................................................ 10 DB2 for i indexing comparison with other databases ............................................................................ 11 Primary and clustered indexes ........................................................................................ 11 Partitioned and non-partitioned indexes.......................................................................... 12 Bitmapped indexing......................................................................................................... 12 DB2 for i usage of indexes..................................................................................................................... 13 Statistical usage ..............................................................................................................13 Implementation usage ..................................................................................................... 14 Selection ........................................................................................................................................ 15 Joining............................................................................................................................................ 15 Grouping ........................................................................................................................................ 15 Ordering ......................................................................................................................................... 15 Selection.......................................................................................................................... 15 Nested loop join with index.............................................................................................. 17 Grouping and ordering .................................................................................................... 19 Index-only access............................................................................................................ 21 DB2 for i indexes and optimization: A summary.................................................................................... 22 Indexing strategies for performance tuning...........................................................................23 Starting point.......................................................................................................................................... 23 Proactive approach................................................................................................................................ 24 Perfect radix index guidelines ......................................................................................... 25 Radix example 1: A one-table query..............................................................................................25 Radix example 2: A three-table query............................................................................................26 Radix example 3: Query with non-equal predicates ...................................................................... 27 Perfect encoded vector index guidelines ........................................................................ 27 EVI example 1: A one-table query ................................................................................................. 28 EVI example 2: A one-table query with uncovered predicates ...................................................... 28 Proactively tuning many queries ..................................................................................... 29 Reactive query tuning ............................................................................................................................ 29 Tuning one query against many queries ......................................................................... 31 Index tuning for multiple table queries............................................................................. 31 IBM DB2 for i indexing methods and strategies Indexing considerations...........................................................................................................33 Index creation: Best practices................................................................................................................ 33 Source management ....................................................................................................... 33 Performance settings....................................................................................................... 33 EVI considerations........................................................................................................... 34 Improving creation performance...................................................................................... 34 Comparing the creation of SQL indexes with keyed logical files........................................................... 35 Duplicate index considerations........................................................................................ 36 Creating an EVI compared with a radix ................................................................................................. 36 Estimating the number of indexes to create .......................................................................................... 36 Index maintenance................................................................................................................................. 37 Different maintenance options......................................................................................... 38 Parallel maintenance for insert operations...................................................................... 38 Maintenance options for batch and bulk operations........................................................ 39 EVI maintenance considerations..................................................................................... 40 Maximum number of distinct values...............................................................................................40 Insertion order ................................................................................................................................ 40 Tools for index analysis and tuning........................................................................................43 Index Advisor ......................................................................................................................................... 44 Index advice details......................................................................................................... 45 Index advice limitations ................................................................................................... 47 System-wide Index Advisor ............................................................................................. 48 Index Advice Condenser ................................................................................................. 49 Autonomic indexes .......................................................................................................... 50 Index Evaluator ...................................................................................................................................... 52 Visual Explain ........................................................................................................................................ 54 Temporary index feedback.............................................................................................. 55 SQL Performance Monitor (Database Monitor) .....................................................................................56 SQE Plan Cache...................................................................................................................................