Extended row size
Extended row size support allows users to create a table where its row length can exceed the maximum record length for the page size of the table space.
Page size | Row size limit | Column count limit |
---|---|---|
4 K | 4 005 | 500 |
8 K | 8 101 | 1 012 |
16 K | 16 293 | 1 012 |
32 K | 32 677 | 1 012 |
CREATE TABLE T1 (C1 INTEGER, C2 VARCHAR(5000))
The row size for this
table is 5010 bytes, calculated as 5 bytes (C1 plus nullable column overhead) + 5005 bytes (C2 plus
varying length column overhead).With extended row size support, tables that contain large rows that exceed the maximum record
length for the page size of the table space can be created. With extended row size support, the
table T1
can be created in a 4 K page size table space.
- Migrate tables that have row sizes that exceed 32 K to Db2® version 10.5.
- Improve the performance of applications where most of data rows can fit on a smaller page, but the table definition requires a bigger page size.
- Create tables with more VARCHAR or VARGRAPHIC columns. The maximum number of columns does not change, but the ability to exceed the maximum record length for the page size allows for more columns.
Existing tables can be altered to take advantaged of extended row size support. For example, more columns can be added or the length of character and graphic string columns can be increased. Without extended row size support, these changes would exceed the row size for the page size of the table space.
Any row-organized tables that are created by a user support extended row size except for range clustered tables (RCT).
Tables with extended row sizes
- The extended_row_sz database configuration parameter must be set to ENABLE.
- The table definition must contain at least one varying length string column (VARCHAR or VARGRAPHIC).
- The row size of the table cannot exceed 1048319 bytes (SQLSTATE 54010).
- Queries requiring an explicit or implicit system temporary table with extended rows needs a system temporary table space that can fully contain the minimum width of the row. The minimum width of the row is calculated in the same way as the maximum width except that all VARCHAR and VARGRAPHIC columns are assumed to have a length of 1.
Tables with extended row size support can be identified by checking the EXTENDED_ROW_SIZE column of the SYSCAT.TABLES catalog view.
Existing tables with extended row size support are unaffected by setting the extended_row_sz database configuration parameter to DISABLE. If you need to turn this off for an existing table, either modify the table definition or move to a larger page size table space so that the maximum record length no longer exceeds the page size limit.
- Inserting data into a table with extended row size support
- When a data row is inserted or updated in a table with extended row size support and the
physical data row length exceeds the maximum record length for the table space, a subset of the
varying length string columns (VARCHAR or VARGRAPHIC) is stored as large object (LOB) data outside
of the data row. The table column in the base row is replaced by a descriptor that is 24 bytes in
size. For columns of VARCHAR(n) where n is less than or equal to 24, or VARGRAPHIC(n) where n is
less than or equal to 12, data remains in the base data row.
If some VARCHAR or VARGRAPHIC data is stored out of row in a LOB data object, the data type is unchanged. The VARCHAR or VARGRAPHIC column does not become a LOB column. Operations like IMPORT, EXPORT, and LOAD do not require any LOB modifiers to work with the VARCHAR or VARGRAPHIC data.
Examples
- Creating a table without specifying a table space
- The following CREATE TABLE statement is
issued:
The row size forCREATE TABLE T1 (C1 INT, C2 VARCHAR(4000));
T1
is 4010 bytes. If a table space with a page size of at least 8 K cannot be found, thenT1
is created in a 4 K page size table space. If needed, some varying length data might be stored out of row. If no 4 K page size table space exists that can be used, an error is returned (SQLSTATE 42727). - Adding a column
- Table
T1
was created with the following CREATE TABLE statement.
Table spaceCREATE TABLE T1 (C1 INT, C2 VARCHAR(3995)) in TS1;
TS1
has a 4 K page size and so tableT1
is created without the need to store any data out of row because its byte count is 4005. A new column is added to tableT1
with the following ALTER TABLE statement:
The byte count for the table now exceeds the maximum record length. The ALTER TABLE is successful because the extended_row_sz database configuration parameter is set to ENABLE.ALTER TABLE T1 ADD C3 CLOB(1M);
- Deactivating VALUE COMPRESSION
- Table
T1
was created with the following CREATE TABLE statement.
Table spaceCREATE TABLE T1 (C1 INT, C2 VARCHAR(1993), C3 VARCHAR(2000)) IN TS1 VALUE COMPRESSION;
TS1
has a 4 K page size and tableT1
has a byte count of 4005 and so no data is stored out of row. Compression on tableT1
is deactivated with the following ALTER TABLE statement:
This statement changes the byte count of tableALTER TABLE T1 DEACTIVATE VALUE COMPRESSION;
T1
to 4008. The ALTER TABLE is successful because the extended_row_sz database configuration parameter is set to ENABLE. If required some varying length data might be stored out of row.If VALUE COMPRESSION is reactivated, any subsequent inserts of VARCHAR data are stored in the base row. All rows that were inserted when VALUE COMPRESSION was deactivated remain out of row until they are updated or table
T1
is reorganized. - Creating an index
- Table
T1
was created with the following CREATE TABLE statement.
Table spaceCREATE TABLE T1 (C1 INT, C2 VARCHAR(1000), C3 VARCHAR(1000), C4 VARCHAR(1000), C5 VARCHAR(1000)) IN TS1;
TS1
has a 4 K page size and tableT1
is successfully created because the extended_row_sz database configuration parameter is set to ENABLE. No special handling is required to create indexes on tableT1
.CREATE INDEX I1 on T1 (C2); CREATE INDEX I2 on T1 (C3); CREATE INDEX I3 on T1 (C4); CREATE INDEX I4 on T1 (C5);