Relational Database Index Design
Total Page:16
File Type:pdf, Size:1020Kb
RReellaattiioonnaall DDaattaabbaassee IInnddeexx DDeessiiggnn Prerequisite for Index Design Workshop Tapio Lahdenmaki April 2004 Copyright Tapio Lahdenmaki, DBTech Pro 1 Relational Database Index Design CHAPTER 1: INTRODUCTION........................................................................................................................4 INADEQUATE INDEXING .......................................................................................................................................4 THE IMPACT OF HARDWARE EVOLUTION ............................................................................................................5 Volatile Columns Should Not Be Indexed – True Or False? ..........................................................................7 Example ..........................................................................................................................................................7 Disk Drive Utilisation.....................................................................................................................................8 SYSTEMATIC INDEX DESIGN ................................................................................................................................9 CHAPTER 2........................................................................................................................................................13 TABLE AND INDEX ORGANIZATION ........................................................................................................13 INTRODUCTION ..................................................................................................................................................13 INDEX AND TABLE PAGES .................................................................................................................................14 INDEX ROWS .....................................................................................................................................................14 THE INDEX STRUCTURE .....................................................................................................................................14 TABLE ROWS .....................................................................................................................................................15 BUFFER POOLS AND DISK I/O S..........................................................................................................................16 Reads from the DBMS Buffer Pool...............................................................................................................16 Random I/O from Disk Drives ......................................................................................................................17 Reads from the Disk Server Cache ...............................................................................................................18 Sequential Reads from Disk Drives ..............................................................................................................19 Skip-sequential Reads from Disk Drives.......................................................................................................20 Synchronous and Asynchronous I/Os ...........................................................................................................22 HARDWARE SPECIFICS ......................................................................................................................................23 DBMS S PECIFICS ..............................................................................................................................................25 Pages ............................................................................................................................................................25 Table Clustering ...........................................................................................................................................25 Index Rows....................................................................................................................................................26 Table rows ....................................................................................................................................................26 Index-Only Tables.........................................................................................................................................27 Page Adjacency ............................................................................................................................................27 Alternatives to B-tree indexes.......................................................................................................................29 The Many Meanings of Cluster.....................................................................................................................30 CHAPTER 3........................................................................................................................................................31 SQL PROCESSING ...........................................................................................................................................31 INTRODUCTION ..................................................................................................................................................31 PREDICATES ......................................................................................................................................................32 OPTIMIZERS AND ACCESS PATHS ......................................................................................................................32 Index Slices and Matching Columns.............................................................................................................33 Index Screening and Screening Columns .....................................................................................................34 Access Path Terminology .............................................................................................................................35 Monitoring the Optimizer .............................................................................................................................36 Helping the Optimizer (Statistics).................................................................................................................36 Helping the Optimizer (Number of FETCH Calls) .......................................................................................37 When the Access Path is Chosen ..................................................................................................................38 FILTER FACTORS ...............................................................................................................................................39 Filter Factors for Compound Predicates......................................................................................................40 The Impact of Filter Factors on Index Design..............................................................................................43 MATERIALIZING THE RESULT ROWS .................................................................................................................45 Cursor Review ..............................................................................................................................................46 Alternative 1: FETCH Call Materializes One Result Row ...........................................................................47 Alternative 2: Early Materialization.............................................................................................................47 What Every Database Designer Should Remember......................................................................................48 EXERCISE 1........................................................................................................................................................49 2 Relational Database Index Design and the Optimizer EXERCISE 2........................................................................................................................................................50 EXERCISE 3........................................................................................................................................................50 3 Relational Database Index Design CCChhhaaapppttteeerrr 111::: IIInnntttrrroooddduuuccctttiiiooonnn Inadequate Indexing For many years, inadequate indexing has been the most common cause of performance disappointments. The most widespread problem appears to be that indexes do not have sufficient columns to support all the predicates of a WHERE clause. Frequently, there are not enough indexes on a table; some SELECTs may have no useful index; sometimes an index has the right columns but in the wrong order. It is relatively easy to improve the indexing of a relational database, because no program changes are required. However, a change to a production system always carries some risk. Furthermore, while a new index is being created, update programs may experience long waits because they are not able to update a table being scanned for a CREATE INDEX . For these reasons, and of course to achieve acceptable performance from the first production day of a new application, indexing should be in fairly good shape before production starts. Indexing should then be finalized soon after cutover, without