Segment Space and the High Water Mark

本文详细介绍了数据库中的高水位线(HWM)概念及其在全表扫描中的作用。HWM以下是已格式化的数据块,而HWM以上则是未使用的。文章对比了两种管理方式——MSSM和ASSM。MSSM在没有可用块时预先格式化HWM以上的块,而ASSM则在插入时才格式化。全表扫描时,ASSM只读取低HWM以下的已格式化块。低HWM随着数据插入不断前进,而HWM始终保持在其后。这种机制影响了物理存储和I/O效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The high water mark (HWM) is the point in a segment beyond which data blocks are unformatted and have never been used.

HWM对于全表扫描至关重要,HWM以下过多碎片空间会占用更多物理存储,增加物理IO,消耗更多内存缓存(内存读入的块也会有大量碎片)

  1. MSSM是在freelist中没有free block时,在freelist加入一些HWM以上blocks, 并且在加入时对它们进行格式化。这导致全表扫描其实是扫描HWM以下blocks的

MSSM uses free lists to manage segment space. At table creation, no blocks in the segment are formatted. When a session first inserts rows into the table, the database searches the free list for usable blocks. If the database finds no usable blocks, then it preformats a group of blocks, places them on the free list, and begins inserting data into the blocks.

In MSSM, a full table scan reads all blocks below the HWM.

  1. ASSM是在bitmap没有free block时,加入HWM以上blocks, 但是是在insert时再对使用的blocks进行format,这导致它有low HWM与HWM两个概念:

Low HWM以下的blocks均为formatted blocks

HWM以下的blocks均为allocated blocks

ASSM uses the bitmap to find free blocks and then formats each block before filling it with data. Every data block in an ASSM segment is in one of the following states:

  1. Above the HWM:These blocks are unformatted and have never been used.
  2. Below the HWM:These blocks are in one of the following states:

Allocated, but currently unformatted and unused

Formatted and contain data

Formatted and empty because the data was deleted

Figure 12-24 depicts an ASSM segment as a horizontal series of blocks.

At table creation, the HWM is at the beginning of the segment on the left.

Suppose that a transaction inserts rows into the segment. The database must allocate a group of blocks to hold the rows. The allocated blocks fall below the HWM. The database formats a bitmap block in this group to hold the metadata, but does not preformat the remaining blocks in the group.

In Figure 12-25, As inserts occur, the database can write to any block with available space. The low high water mark (low HWM) marks the point below which all blocks are known to be formatted because they either contain data or formerly contained data.

In Figure 12-26, the database chooses a block between the HWM and low HWM and writes to it. The database could have just as easily chosen any other block between the HWM and low HWM, or any block below the low HWM that had available space.

下面newly filled blocks两边的blocks均为unformatted

In Figure 12-26, the blocks to either side of the newly filled block are unformatted.

全表扫描会使用扫描全部low HWM以下blocks,low HWM到HWM之间的blocks选择性读

The low HWM is important in a full table scan. Because blocks below the HWM are formatted only when used, some blocks could be unformatted, as in Figure 12-26. For this reason, the database reads the bitmap block to obtain the location of the low HWM. The database reads all blocks up to the low HWM because they are known to be formatted, and then carefully reads only the formatted blocks between the low HWM and the HWM.

Low HWM永远保持在HWM相同或以下水位线

When the blocks between the HWM and low HWM are full, the HWM advances to the right and the low HWM advances to the location of the old HWM. As the database inserts data over time, the HWM continues to advance to the right, with the low HWM always trailing behind it. Unless you manually rebuild, truncate, or shrink the object, the HWM never retreats.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值