05.11.2015 Views

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

Create successful ePaper yourself

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

590<br />

CHAPTER 13 ■ PARTITIONING<br />

ops$tkyte@ORA10G> alter table partitioned<br />

2 add constraint<br />

3 partitioned_pk<br />

4 primary key(id)<br />

5 /<br />

alter table partitioned<br />

*<br />

ERROR at line 1:<br />

ORA-01408: such column list already indexed<br />

Here, <strong>Oracle</strong> attempts to create a global index on ID, but finds that it cannot since an<br />

index already exists. The preceding statements would work if the index we created was not<br />

partitioned, as <strong>Oracle</strong> would have used that index to enforce the constraint.<br />

The reasons why uniqueness cannot be enforced, unless the partition key is part of the<br />

constraint, are twofold. First, if <strong>Oracle</strong> allowed this, it would void most of the advantages of<br />

partitions. Availability <strong>and</strong> scalability would be lost, as each <strong>and</strong> every partition would always<br />

have to be available <strong>and</strong> scanned to do any inserts <strong>and</strong> updates. The more partitions you had,<br />

the less available the data would be. The more partitions you had, the more index partitions<br />

you would have to scan, <strong>and</strong> the less scalable partitions would become. Instead of providing<br />

availability <strong>and</strong> scalability, doing this would actually decrease both.<br />

Additionally, <strong>Oracle</strong> would have to effectively serialize inserts <strong>and</strong> updates to this table at<br />

the transaction level. This is because if we add ID=1 to PART_1, <strong>Oracle</strong> would have to somehow<br />

prevent anyone else from adding ID=1 to PART_2. The only way to do this would be to prevent<br />

others from modifying index partition PART_2, since there isn’t anything to really “lock” in that<br />

partition.<br />

In an OLTP system, unique constraints must be system enforced (i.e., enforced by <strong>Oracle</strong>)<br />

to ensure the integrity of data. This implies that the logical model of your application will have<br />

an impact on the physical design. Uniqueness constraints will either drive the underlying<br />

table partitioning scheme, driving the choice of the partition keys, or point you toward the<br />

use of global indexes instead. We’ll take a look at global indexes in more depth next.<br />

Global Indexes<br />

Global indexes are partitioned using a scheme that is different from that used in the underlying<br />

table. The table might be partitioned by a TIMESTAMP column into ten partitions, <strong>and</strong> a<br />

global index on that table could be partitioned into five partitions by the REGION column.<br />

Unlike local indexes, there is only one class of global index, <strong>and</strong> that is a prefixed global index.<br />

There is no support for a global index whose index key does not begin with the partitioning<br />

key for that index. That implies that whatever attribute(s) you use to partition the index will be<br />

on the leading edge of the index key itself.<br />

Continuing on from our previous example, here is a quick example of the use of a global<br />

index. It shows that a global partitioned index can be used to enforce uniqueness for a primary<br />

key, so you can have partitioned indexes that enforce uniqueness, but do not include the<br />

partition key of TABLE. The following example creates a table partitioned by TIMESTAMP that has<br />

an index partitioned by ID:

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

Saved successfully!

Ooh no, something went wrong!