DBAdminFund PPT 4.3
DBAdminFund PPT 4.3
Understand Indexes
LESSON 4.3
Lesson Overview
What is an index?
Four common data structures for indexes: bitmap, dense, sparse, and reverse.
Bitmap index
— A bitmap index stores the data in bit arrays.
— The most common form is a B-tree.
— B-trees can be a highly efficient data structure.
Dense index
— A dense index works with pairs of keys and pointers for each record.
— Every key has a pointer tied directly to a record.
LESSON 4.3
Sparse index
— A sparse index works with pairs of keys and pointers for each block (a
sequence of bytes or bits).
— Every key has a pointer tied to a block of data.
— Less costly in resources and less effective (more generalized) than a dense
index.
Reverse index
— A reverse index reverses the key value; for instance, 12345 becomes
54321.
— This method is useful when keys are set in a sequence where new key
values change by a uniform amount.
LESSON 4.3
B-tree
B-tree (continued)
Leaf layer
This B-tree cuts search time significantly.
The data is organized in a balance method.
Each side of the tree has half the keys.
If you are looking for 59, you would travel down the right branch until you hit
73 and then travel down the left branch to reach 59.
The lowest layer is the tree is referred to as the leaf layer of the tree.
At this layer, you can find the pointer to the location of the desired records or
rows.
LESSON 4.3
Non-clustered Indexes
Syntax:
CREATE INDEX index_name
ON table_name (column_name)
Example:
CREATE INDEX NamesIndex
ON employees (LastName, FirstName)
The above statement creates an index on the employees table by LastName and
any duplicate last names are then sorted by FirstName.
LESSON 4.3
Clustered Indexes
Syntax:
CREATE [ UNIQUE ] CLUSTERED INDEX index_name
ON table_name (column_name)
[ ] = Optional: A unique index is one in which no two rows have the same index key value.
Example:
CREATE CLUSTERED INDEX NamesIndex
ON employees (LastName, FirstName)
Lesson Review
1. What is an index?
2. Why do we use indexes?
3. List the four common index structures.
4. What is a B-tree?
5. What is the difference between a clustered and non-clustered
index?
6. What factors influence which index method is used?
7. List several indexes that you use and predict the structure
employed.