10. Choosing Storage Structures and Secondary Indexes : Heap Storage Structure : Heap as Structure for Loading Data
 
Share this page                  
Heap as Structure for Loading Data
If the configuration parameter auto_table_structure is set to OFF, heap is used as the default storage structure when a table is first created, because it is assumed that a newly created table is likely to be loaded with data.
Loading is optimized by not doing “per row” logging. Therefore, you must load into an empty table. This can be a table that was just created and into which no data has ever been added or deleted. Or it can be an existing table that was truncated by clicking Delete All Data in the Modify Table Structure dialog or by using the MODIFY TO TRUNCATE statement.
The empty table must also have the following characteristics:
The table must not be journaled or have secondary indexes.
The table must not have system-maintained keys.
You must have an exclusive lock on the table.
Heap is also the best structure to use for adding data. Additions to a heap table progress quickly because inserted rows are added to the end of the heap. There is no overhead of calculating what page the row is on. The disadvantage is that the heap structure does not make use of deleted row space except at the end of the table.
Aside from compressed storage structures, the heap structure produces tables with the smallest number of pages. This is because every page in a heap table is filled as completely as possible. This is referred to as a 100% fill factor. A heap table is approximately half the size of the same table modified to hash because hash uses a 50% default fill factor instead of 100%.
After loading or adding the data, you can modify the table to another storage structure. (Do not modify an empty table to another storage structure before loading the data.)
To free deleted space, remodify the table to heap using the Modify Table Structure dialog or the modify statement.
Very small tables can usually be left as heap tables. If the table fits on one to five pages as a heap, there is no speed advantage to modifying it to a different structure.
Note:  The heap structure is sometimes used for large tables in conjunction with a secondary index. This can be useful in a situation where the table is so large it cannot be modified, but an accelerated access method is needed.