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.

CHAPTER 10 ■ DATABASE TABLES 375<br />

7 dept.deptno<br />

8 from emp, dept<br />

9 where emp.deptno = dept.deptno<br />

10 )<br />

11 order by deptno<br />

12 /<br />

DEPT_BLK EMP_BLK F DEPTNO<br />

---------- ---------- - ----------<br />

12 12 10<br />

12 12 10<br />

12 12 10<br />

11 11 20<br />

11 11 20<br />

11 11 20<br />

11 12 * 20<br />

11 11 20<br />

10 10 30<br />

10 10 30<br />

10 10 30<br />

10 10 30<br />

10 10 30<br />

10 11 * 30<br />

14 rows selected.<br />

■Note Your mileage may vary here, as the order in which the rows are fetched from the SCOTT.DEPT table<br />

can <strong>and</strong> will change the results, <strong>and</strong> the use of ASSM versus MSSM may as well. The concept should be<br />

clear, however: if you put the row for DEPTNO=n on a given block, <strong>and</strong> then the employee rows for<br />

DEPTNO=n, you should achieve the best clustering possible.<br />

Most of the EMP rows are on the same block as the DEPT rows. This example is somewhat<br />

contrived in that I woefully undersized the SIZE parameter on the cluster to make a point, but<br />

the approach suggested is correct for an initial load of a cluster. It will ensure that if for some<br />

of the cluster keys, you exceed the estimated SIZE, you will still end up with most of the data<br />

clustered on the same block. If you load a table at a time, you will not.<br />

This technique applies only to the initial load of a cluster—after that, you would use it as<br />

your transactions deem necessary. You will not adapt your application to work specifically<br />

with a cluster.<br />

Here is a bit of puzzle to amaze <strong>and</strong> astound your friends with. Many people mistakenly<br />

believe a rowid uniquely identifies a row in a database, <strong>and</strong> that given a rowid you can tell<br />

what table the row came from. In fact, you cannot. You can <strong>and</strong> will get duplicate rowids from<br />

a cluster. For example, after executing the preceding code you should find

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

Saved successfully!

Ooh no, something went wrong!