[Database]|[Database] Physical Storage Media and File Organisation
Physical Storage Media
Access time
$$ Access\ time = Seek\ time + Rotational\ latency + (Transfer\ time) $$
文章图片
Disk Block
Features
- A contiguous sequence of sectors from a single track
- Data is transferred between disk and main memory in blocks
- The operating system stipulates that a disk block can only contain one file, so the space occupied by the file can only be an integer multiple of the disk block
Compare
- Smaller blocks: more transfers from disk
- Larger blocks: more space wasted due to partially filled blocks
Typical block sizes today range from 4 to 16 kilobytes
Access Optimisation
The elevator algorithm:
文章图片
File Organisation Definition Optimise block access time by organising the blocks to correspond to how data will be accessed
- Fixed-length records
- Variable-length records
- Allocate only as many records to a block as would fit entirely in the block
- Undesirable to delete records (requires additional block accesses)
Reference: https://songlee24.github.io/2...
Delete When delete a record, the record's pointer is inserted in the free list. It will not be deleted immediately.
Insert We change the header pointer to point to the next available record in the free list.
If no space is available, we add the new record to the end of the file.
Variable-length Records 【[Database]|[Database] Physical Storage Media and File Organisation】Variable-length attributes are represented in the initial part of the record by a pair (offset, length)
slotted-page structure
- The actual records are allocated contiguously in the block, starting from the end of the block.
- The free space in the block is contiguous, between the final entry in the header array, and the first record
文章图片
The header stores the information of each records.
Insert If a record is inserted, space is allocated for it at the end of free space.
Delete Free the space that it occupies and the records in the block before the deleted record are moved.
Organisation
- Heap
- Sequential
- Hashing
- Multitable clustering file organisation
文章图片
Sequential File Organisation
It is applied in many databases, such as Rocksdb
Insert locate the position where the record is to be inserted
- If there is free space insert there
- If no free space, insert the record in an overflow block
- In either case, pointer chain must be updated
Multitable Clustering File Organisation
Example
文章图片
Features
- good for queries involving join
- bad for queries involving only one table
- results in variable size records
- can add pointer chains to link records of a particular relation
推荐阅读
- HTTP高级(Cookie,Session|HTTP高级(Cookie,Session ,LocalStorage )
- 澳洲国立大学|澳洲国立大学 COMP6240 Relational Databases 笔记
- 云原生 Serverless Database 使用体验
- django.db.backends.postgresql' isn't an available database backend.解决方法
- TLS(Thread Local Storage)问题demo
- 二分法(一)
- Amazon Simple Storage Service (Amazon S3)
- Database|【sql】sqlserver因设置最大内存(256)过小导致无法启动的修复
- 如何实现微信小程序wx.setStorage数据缓存实现缓存过期时间
- 一个C#实现的数据库访问帮助类DatabaseHelper