15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using Indexes 417<br />

102 John Smith 555-1462<br />

148 Mary Adams 555-7001<br />

152 Nancy Wiggins 555-9604<br />

166 Travis Gullins 555-0147<br />

170 Sam Perkins 555-8136<br />

193 Gail Hall 555-8772<br />

Hash table<br />

A hash table converts data into a numeric<br />

value, which is then used to point to the<br />

actual data.<br />

Figure 2-7:<br />

Comparison<br />

of hash<br />

tables and<br />

indexes.<br />

Adams<br />

Gullins<br />

Hall<br />

Perkins<br />

Smith<br />

Wiggins<br />

Index<br />

Mary 555-7001<br />

Travis 555-0147<br />

Gail 555-8772<br />

Sam 555-8136<br />

John 555-1462<br />

Nancy 555-9604<br />

An index uses part of the data to organize<br />

the rest of the data<br />

Clustered and unclustered indexes<br />

Here are two types of indexes — clustered and unclustered.<br />

A clustered index sorts the actual data. If you have a list of names and<br />

addresses, a clustered index could sort the data by last name, which physically<br />

rearranges the data in order. Because a clustered index physically<br />

rearranges data, you can have only one clustered index per file. Sorting data<br />

by a single field, such as last name, is an example of a clustered index.<br />

Book IV<br />

Chapter 2<br />

An unclustered index doesn’t physically rearrange data but creates pointers<br />

to that data. Because unclustered indexes don’t rearrange the data, you can<br />

have as many unclustered indexes as you need. The drawback of unclustered<br />

indexes is that they’re slower than clustered indexes. A clustered<br />

index finds the data right away whereas an unclustered index needs an extra<br />

step to search the index and then follow the pointer to the actual data, as<br />

shown in Figure 2-8.<br />

Searching<br />

Algorithms

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!