01.09.2016 Views

Beginning Oracle Database 11g Administration From Novice to Professional

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 7 PHYSICAL DATABASE DESIGN 133<br />

Unique vs. Non- Unique Indexes<br />

Sometimes, the collection of indexed values should not include duplicates. For example,<br />

no two employees should have the same employee ID number. You can use the <br />

clause of the command <strong>to</strong> enforce the uniqueness requirement, as in the<br />

following example:<br />

<br />

Concatenated Indexes<br />

Consider the following query, which retrieves all red cars registered in the state of<br />

California: . The query<br />

would probably benefit from an index of states or an index of colors, but an even more<br />

selective index would be an index of state and color combinations. The following command<br />

creates an index of state and color combinations and names it :<br />

<br />

<strong>Oracle</strong> is capable of using the information in a concatenated index even if all relevant<br />

data items are not restricted in the SQL query. Instead of separate indexes, one of<br />

states and one of colors, let us suppose that a concatenated index has been created as in<br />

the previous paragraph. Also, suppose that the query specifies only the state or the color<br />

but not both. <strong>Oracle</strong> is capable of using the concatenated index even in such a case. For<br />

example, consider the query . In this case, it<br />

makes perfect sense <strong>to</strong> use the concatenated index described in the previous paragraph.<br />

Now consider the query . Because color<br />

is not the leading item in the concatenated index, it might appear at first sight that the<br />

concatenated index is not useful. However, <strong>Oracle</strong> can check the index 50 times, once for<br />

each state in the union, and thus identify rows satisfying both restrictions. It makes sense<br />

<strong>to</strong> do so because indexes are relatively compact objects, compared <strong>to</strong> tables. Also, database<br />

indexes are structured for easy lookup, just as the index of keywords at the back of<br />

this book is sorted in alphabetical order.<br />

Function-Based Indexes<br />

Indexes of the type we have considered so far are not as useful if the restrictions listed in<br />

the query include anything more complex than simple equality and inequality checks.<br />

For example, an index of salaries would not help if we are trying <strong>to</strong> identify employees for<br />

whom the <strong>to</strong>tal of salary and bonus is greater than a certain amount. Therefore, <strong>Oracle</strong><br />

provides the ability <strong>to</strong> create indexes of the results of expressions. For example, the following<br />

command creates an index of the <strong>to</strong>tal of salary and bonus:

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

Saved successfully!

Ooh no, something went wrong!