05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

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

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

584<br />

CHAPTER 13 ■ PARTITIONING<br />

Local Indexes<br />

<strong>Oracle</strong> makes a distinction between the following two types of local indexes:<br />

• Local prefixed indexes: These are indexes whereby the partition keys are on the leading<br />

edge of the index definition. For example, if a table is range partitioned on a column<br />

named LOAD_DATE, a local prefixed index on that table would have LOAD_DATE as the first<br />

column in its column list.<br />

• Local nonprefixed indexes: These indexes do not have the partition key on the leading<br />

edge of their column list. The index may or may not contain the partition key columns.<br />

Both types of indexes are able take advantage of partition elimination, both can support<br />

uniqueness (as long as the nonprefixed index includes the partition key), <strong>and</strong> so on. The fact is<br />

that a query that uses a local prefixed index will always allow for index partition elimination,<br />

whereas a query that uses a local nonprefixed index might not. This is why local nonprefixed<br />

indexes are said to be “slower” by some people—they do not enforce partition elimination (but<br />

they do support it).<br />

There is nothing inherently better about a local prefixed index as opposed to a local nonprefixed<br />

index when that index is used as the initial path to the table in a query. What I mean<br />

by that is that if the query can start with “scan an index” as the first step, there isn’t much difference<br />

between a prefixed <strong>and</strong> a nonprefixed index.<br />

Partition Elimination Behavior<br />

For the query that starts with an index access, whether or not it can eliminate partitions from<br />

consideration all really depends on the predicate in your query. A small example will help<br />

demonstrate this. The following code creates a table, PARTITIONED_TABLE, that is range partitioned<br />

on a numeric column A such that values less than two will be in partition PART_1 <strong>and</strong><br />

values less than three will be in partition PART_2:<br />

ops$tkyte@ORA10G> CREATE TABLE partitioned_table<br />

2 ( a int,<br />

3 b int,<br />

4 data char(20)<br />

5 )<br />

6 PARTITION BY RANGE (a)<br />

7 (<br />

8 PARTITION part_1 VALUES LESS THAN(2) tablespace p1,<br />

9 PARTITION part_2 VALUES LESS THAN(3) tablespace p2<br />

10 )<br />

11 /<br />

Table created.<br />

We then create both a local prefixed index, LOCAL_PREFIXED, <strong>and</strong> a local nonprefixed index,<br />

LOCAL_NONPREFIXED. Note that the nonprefixed index does not have A on the leading edge of its<br />

definition, which is what makes it a nonprefixed index:

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

Saved successfully!

Ooh no, something went wrong!