>> > Hi,
>> >
[quoted text clipped - 30 lines]
> (not that I've used them much; don't think I've ever used them in a
> production environment)
In the early days of the MVS version of DB2, before row-level locking became
available, some people liked LONG VARCHARs because they effectively made
each row occupy an entire page. When every row was the only row on its page,
page-locking effectively became row-locking. Obviously, there can be
application benefits to locking only one row instead of a whole page full of
rows.
But if you consider that rows containing LONG VARCHAR columns occupy an
entire page but are probably only using a small fraction of the available
space, it's obvious that you are paying a very high price in storage for the
locking-benefit you are getting.
For example, I remember a table that some people on one of my project teams
developed back in the late 1980s. It was an audit table of some kind that
was intended to hold comments about particular transactions. There was a
small multicolumn key, then a single LONG VARCHAR column for comments about
the transaction identified in the key. I'm not sure what page size they were
using but I think it was 32K. Most of the comments were 100 characters or
less. By using LONG VARCHAR for the column, they were guaranteeing
themselves that their comments could be as long 32,700 bytes but they were
also guaranteeing that 32,700 bytes would be unavailable for other rows on
that same page! Since most comments were quite brief, they were wasting an
incredible amount of space. Now, if I remember correctly, they were only
writing rows to that table for a handful of transactions so the space wasted
was relatively trivial but if they changed the design to write a row to the
table for every transaction in the system, whether it was likely to need a
comment or not, the space wasted would quickly become staggering as the
number of transactions grew.
On top of that, if they ever needed to add a column to the table, they would
have had to save the data, drop the table, re-create it with the new
column(s) in it, then reload all old data. You can't add columns to a table
if it already occupies the whole page since there is no place to put the
data for the new column.
>> Please note that VARCHAR columns cannot be more than 32,672 bytes
>> long and LONG VARCHARs cannot be more than 32,700 bytes long
[quoted text clipped - 13 lines]
> IIRC, LONG VARCHARs are more-or-less Large Objects as well (i.e. like
> LOBs their data isn't stored entirely within the table)?
Yes, that's right. According to the current manual for DB2 for
Windows/Unix/Linux, the 'LONG IN' clause:
Identifies the table space in which the values of any long columns (LONG
VARCHAR, LONG VARGRAPHIC, LOB data types, distinct types with any of these
as source types, or any columns defined with user-defined structured types
with values that cannot be stored inline) will be stored. This option is
allowed only when the primary table space specified in the IN clause is a
DMS table space. The table space must exist, must be a LARGE DMS table space
over which the authorization ID of the statement has USE privilege, and must
be in the same database partition group as tablespace-name1 (SQLSTATE
42838).
> The reason I
> didn't suggest a 32k VARCHAR was that VARCHARs are stored entirely
[quoted text clipped - 9 lines]
> pages can hold a maximum of 255 rows this would result in a *lot* of
> wasted space).
The important thing is that you want to make sure you've chosen optimum page
sizes otherwise you will waste a lot of space, as you've said. You also want
to choose those sizes BEFORE you start loading the database if possible; it
can be a lot of work to move data that was in tablespaces with poor page
sizes to tablespaces with better page sizes. As with most things, it best to
plan things out ahead of time as best you can than to go into things without
any forethought and then spent all your time doing damage control.
--
Rhino
> IIRC, LONG VARCHARs are more-or-less Large Objects as well (i.e. like
> LOBs their data isn't stored entirely within the table)?
That's correct. However, the use of LONG VARCHARs is discouraged and you
should stick with CLOBs in this case. For example, many of the new
features added to DB2 don't even consider/accept LONG VARCHARs.
Btw, if you want to have some mix of both, the VARCHAR and the CLOB world,
i.e. store short strings like VARCHARs inline with the other data and long
strings like CLOBs, then you could wrap a CLOB value in a structured type
and the inline length for the structured type (or rather the column where
the structured type is used) determines the threshold between the two
storage models.

Signature
Knut Stolze
DB2 Information Integration Development
IBM Germany