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 353 That aside, what is important to know about heap tables? Well, the CREATE TABLE syntax spans some 72 pages in the Oracle SQL Reference manual, so there are lots of options that go along with them. There are so many options that getting a hold on all of them is pretty difficult. The “wire diagrams” (or “train track” diagrams) alone take 18 pages to cover. One trick I use to see most of the options available to me in the CREATE TABLE statement for a given table is to create the table as simply as possible, for example: ops$tkyte@ORA10GR1> create table t 2 ( x int primary key, 3 y date, 4 z clob 5 ) 6 / Table created. Then, using the standard supplied package DBMS_METADATA, I query the definition of it and see the verbose syntax: ops$tkyte@ORA10GR1> select dbms_metadata.get_ddl( 'TABLE', 'T' ) from dual; DBMS_METADATA.GET_DDL('TABLE','T') ------------------------------------------------------------------------------- CREATE TABLE "OPS$TKYTE"."T" ( "X" NUMBER(*,0), "Y" DATE, "Z" CLOB, PRIMARY KEY ("X") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOB ("Z") STORE AS ( TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) The nice thing about this trick is that it shows many of the options for my CREATE TABLE statement. I just have to pick data types and such, and Oracle will produce the verbose version for me. I can now customize this verbose version, perhaps changing the ENABLE STORAGE IN ROW to DISABLE STORAGE IN ROW, which would disable the storage of the LOB data in the row with the structured data, causing it to be stored in another segment. I use this trick all of the time to save the couple minutes of confusion I would otherwise have if I were trying to figure this all out from the huge wire diagrams. I can also use this technique to learn what options are available to me on the CREATE TABLE statement under different circumstances.

354 CHAPTER 10 ■ DATABASE TABLES Now that you know how to see most of the options available to you on a given CREATE TABLE statement, which are the important ones you need to be aware of for heap tables? In my opinion, there are two with ASSM and four with MSSM: • FREELISTS: MSSM only. Every table manages the blocks it has allocated in the heap on a freelist. A table may have more than one freelist. If you anticipate heavy insertion into a table by many concurrent users, configuring more than one freelist can have a major positive impact on performance (at the cost of possible additional storage). Refer to the previous discussion and example in the section “FREELISTS” for the sort of impact this setting can have on performance. • PCTFREE: Both ASSM and MSSM. A measure of how full a block can be is made during the INSERT process. As shown earlier, this is used to control whether a row may be added to a block or not based on how full the block currently is. This option is also used to control row migrations caused by subsequent updates and needs to be set based on how you use the table. • PCTUSED: MSSM only. A measure of how empty a block must become before it can be a candidate for insertion again. A block that has less than PCTUSED space used is a candidate for insertion of new rows. Again, like PCTFREE, you must consider how you will be using your table to set this option appropriately. • INITRANS: Both ASSM and MSSM. The number of transaction slots initially allocated to a block. If set too low (it defaults to and has a minimum of 2), this option can cause concurrency issues in a block that is accessed by many users. If a database block is nearly full and the transaction list cannot be dynamically expanded, sessions will queue up waiting for this block, as each concurrent transaction needs a transaction slot. If you believe you will have many concurrent updates to the same blocks, you should consider increasing this value ■Note LOB data that is stored out of line in the LOB segment does not make use of the PCTFREE/PCTUSED parameters set for the table. These LOB blocks are managed differently: they are always filled to capacity and returned to the freelist only when completely empty. These are the parameters you want to pay particularly close attention to. With the introduction of locally managed tablespaces, which are highly recommended, I find that the rest of the storage parameters (such as PCTINCREASE, NEXT, and so on) are simply not relevant anymore. Index Organized Tables Index organized tables (IOTs) are, quite simply, tables stored in an index structure. Whereas a table stored in a heap is unorganized (i.e., data goes wherever there is available space), data in an IOT is stored and sorted by primary key. IOTs behave just like “regular” tables do as far as your application is concerned; you use SQL to access them as normal. They are especially useful for information retrieval, spatial, and OLAP applications.

CHAPTER 10 ■ DATABASE TABLES 353<br />

That aside, what is important to know about heap tables? Well, the CREATE TABLE syntax<br />

spans some 72 pages in the <strong>Oracle</strong> SQL Reference manual, so there are lots of options that go<br />

along with them. There are so many options that getting a hold on all of them is pretty difficult.<br />

The “wire diagrams” (or “train track” diagrams) alone take 18 pages to cover. One trick I<br />

use to see most of the options available to me in the CREATE TABLE statement for a given table<br />

is to create the table as simply as possible, for example:<br />

ops$tkyte@ORA10GR1> create table t<br />

2 ( x int primary key,<br />

3 y date,<br />

4 z clob<br />

5 )<br />

6 /<br />

Table created.<br />

Then, using the st<strong>and</strong>ard supplied package DBMS_METADATA, I query the definition of it <strong>and</strong><br />

see the verbose syntax:<br />

ops$tkyte@ORA10GR1> select dbms_metadata.get_ddl( 'TABLE', 'T' ) from dual;<br />

DBMS_METADATA.GET_DDL('TABLE','T')<br />

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

CREATE TABLE "OPS$TKYTE"."T"<br />

( "X" NUMBER(*,0),<br />

"Y" DATE,<br />

"Z" CLOB,<br />

PRIMARY KEY ("X")<br />

USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255<br />

STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645<br />

PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)<br />

TABLESPACE "USERS" ENABLE<br />

) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING<br />

STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645<br />

PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)<br />

TABLESPACE "USERS"<br />

LOB ("Z") STORE AS (<br />

TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10<br />

NOCACHE<br />

STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645<br />

PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))<br />

The nice thing about this trick is that it shows many of the options for my CREATE TABLE<br />

statement. I just have to pick data types <strong>and</strong> such, <strong>and</strong> <strong>Oracle</strong> will produce the verbose version<br />

for me. I can now customize this verbose version, perhaps changing the ENABLE STORAGE IN ROW<br />

to DISABLE STORAGE IN ROW, which would disable the storage of the LOB data in the row with the<br />

structured data, causing it to be stored in another segment. I use this trick all of the time to<br />

save the couple minutes of confusion I would otherwise have if I were trying to figure this all<br />

out from the huge wire diagrams. I can also use this technique to learn what options are available<br />

to me on the CREATE TABLE statement under different circumstances.

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

Saved successfully!

Ooh no, something went wrong!