Download presentation
Presentation is loading. Please wait.
Published byBaldwin Eaton Modified over 9 years ago
1
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management
2
Oracle9i Database Administrator: Implementation and Administration 2 Objectives Learn the types of indexes Oracle offers and when to use each type Understand how to create each type of index Determine which data dictionary views contain information on indexes Find out how to monitor index usage and when to drop an index Learn how to modify, rebuild, and coalesce an index
3
Oracle9i Database Administrator: Implementation and Administration 3 Introduction to Indexes An index: Is a database structure that speeds up data retrieval Is automatically updated when rows are inserted updated or deleted Create indexes on: Relational tables Object tables Nested tables Index-organized tables Partitioned tables
4
Oracle9i Database Administrator: Implementation and Administration 4 Introduction to Indexes An index: Enforces PRIMARY KEY and UNIQUE constraints Can have up to 32 (30 for bitmap) columns Stores an entry for rows except those with all nulls in indexed columns (except bitmap, which stores all rows)
5
Oracle9i Database Administrator: Implementation and Administration 5 Introduction to Indexes Example of table and index data:
6
Oracle9i Database Administrator: Implementation and Administration 6 Types and Uses of Indexes The types of indexes offered in Oracle9i are: B-tree index Bitmap index Local partitioned index Global partitioned index and global nonpartitioned index Reverse key index Function-based index B-tree cluster index Hash cluster index Domain index Oracle's default type Compact but limited For partitioned tables For Real Application Clusters New in Oracle9i For clusters -- not in scope For applications -- not in scope
7
Oracle9i Database Administrator: Implementation and Administration 7 Types and Uses of Indexes Syntax of CREATE INDEX command: CREATE UNIQUE|BITMAP INDEX. ON. ( | ASC|DESC, | ASC|DESC,..) TABLESPACE STORAGE ( ) LOGGING|NOLOGGING ONLINE COMPUTE STATISTICS NOCOMPRESS|COMPRESS NOSORT|REVERSE NOPARALLEL|PARALLEL PARTITION|GLOBAL PARTITION
8
Oracle9i Database Administrator: Implementation and Administration 8 Types and Uses of Indexes Components of CREATE INDEX command: UNIQUE / BITMAP ( | ASC|DESC,...) COMPUTE STATISTICS NOCOMPRESS / COMPRESS NOSORT / REVERSE NOPARALLEL / PARALLEL PARTITION / NOPARTITION
9
Oracle9i Database Administrator: Implementation and Administration 9 B-tree Index Similar to a binary tree algorithm:
10
Oracle9i Database Administrator: Implementation and Administration 10 B-tree Index B-tree structure example:
11
Oracle9i Database Administrator: Implementation and Administration 11 B-tree Index B-tree advantages over binary tree: Keeps the leaf nodes from getting too far down in the hierarchy Adds more values in each leaf node Adds more values in each branch node Allows each branch node to branch in more than two directions
12
Oracle9i Database Administrator: Implementation and Administration 12 B-tree Index Example: A unique, single column index: CREATE UNIQUE INDEX CLASSMATE.DEWEY_IX ON CLASSMATE.CH09LIBRARYBOOK (DEWEY_DECIMAL) INITRANS 2 PCTFREE 20 LOGGING COMPUTE STATISTICS;
13
Oracle9i Database Administrator: Implementation and Administration 13 Bitmap Index A bitmap index: Does not use b-tree algorithm Stores information in a bitmap More compact than b-tree index Useful only in certain circumstances: Columns with low cardinality Queries comply to a list of criteria of the way data is accessed Few if any updates Not unique and not using the DESC clause
14
Oracle9i Database Administrator: Implementation and Administration 14 Bitmap Index Example of CREATE BITMAP INDEX command: CREATE BITMAP INDEX PATIENT_BITMAP_X ON PATIENT (BLOOD_TYPE, GENDER);
15
Oracle9i Database Administrator: Implementation and Administration 15 Bitmap Index Example of bitmap structure:
16
Oracle9i Database Administrator: Implementation and Administration 16 Local Partitioned Index Created on a partitioned table Partitioned exactly like the table Advantage: Data changes inside a partition cause only that partition's index to be updated Faster performance if query uses one partition's data
17
Oracle9i Database Administrator: Implementation and Administration 17 Local Partitioned Index Examples: Local b-tree partitioned index: CREATE INDEX LOCAL_X ON CH09MORTGAGE_HISTORY(DATE_CREATED) LOCAL STORE IN (USERS, USER_AUTO); Local bitmap partitioned index: CREATE BITMAP INDEX MCLIENT_LOCAL_X ON CH09MORTGAGE_CLIENT(LOAN_DATE) LOCAL (PARTITION OLDER_X TABLESPACE USERS STORAGE (INITIAL 50K NEXT 10K), PARTITION NEWER_X TABLESPACE USER_AUTO STORAGE (INITIAL 40K NEXT 15K)); Oracle handles index partition names and storage settings
18
Oracle9i Database Administrator: Implementation and Administration 18 Local Partitioned Index Query the USER_IND_PARTITIONS to see partitioned index details:
19
Oracle9i Database Administrator: Implementation and Administration 19 Global Partitioned Index and Global Nonpartitioned Index Global partitioned index: On nonpartitioned table, or On partitioned table but index is partitioned differently than the table Global nonpartitioned index: Always on partitioned table Index is not partitioned
20
Oracle9i Database Administrator: Implementation and Administration 20 Global Partitioned Index Example: Range-partitioned index on hash-partitioned table: CREATE INDEX G_ACCT_X ON CH09MORTGAGE_HISTORY (ACCT_NO) GLOBAL PARTITION BY RANGE (ACCT_NO) (PARTITION LOWEST_ACCT VALUES LESS THAN (5000), PARTITION MIDDLE_ACCT VALUES LESS THAN (10000), PARTITION HIGHEST_ACCT VALUES LESS THAN (MAXVALUE));
21
Oracle9i Database Administrator: Implementation and Administration 21 Global Nonpartitioned Index Example: Nonpartitioned index on hash-partitioned table: CREATE UNIQUE INDEX G_LOAN_X ON CH09MORTGAGE_HISTORY (LOAN_NO) GLOBAL;
22
Oracle9i Database Administrator: Implementation and Administration 22 Reverse Key Index Useful when most queries access a group of index rows that are located physically close together Solves I/O bottleneck by distributing data more evenly Example: CREATE INDEX EVENT_REVERSE ON CURRENT_EVENTS(CREATE_DATE) REVERSE;
23
Oracle9i Database Administrator: Implementation and Administration 23 Function-Based Index New in Oracle9i Can only be used by the cost-based optimizer Index contains a function or expression in place of a column Stores the results of the expression in the index
24
Oracle9i Database Administrator: Implementation and Administration 24 Function-Based Index Examples: CREATE INDEX PUB_YEAR_IX ON CH09LIBRARYBOOK ( TO_CHAR(PUB_DATE,'YYYY') ); 9 CREATE INDEX TOTAL_PAIDX ON CH09MORTGAGE_CLIENT ( (MORTGAGE_AMOUNT*NUMBER_OF_YEARS*MORTGAGE_RATE) +MORTGAGE_AMOUNT ) TABLESPACE USERS STORAGE (INITIAL 20K NEXT 10K) LOGGING COMPUTE STATISTICS; Indexed function Indexed expression
25
Oracle9i Database Administrator: Implementation and Administration 25 Data Dictionary Information on Indexes Gather statistics periodically to keep data dictionary information current Helps optimizer performance Helps you find unused indexes Use: ANALYZE DBMS_STATS
26
Oracle9i Database Administrator: Implementation and Administration 26 Data Dictionary Information on Indexes Examples: DBMS_STATS: BEGIN DBMS_STATS.GATHER_SCHEMA_STATS (ownname=>'CLASSMATE',cascade=>TRUE); END; ANALYZE: ANALYZE INDEX TOTAL_PAIDX VALIDATE STRUCTURE;
27
Oracle9i Database Administrator: Implementation and Administration 27 Data Dictionary Information on Indexes Data dictionary views:
28
Oracle9i Database Administrator: Implementation and Administration 28 Managing Indexes Use ALTER INDEX to: Monitor Move Rename Restructure Coalesce Use DROP INDEX to remove an index Cannot change order of columns
29
Oracle9i Database Administrator: Implementation and Administration 29 Monitoring Indexes and Dropping Indexes Syntax for monitoring indexes: ALTER INDEX. MONITORING USAGE; To view monitoring results: SELECT * FROM V$OBJECT_USAGE; Syntax for dropping indexes: DROP INDEX. ;
30
Oracle9i Database Administrator: Implementation and Administration 30 Reorganizing and Modifying Indexes Use the ALTER INDEX command to: Reorganized an index Change storage settings Compute statistics Compress Coalesce
31
Oracle9i Database Administrator: Implementation and Administration 31 Reorganizing and Modifying Indexes Syntax of ALTER INDEX command: ALTER INDEX. REBUILD PARTITION|SUBPARTITION REVERSE|NOREVERSE TABLESPACE STORAGE (NEXT MAXEXTENTS ) PCTFREE COMPUTE STATISTICS COMPRESS|NOCOMPRESS LOGGING|NOLOGGING ONLINE; Clauses for indexes only Same meanings as in the ALTER TABLE statement
32
Oracle9i Database Administrator: Implementation and Administration 32 Reorganizing and Modifying Indexes The ALTER INDEX... REBUILD command: Automatically rebuilds the b-tree structure Automatically corrects an index that has been marked “UNUSABLE” due to change in table structure Can change a reverse key index to a normal index or vice versa
33
Oracle9i Database Administrator: Implementation and Administration 33 Reorganizing and Modifying Indexes Example of rebuilding an index: ALTER INDEX PUB_YEAR_IX REBUILD TABLESPACE USER_AUTO ONLINE;
34
Oracle9i Database Administrator: Implementation and Administration 34 Reorganizing and Modifying Indexes Syntax of additional clauses for ALTER INDEX: ALTER INDEX. COALESCE UPDATE BLOCK REFERENCES UNUSABLE ONLINE RENAME TO RENAME PARTITION TO DEALLOCATE UNUSED KEEP LOGGING|NOLOGGING NOPARALLEL|PARALLEL MONITORING USAGE|NOMONITORING USAGE; Same meanings as in the ALTER TABLE statement Clauses for indexes only
35
Oracle9i Database Administrator: Implementation and Administration 35 Reorganizing and Modifying Indexes Syntax components: COALESCE: Consolidate fragmented storage space in the leaf blocks Add DEALLOCATE UNUSED to deallocate unused space UPDATE BLOCK REFERENCES: Only for normal index-organized tables Updates the physical guesses of the indexed row’s location stored in the index
36
Oracle9i Database Administrator: Implementation and Administration 36 Reorganizing and Modifying Indexes UNUSABLE: Marks index unusable Optimizer ignores the index Example: ALTER INDEX DEWEY_IX COALESCE;
37
Oracle9i Database Administrator: Implementation and Administration 37 Chapter Summary An index is a structure that holds data and has its own storage in the database A normal index stores rows in order by the index key values There are nine types of indexes B-tree is Oracle’s default type of index
38
Oracle9i Database Administrator: Implementation and Administration 38 Chapter Summary B-tree indexes are efficient even for very large amounts of data Bitmap indexes take up far less storage space than b-tree indexes Local partitioned indexes mirror the partitioning of the partitioned table Global partitioned indexes can only be RANGE partitioned
39
Oracle9i Database Administrator: Implementation and Administration 39 Chapter Summary Function-based indexes substitute a function or expression for a column The ALTER INDEX command allows you to make changes to the index ALTER INDEX REBUILD can change storage settings and adjust b-tree leaves ALTER INDEX COALESCE can release unused space
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.