05.11.2015 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

544<br />

CHAPTER 12 ■ DATATYPES<br />

The main reasons you might consider using a different tablespace for the LOB data versus<br />

the table data relate mainly to administration <strong>and</strong> performance. From the administrative<br />

angle, a LOB datatype represents a sizable amount of information. If the table had millions<br />

of rows, <strong>and</strong> each row had a sizeable LOB associated with it, the LOB data would be huge. It<br />

would make sense to segregate the table from the LOB data just to facilitate backup <strong>and</strong> recovery<br />

<strong>and</strong> space management. You may well want a different uniform extent size for your LOB<br />

data than you have for your regular table data, for example.<br />

The other reason could be for I/O performance. By default, LOBs are not cached in the<br />

buffer cache (more on that later). Therefore, by default every LOB access, be it read or write, is<br />

a physical I/O—a direct read from disk or a direct write to disk.<br />

■Note LOBs may be inline, or stored in the table. In that case, the LOB data would be cached, but this<br />

applies only to LOBs that are 4,000 bytes or less in size. We’ll discuss this further in the “IN ROW Clause”<br />

section.<br />

Because each access is a physical I/O, it makes sense to segregate to their own disk those<br />

objects you know for a fact will be experiencing more physical I/O than most objects in real<br />

time (as the user accesses them) to their own disks.<br />

It should be noted that the lobindex <strong>and</strong> the lobsegment will always be in the same tablespace.<br />

You cannot have the lobindex <strong>and</strong> lobsegment in separate tablespaces. Much earlier<br />

releases of <strong>Oracle</strong> allowed you to separate them, but versions 8i Release 3 <strong>and</strong> later do not<br />

allow you to specify separate tablespaces for the lobindex <strong>and</strong> lobsegment. In fact, all storage<br />

characteristics of the lobindex are inherited from the lobsegment, as we’ll see shortly.<br />

IN ROW Clause<br />

The CREATE TABLE statement returned from DBMS_METADATA earlier included the following:<br />

LOB ("TXT") STORE AS (... ENABLE STORAGE IN ROW ...<br />

This controls whether the LOB data is always stored separately from the table, in the lobsegment,<br />

or if it can sometimes be stored right in the table itself without being placed into the<br />

lobsegment. If ENABLE STORAGE IN ROW is set, as opposed to DISABLE STORAGE IN ROW, small<br />

LOBs of up to 4,000 bytes will be stored in the table itself, much like a VARCHAR2 would be.<br />

Only when LOBs exceed 4,000 bytes will they be moved “out of line” into the lobsegment.<br />

Enabling storage in the row is the default <strong>and</strong>, in general, should be the way to go if you<br />

know the LOBs will generally fit in the table itself. For example, you might have an application<br />

with a DESCRIPTION field of some sort in it. The DESCRIPTION might store between 0 <strong>and</strong> 32KB of<br />

data (or maybe even more, but mostly 32KB or less). Many of the descriptions are known to be<br />

very short, consisting of a couple hundred characters. Rather than suffering the overhead of<br />

storing these out of line <strong>and</strong> accessing them via the index every time you retrieve them, you<br />

can store them inline, in the table itself. Further, if the LOB is using the default of NOCACHE (the<br />

lobsegment data is not cached in the buffer cache), then a LOB stored in the table will avoid<br />

the physical I/O required to retrieve the LOB.

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

Saved successfully!

Ooh no, something went wrong!