A10 Indexes
-
Upload
thanh-thao -
Category
Documents
-
view
246 -
download
0
Transcript of A10 Indexes
-
7/27/2019 A10 Indexes
1/32
-
7/27/2019 A10 Indexes
2/32
2
Agenda
Index types
Create various indexes
Drop index
Get index information
-
7/27/2019 A10 Indexes
3/32
3
Index
An index is a tree structure that allowsdirect access to a row in a table
Indexes can be classified on their
logical design or on their physicalimplementation Logical: groups indexes from an application
perspective Physical: derived from the way the indexes
are stored
-
7/27/2019 A10 Indexes
4/32
-
7/27/2019 A10 Indexes
5/32
5
Single Column and ConcatenatedIndexes
Single column index: has only one column inthe index keyAn index on the employee IDcolumn of an
employees table
Concatenated index: also known ascomposite index. Created on multiple columnsin a tableAn index on the departmentandjobcolumns of
an employees table Maximum number of columns in a composite key
index is 32
-
7/27/2019 A10 Indexes
6/32
6
Unique and Non-unique Indexes
Unique index: guarantees that no tworows of a table have duplicate values inthe column that defines the index
An index key in a unique index can point toonly one row in the table
Non-unique index: a single key canhave multiple rows associated with it
-
7/27/2019 A10 Indexes
7/32
7
Function-based Index
Created when using functions orexpressions that involve one or morecolumns in the table being indexed
Function-based indexes can be treatedas either a B-tree or a bitmap index
-
7/27/2019 A10 Indexes
8/32
-
7/27/2019 A10 Indexes
9/32
9
Partitioned and Non-partitionedIndexes
Partitioned indexes are used for largetables to store index entriescorresponding to an index in several
segments
Partitioning allows an index to be
spread across many tablespaces Decrease contention for index lookup, and
increase manageability
-
7/27/2019 A10 Indexes
10/32
-
7/27/2019 A10 Indexes
11/32
11
Index Leaf Entries
Entry header: storesnumber of columns andlocking info
Key column length-valuepairs: size of the a columnin the key, followed by the
value for the columnROWID
-
7/27/2019 A10 Indexes
12/32
12
B-tree Index and Null
There is no index entry correspondingto a row that has all key columns thatare NULL
Therefore a WHERE clause specifyingNULL will result in a full table scan
-
7/27/2019 A10 Indexes
13/32
13
Bitmap Index
A bitmap index is also organized as a B-tree, but the leaf node stores a bitmapfor each key value instead of a list of
ROWIDsEach bit in the bitmap corresponds to a
possible ROWID
If the bit is set, it means that the row withthe corresponding ROWID contains the keyvalue
-
7/27/2019 A10 Indexes
14/32
14
Bitmap Index Structure
-
7/27/2019 A10 Indexes
15/32
15
Bitmap Index Advantages
Bitmap indexes are more advantageous thanB-tree indexes in certain situations:
When a table has millions of rows and the key
columns have low cardinalityWhen queries often use a combination of
multiple WHERE conditions involving OR
operatorWhen there is read-only or low update
activity on the key columns
-
7/27/2019 A10 Indexes
16/32
16
Using Bitmap Index
The B-tree is used to locate the leaf nodesthat contain bitmap segments for a givenvalue of the key Start ROWID and the bitmap segments are used
to locate the rows that contain the key value
When changes are made to the key column inthe table, bitmaps must be modified.
Resulted in locking the bitmap segmentA row covered by the bitmap cannot be updated
by other transactions until the 1st transaction ends
-
7/27/2019 A10 Indexes
17/32
17
B-tree vs Bitmap Indexes
-
7/27/2019 A10 Indexes
18/32
18
Create Normal B-tree Indexes
Create an index on the EMPLOYEEStable using the LAST_NAME column
-
7/27/2019 A10 Indexes
19/32
19
Create Index: Guidelines
Balance query and DML needs Indexes speed up query performance and
slow down DML operations. Always
minimize the number of indexes needed onvolatile tables
Place in separate tablespace
Consider NOLOGGING for large indexes The creation and certain types of data
loads are not logged in the redo log file
-
7/27/2019 A10 Indexes
20/32
20
Create Bitmap Indexes
Use the CREATE_BITMAP_AREA_SIZE to
specify the amount of memory allocated forbitmap creation
Default value 8MB
Larger value, faster index creation
-
7/27/2019 A10 Indexes
21/32
21
Change Storage Parameters forIndexes
-
7/27/2019 A10 Indexes
22/32
22
Allocate Index Space
Add extents to an index before a periodof high insert activity on a table
Adding extents prevents dynamic
extensions of indexes and the resultingdegradation in performance
-
7/27/2019 A10 Indexes
23/32
23
De-allocate Index Space
Use the DEALLOCATE clause of ALTERINDEX command to release unusedspace above the high-water mark in an
index
-
7/27/2019 A10 Indexes
24/32
24
Rebuild Indexes
Use theALTER INDEX command toMove an index to a different tablespace
Improve space utilization by removing
deleted entries Change a reverse key index to a normal B-
tree index and vice versa
-
7/27/2019 A10 Indexes
25/32
25
Online Rebuild of Indexes
Building or rebuilding an index can betime-consuming, especially if the tableis very large
Rebuild indexes can be done withminimal table locking
-
7/27/2019 A10 Indexes
26/32
26
Coalescing Indexes
When you encounterindex fragmentation, youcan rebuild or coalesce
the indexCoalesce on an index is
a block rebuild that is
done online
-
7/27/2019 A10 Indexes
27/32
27
Check Index Validity
Analyze the index to perform thefollowing
Check all the index blocks for block
corruption. Populate the INDEX_STATS view with
information about the index
-
7/27/2019 A10 Indexes
28/32
28
Example: Query INDEX_STATS
Reorganize the index if it has a high
proportion of deleted rowsFor example: when the ration of
DEL_LF_ROWS to LF_ROWS exceeds 30%
-
7/27/2019 A10 Indexes
29/32
29
Drop Indexes
An index that is no longer needed byapplications can be dropped
An index may be dropped prior to
performing bulk loads. Improve performance of the load
Re-create the index after the load
-
7/27/2019 A10 Indexes
30/32
30
Identify Unused Index
To start monitoring the usage of anindex
To stop monitoring the usage of an
index
-
7/27/2019 A10 Indexes
31/32
31
Obtain Index Information
DBA_INDEXES: provide information onthe indexes
DBA_IND_COLUMNS: provide
information on the columns indexesDBA_IND_EXPRESSIONS: provide
information on function based indexes
V$OBJECT_USAGE: provide informationon the usage of an index
-
7/27/2019 A10 Indexes
32/32
32
Summary
Create different types of indexesReorganize index
Drop index
Get index information from the datadictionary