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 415<br />

Obviously, this export cannot be imported into the new structure—it will not fit. This<br />

check prevents that from occurring.<br />

If you remember, I mentioned that we can change the behavior of the object identifier<br />

assigned to an object instance. Instead of having the system generate a pseudo primary key<br />

for us, we can use the natural key of an object. At first, this might appear self-defeating—the<br />

SYS_NC_OID$ will still appear in the table definition in SYS.COL$ <strong>and</strong>, in fact, it will appear to<br />

consume massive amounts of storage as compared to the system-generated column. Once<br />

again, however, there is “magic” at work here. The SYS_NC_OID$ column for an object table that<br />

is based on a primary key <strong>and</strong> not system generated is a virtual column <strong>and</strong> consumes no real<br />

storage on disk.<br />

Here is an example that shows what happens in the data dictionary <strong>and</strong> demonstrates<br />

that there is no physical storage consumed for the SYS_NC_OID$. We’ll start with an analysis of<br />

the system-generated OID table:<br />

ops$tkyte@ORA10G> create table people of person_type<br />

2 /<br />

Table created.<br />

ops$tkyte@ORA10G> select name, type#, segcollength<br />

2 from sys.col$<br />

3 where obj# = ( select object_id<br />

4 from user_objects<br />

5 where object_name = 'PEOPLE' )<br />

6 <strong>and</strong> name like 'SYS\_NC\_%' escape '\'<br />

7 /<br />

NAME<br />

TYPE# SEGCOLLENGTH<br />

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

SYS_NC_OID$ 23 16<br />

SYS_NC_ROWINFO$ 121 1<br />

ops$tkyte@ORA10G> insert into people(name)<br />

2 select rownum from all_objects;<br />

48217 rows created.<br />

ops$tkyte@ORA10G> exec dbms_stats.gather_table_stats( user, 'PEOPLE' );<br />

PL/SQL procedure successfully completed.<br />

ops$tkyte@ORA10G> select table_name, avg_row_len from user_object_tables;<br />

TABLE_NAME<br />

AVG_ROW_LEN<br />

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

PEOPLE 23<br />

We see here that the average row length is 23 bytes: 16 bytes for the SYS_NC_OID$ <strong>and</strong><br />

7 bytes for the NAME. Now, let’s do the same thing, but use a primary key on the NAME column<br />

as the object identifier:

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

Saved successfully!

Ooh no, something went wrong!