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.

370<br />

CHAPTER 10 ■ DATABASE TABLES<br />

When considering an OVERFLOW segment, however, PCTFREE <strong>and</strong> PCTUSED have the same interpretation<br />

as they do for a heap table; set them for an overflow segment using the same logic as<br />

you would for a heap table.<br />

Index Clustered Tables<br />

I generally find people’s underst<strong>and</strong>ing of what a cluster is in <strong>Oracle</strong> to be inaccurate. Many<br />

people tend to confuse a cluster with a SQL Server or Sybase “clustered index.” They are not<br />

the same. A cluster is a way to store a group of tables that share some common column(s)<br />

in the same database blocks <strong>and</strong> to store related data together on the same block. A clustered<br />

index in SQL Server forces the rows to be stored in sorted order according to the index key,<br />

similar to an IOT as just described. With a cluster, a single block of data may contain data from<br />

many tables. Conceptually, you are storing the data “prejoined.” It can also be used with single<br />

tables, where you are storing data together grouped by some column. For example, all of the<br />

employees in department 10 will be stored on the same block (or as few blocks as possible,<br />

if they all don’t fit). It is not storing the data sorted—that is the role of the IOT. It is storing<br />

the data clustered by some key, but in a heap. So, department 100 might be right next to<br />

department 1, <strong>and</strong> very far away (physically on disk) from departments 101 <strong>and</strong> 99.<br />

Graphically, you might think of it as shown in Figure 10-8. On the left side of the image,<br />

we are using conventional tables. EMP will be stored in its segment. DEPT will be stored on its<br />

own. They may be in different files <strong>and</strong> different tablespaces, <strong>and</strong> they are definitely in separate<br />

extents. On the right side of the image, we see what would happen if we clustered these<br />

two tables together. The square boxes represent database blocks. We now have the value 10<br />

factored out <strong>and</strong> stored once. Then, all of the data from all of the tables in the cluster for<br />

department 10 is stored in that block. If all of the data for department 10 does not fit on the<br />

block, then additional blocks will be chained to the original block to contain the overflow, in<br />

the same fashion as the overflow blocks for an IOT.<br />

Figure 10-8. Index clustered data<br />

So, let’s look at how we might go about creating a clustered object. Creating a cluster of<br />

tables in the object is straightforward. The definition of the storage of the object (PCTFREE,<br />

PCTUSED, INITIAL, <strong>and</strong> so on) is associated with the CLUSTER, not the tables. This makes sense<br />

aving

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

Saved successfully!

Ooh no, something went wrong!