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

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 10 ■ DATABASE TABLES 375 7 dept.deptno 8 from emp, dept 9 where emp.deptno = dept.deptno 10 ) 11 order by deptno 12 / DEPT_BLK EMP_BLK F DEPTNO ---------- ---------- - ---------- 12 12 10 12 12 10 12 12 10 11 11 20 11 11 20 11 11 20 11 12 * 20 11 11 20 10 10 30 10 10 30 10 10 30 10 10 30 10 10 30 10 11 * 30 14 rows selected. ■Note Your mileage may vary here, as the order in which the rows are fetched from the SCOTT.DEPT table can and will change the results, and the use of ASSM versus MSSM may as well. The concept should be clear, however: if you put the row for DEPTNO=n on a given block, and then the employee rows for DEPTNO=n, you should achieve the best clustering possible. Most of the EMP rows are on the same block as the DEPT rows. This example is somewhat contrived in that I woefully undersized the SIZE parameter on the cluster to make a point, but the approach suggested is correct for an initial load of a cluster. It will ensure that if for some of the cluster keys, you exceed the estimated SIZE, you will still end up with most of the data clustered on the same block. If you load a table at a time, you will not. This technique applies only to the initial load of a cluster—after that, you would use it as your transactions deem necessary. You will not adapt your application to work specifically with a cluster. Here is a bit of puzzle to amaze and astound your friends with. Many people mistakenly believe a rowid uniquely identifies a row in a database, and that given a rowid you can tell what table the row came from. In fact, you cannot. You can and will get duplicate rowids from a cluster. For example, after executing the preceding code you should find

376 CHAPTER 10 ■ DATABASE TABLES ops$tkyte@ORA10GR1> select rowid from emp 2 intersect 3 select rowid from dept; ROWID ------------------ AAAOniAAJAAAAAKAAA AAAOniAAJAAAAAKAAB AAAOniAAJAAAAALAAA AAAOniAAJAAAAAMAAA Every rowid assigned to the rows in DEPT has been assigned to the rows in EMP as well. That is because it takes a table and row ID to uniquely identify a row. The rowid pseudo-column is unique only within a table. I also find that many people believe the cluster object to be an esoteric object that no one really uses—everyone just uses normal tables. The fact is, you use clusters every time you use Oracle. Much of the data dictionary is stored in various clusters, for example: sys@ORA10GR1> break on cluster_name sys@ORA10GR1> select cluster_name, table_name 2 from user_tables 3 where cluster_name is not null 4 order by 1; CLUSTER_NAME TABLE_NAME ------------------------------ ------------------------------ C_COBJ# CCOL$ CDEF$ C_FILE#_BLOCK# UET$ SEG$ C_MLOG# MLOG$ SLOG$ C_OBJ# ICOL$ CLU$ COL$ TYPE_MISC$ VIEWTRCOL$ ATTRCOL$ SUBCOLTYPE$ COLTYPE$ LOB$ TAB$ IND$ ICOLDEP$ OPQTYPE$ REFCON$

376<br />

CHAPTER 10 ■ DATABASE TABLES<br />

ops$tkyte@ORA10GR1> select rowid from emp<br />

2 intersect<br />

3 select rowid from dept;<br />

ROWID<br />

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

AAAOniAAJAAAAAKAAA<br />

AAAOniAAJAAAAAKAAB<br />

AAAOniAAJAAAAALAAA<br />

AAAOniAAJAAAAAMAAA<br />

Every rowid assigned to the rows in DEPT has been assigned to the rows in EMP as well. That<br />

is because it takes a table <strong>and</strong> row ID to uniquely identify a row. The rowid pseudo-column is<br />

unique only within a table.<br />

I also find that many people believe the cluster object to be an esoteric object that no one<br />

really uses—everyone just uses normal tables. The fact is, you use clusters every time you use<br />

<strong>Oracle</strong>. Much of the data dictionary is stored in various clusters, for example:<br />

sys@ORA10GR1> break on cluster_name<br />

sys@ORA10GR1> select cluster_name, table_name<br />

2 from user_tables<br />

3 where cluster_name is not null<br />

4 order by 1;<br />

CLUSTER_NAME<br />

TABLE_NAME<br />

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

C_COBJ#<br />

CCOL$<br />

CDEF$<br />

C_FILE#_BLOCK#<br />

UET$<br />

SEG$<br />

C_MLOG#<br />

MLOG$<br />

SLOG$<br />

C_OBJ#<br />

ICOL$<br />

CLU$<br />

COL$<br />

TYPE_MISC$<br />

VIEWTRCOL$<br />

ATTRCOL$<br />

SUBCOLTYPE$<br />

COLTYPE$<br />

LOB$<br />

TAB$<br />

IND$<br />

ICOLDEP$<br />

OPQTYPE$<br />

REFCON$

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

Saved successfully!

Ooh no, something went wrong!