SQL Server LOB and Row Overflow
A SQL Server row must fit within one 8KB page, and the in-row data cannot exceed 8,060 bytes. Data larger than that goes off the row in two ways. When variable-length columns such as varchar(n) make the row overflow, the data goes to row overflow; large values of large-object types such as varchar(max) are stored in LOB pages. In both cases only a pointer stays in the row.
Key Specifications
| Item | Value |
|---|---|
| Maximum in-row data | 8,060 bytes |
| Allocation units | IN_ROW_DATA, ROW_OVERFLOW_DATA, LOB_DATA |
| Row-overflow candidates | Variable-length columns such as varchar(n), nvarchar(n), varbinary(n), sql_variant |
| Row-overflow pointer | 24 bytes |
| LOB data types | varchar(max), nvarchar(max), varbinary(max), xml. Older types text, ntext, image |
Default location of max values | In the row if 8,000 bytes or less; in LOB pages if larger (large value types out of row = 0) |
| LOB pointer | 16 bytes (larger if the root is kept in the row) |
| Maximum size of one value | 2GB |
How It Works
Figure. The three allocation units
flowchart LR
R["Row IN_ROW_DATA<br/>fixed-length columns and short variable-length columns"]
R -- "24-byte pointer" --> O["ROW_OVERFLOW_DATA page<br/>overflowed varchar(n) value"]
R -- "16-byte pointer" --> L["LOB_DATA page<br/>max value over 8,000 bytes"]
L --> L2["LOB page tree"]
Diagram description: Each table (more precisely, each partition of a heap or index) has IN_ROW_DATA, ROW_OVERFLOW_DATA, and LOB_DATA allocation units. When a row exceeds 8,060 bytes, SQL Server moves the largest variable-length column first to a ROW_OVERFLOW_DATA page and leaves a 24-byte pointer in the row. A large max data type value is stored in LOB_DATA pages, and when the value spans several pages, they are chained together as a LOB page tree.
The cost of row overflow. Every read of an overflowed column reads one more page. An update that shortens the value can bring it back into the row, so I/O becomes hard to predict on frequently updated tables. If overflow happens often, split the table or change the large column to a max data type.
large value types out of row. With this option on, max values always go in LOB pages regardless of size. On a table where large values are rarely read, rows become shorter and more rows fit on one page.
Restrictions. A max data type column cannot be an index key; it can only be added as an INCLUDE column. Page compression and row compression apply only to IN_ROW_DATA.
Configuration and Inspection
-- Page count per allocation unit
SELECT o.name AS table_name, au.type_desc, au.total_pages, au.used_pages
FROM sys.allocation_units au
JOIN sys.partitions p ON au.container_id = p.partition_id
JOIN sys.objects o ON o.object_id = p.object_id
WHERE o.name = 'orders';
-- Always keep large values off the row
EXEC sp_tableoption 'dbo.docs', 'large value types out of row', 1;
SELECT index_id, alloc_unit_type_desc, page_count, avg_record_size_in_bytes
FROM sys.dm_db_index_physical_stats(DB_ID(), OBJECT_ID('dbo.orders'), NULL, NULL, 'DETAILED');
Comparison with Other DBMSs
| SQL Server | PostgreSQL | InnoDB | Oracle | |
|---|---|---|---|---|
| Name | LOB, row overflow | TOAST | Off-page storage | LOB |
| Threshold for moving data | Row 8,060 bytes, max value 8,000 bytes | Row about 2KB | Row near half a page | LOB about 4,000 bytes |
| Compression | Off-row values are not compressed | Compressed first by default | In the COMPRESSED row format | SecureFiles option |
In the Articles
NOTE Limits and defaults can vary by version.