Storage Structure
Storage Structure
Database System Concepts - 7th Edition 13.2 ©Silberschatz, Korth and Sudarshan
Fixed-Length Records
§ Simple approach:
• Store record i starting from byte n * (i – 1), where n is the size of
each record.
• Record access is simple but records may cross blocks
§ Modification: do not allow records to cross block boundaries
Database System Concepts - 7th Edition 13.3 ©Silberschatz, Korth and Sudarshan
Fixed-Length Records
Database System Concepts - 7th Edition 13.4 ©Silberschatz, Korth and Sudarshan
Fixed-Length Records
Database System Concepts - 7th Edition 13.5 ©Silberschatz, Korth and Sudarshan
Fixed-Length Records
Database System Concepts - 7th Edition 13.6 ©Silberschatz, Korth and Sudarshan
Variable-Length Records
Database System Concepts - 7th Edition 13.7 ©Silberschatz, Korth and Sudarshan
Variable-Length Records: Slotted Page Structure
Block Header Records
Database System Concepts - 7th Edition 13.8 ©Silberschatz, Korth and Sudarshan
Storing Large Objects
Database System Concepts - 7th Edition 13.9 ©Silberschatz, Korth and Sudarshan
Organization of Records in Files
§ Heap – record can be placed anywhere in the file where there is space
§ Sequential – store records in sequential order, based on the value of the
search key of each record
§ In a multitable clustering file organization records of several different
relations can be stored in the same file
• Motivation: store related records on the same block to minimize I/O
§ B+-tree file organization
• Ordered storage even with inserts/deletes
• More on this in Chapter 14
§ Hashing – a hash function computed on search key; the result specifies in
which block of the file the record should be placed
• More on this in Chapter 14
Database System Concepts - 7th Edition 13.10 ©Silberschatz, Korth and Sudarshan
Heap File Organization
§ Records can be placed anywhere in the file where there is free space
§ Records usually do not move once allocated
§ Important to be able to efficiently find free space within file
§ Free-space map
• Array with 1 entry per block. Each entry is a few bits to a byte, and
records fraction of block that is free
• In example below, 3 bits per block, value divided by 8 indicates
fraction of block that is free
§ Free space map written to disk periodically, OK to have wrong (old) values
for some entries (will be detected and fixed)
Database System Concepts - 7th Edition 13.11 ©Silberschatz, Korth and Sudarshan
Sequential File Organization
Database System Concepts - 7th Edition 13.12 ©Silberschatz, Korth and Sudarshan
Sequential File Organization (Cont.)
Database System Concepts - 7th Edition 13.13 ©Silberschatz, Korth and Sudarshan
Multitable Clustering File Organization
Store several relations in one file using a multitable clustering
file organization
department
instructor
multitable clustering
of department and
instructor
Database System Concepts - 7th Edition 13.14 ©Silberschatz, Korth and Sudarshan
Multitable Clustering File Organization (cont.)
Database System Concepts - 7th Edition 13.15 ©Silberschatz, Korth and Sudarshan
Partitioning
Database System Concepts - 7th Edition 13.16 ©Silberschatz, Korth and Sudarshan
Data Dictionary Storage
Database System Concepts - 7th Edition 13.17 ©Silberschatz, Korth and Sudarshan
Relational Representation of System Metadata
Database System Concepts - 7th Edition 13.18 ©Silberschatz, Korth and Sudarshan
Storage Access
Database System Concepts - 7th Edition 13.19 ©Silberschatz, Korth and Sudarshan
Buffer Manager
§ Programs call on the buffer manager when they need a block from disk.
• If the block is already in the buffer, buffer manager returns the
address of the block in main memory
• If the block is not in the buffer, the buffer manager
§ Allocates space in the buffer for the block
• Replacing (throwing out) some other block, if required, to make
space for the new block.
• Replaced block written back to disk only if it was modified
since the most recent time that it was written to/fetched from
the disk.
§ Reads the block from the disk to the buffer, and returns the
address of the block in main memory to requester.
Database System Concepts - 7th Edition 13.20 ©Silberschatz, Korth and Sudarshan
Buffer Manager
Database System Concepts - 7th Edition 13.21 ©Silberschatz, Korth and Sudarshan
Buffer-Replacement Policies
§ Most operating systems replace the block least recently used (LRU
strategy)
• Idea behind LRU – use past pattern of block references as a
predictor of future references
• LRU can be bad for some queries
§ Queries have well-defined access patterns (such as sequential scans),
and a database system can use the information in a user’s query to
predict future references
§ Mixed strategy with hints on replacement strategy provided
by the query optimizer is preferable
§ Example of bad access pattern for LRU: when computing the join of 2
relations r and s by a nested loops
for each tuple tr of r do
for each tuple ts of s do
if the tuples tr and ts match …
Database System Concepts - 7th Edition 13.22 ©Silberschatz, Korth and Sudarshan
Buffer-Replacement Policies (Cont.)
Database System Concepts - 7th Edition 13.23 ©Silberschatz, Korth and Sudarshan
Optimization of Disk Block Access (Cont.)
§ Buffer managers support forced output of blocks for the purpose of recovery
(more in Chapter 19)
§ Nonvolatile write buffers speed up disk writes by writing blocks to a non-
volatile RAM or flash buffer immediately
• Writes can be reordered to minimize disk arm movement
§ Log disk – a disk devoted to writing a sequential log of block updates
• Used exactly like nonvolatile RAM
§ Write to log disk is very fast since no seeks are required
§ Journaling file systems write data in-order to NV-RAM or log disk
• Reordering without journaling: risk of corruption of file system data
Database System Concepts - 7th Edition 13.24 ©Silberschatz, Korth and Sudarshan
Column-Oriented Storage
Database System Concepts - 7th Edition 13.25 ©Silberschatz, Korth and Sudarshan
Columnar Representation
§ Benefits:
• Reduced IO if only some attributes are accessed
• Improved CPU cache performance
• Improved compression
• Vector processing on modern CPU architectures
§ Drawbacks
• Cost of tuple reconstruction from columnar representation
• Cost of tuple deletion and update
• Cost of decompression
§ Columnar representation found to be more efficient for decision support than
row-oriented representation
§ Traditional row-oriented representation preferable for transaction processing
§ Some databases support both representations
• Called hybrid row/column stores
Database System Concepts - 7th Edition 13.26 ©Silberschatz, Korth and Sudarshan
Columnar File Representation
Database System Concepts - 7th Edition 13.27 ©Silberschatz, Korth and Sudarshan
Storage Organization in Main-Memory Databases
Database System Concepts - 7th Edition 13.28 ©Silberschatz, Korth and Sudarshan