Managing Indexes
description
Transcript of Managing Indexes
![Page 1: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/1.jpg)
12Copyright © Oracle Corporation, 2001. All rights reserved.
Managing Indexes
![Page 2: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/2.jpg)
12-2 Copyright © Oracle Corporation, 2001. All rights reserved.
Objectives
After completing this lesson, you should be able to do the following:
• List the different types of indexes and their uses
• Create various types of indexes
• Reorganize indexes
• Maintain indexes
• Monitor the usage of an index
![Page 3: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/3.jpg)
12-3 Copyright © Oracle Corporation, 2001. All rights reserved.
Classification of Indexes
• Logical– Single column or concatenated– Unique or nonunique– Function-based– Domain
• Physical– Partitioned or nonpartitioned – B-tree
Normal or reverse key– Bitmap
![Page 4: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/4.jpg)
12-5 Copyright © Oracle Corporation, 2001. All rights reserved.
B-Tree Index
Index entry header
Key column length
Key column value
ROWID
Root
Branch
Leaf
Index entry
![Page 5: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/5.jpg)
12-7 Copyright © Oracle Corporation, 2001. All rights reserved.
Bitmap Indexes
<Blue, 10.0.3, 12.8.3, 1000100100010010100>
<Green, 10.0.3, 12.8.3, 0001010000100100000>
<Red, 10.0.3, 12.8.3, 0100000011000001001>
<Yellow, 10.0.3, 12.8.3, 0010001000001000010>
keystartROWID
endROWID bitmap
Table
Index
Block 10
Block 11
Block 12
File 3
![Page 6: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/6.jpg)
12-9 Copyright © Oracle Corporation, 2001. All rights reserved.
Comparing B-Tree and Bitmap Indexes
B-tree
Suitable for high-cardinality columns
Updates on keys relativelyinexpensive
Inefficient for queries using OR predicates
Useful for OLTP
Bitmap
Suitable for low-cardinality columns
Updates to key columns veryexpensive
Efficient for queries using OR predicates
Useful for data warehousing
![Page 7: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/7.jpg)
12-10 Copyright © Oracle Corporation, 2001. All rights reserved.
Creating Normal B-Tree Indexes
CREATE INDEX hr.employees_last_name_idx
ON hr.employees(last_name)
PCTFREE 30
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE indx;
![Page 8: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/8.jpg)
12-13 Copyright © Oracle Corporation, 2001. All rights reserved.
Creating Indexes: Guidelines
• Balance query and DML needs
• Place in separate tablespace
• Use uniform extent sizes: Multiples of five blocks or MINIMUM EXTENT size for tablespace
• Consider NOLOGGING for large indexes
• INITRANS should generally be higher on indexes than on the corresponding tables.
![Page 9: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/9.jpg)
12-15 Copyright © Oracle Corporation, 2001. All rights reserved.
Creating Bitmap Indexes
CREATE BITMAP INDEX orders_region_id_idx
ON orders(region_id)
PCTFREE 30
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE indx;
![Page 10: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/10.jpg)
12-18 Copyright © Oracle Corporation, 2001. All rights reserved.
Changing Storage Parameters for Indexes
ALTER INDEX employees_last_name_idx
STORAGE(NEXT 400K
MAXEXTENTS 100);
![Page 11: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/11.jpg)
12-20 Copyright © Oracle Corporation, 2001. All rights reserved.
Allocating and Deallocating Index Space
ALTER INDEX orders_region_id_idx
ALLOCATE EXTENT (SIZE 200K
DATAFILE ‘/DISK6/indx01.dbf’);
ALTER INDEX orders_id_idx
DEALLOCATE UNUSED;
![Page 12: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/12.jpg)
12-21 Copyright © Oracle Corporation, 2001. All rights reserved.
Rebuilding Indexes
Use the ALTER INDEX command to:
• Move an index to a different tablespace
• Improve space utilization by removing deleted entries
ALTER INDEX orders_region_id_idx REBUILD
TABLESPACE indx02;
![Page 13: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/13.jpg)
12-23 Copyright © Oracle Corporation, 2001. All rights reserved.
Rebuilding Indexes Online
• Indexes can be rebuilt with minimal table locking.
• Some restrictions still apply.
ALTER INDEX orders_id_idx REBUILD ONLINE;
![Page 14: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/14.jpg)
12-24 Copyright © Oracle Corporation, 2001. All rights reserved.
Coalescing Indexes
Before coalescing After coalescing
ALTER INDEX orders_id_idx COALESCE;
![Page 15: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/15.jpg)
12-25 Copyright © Oracle Corporation, 2001. All rights reserved.
Checking Indexes and Their Validity
ANALYZE INDEX orders_region_id_idx
VALIDATE STRUCTURE;
INDEX_STATS
![Page 16: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/16.jpg)
12-27 Copyright © Oracle Corporation, 2001. All rights reserved.
Dropping Indexes
• Drop and recreate an index before bulk loads.
• Drop indexes that are infrequently needed and build them when necessary.
• Drop and recreate invalid indexes.
DROP INDEX hr.deptartments_name_idx;
![Page 17: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/17.jpg)
12-29 Copyright © Oracle Corporation, 2001. All rights reserved.
Identifying Unused Indexes
• To start monitoring the usage of an index:
• To stop monitoring the usage of an index:
ALTER INDEX hr.dept_id_idx
MONITORING USAGE
ALTER INDEX hr.dept_id_idx
NOMONITORING USAGE
![Page 18: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/18.jpg)
12-30 Copyright © Oracle Corporation, 2001. All rights reserved.
Obtaining Index Information
Information about indexes can be obtained by querying the following views:
• DBA_INDEXES: Provides information on the indexes
• DBA_IND_COLUMNS: Provides information on the columns indexed
• V$OBJECT_USAGE: Provides information on the usage of an index
![Page 19: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/19.jpg)
12-31 Copyright © Oracle Corporation, 2001. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Create different types of indexes
• Reorganize indexes
• Drop indexes
• Get index information from the data dictionary
• Begin and end monitoring usage of indexes
![Page 20: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/20.jpg)
12-32 Copyright © Oracle Corporation, 2001. All rights reserved.
Practice 12 Overview
This practice covers the following topics:
• Creating an index on columns of a table
• Moving the index to another tablespace
• Dropping an index
• Obtain index information
![Page 21: Managing Indexes](https://reader035.fdocuments.us/reader035/viewer/2022081506/5681479e550346895db4d504/html5/thumbnails/21.jpg)
12-34 Copyright © Oracle Corporation, 2001. All rights reserved.