MySQL InnoDB: 获取记录外部存储大小的函数分析
MySQL InnoDB: 获取记录外部存储大小的函数分析
函数: btr_rec_get_externally_stored_len
功能: 该函数用于获取记录的外部存储部分的大小,以数据库页为单位。
代码:
/***********************************************************//**
* Gets the externally stored size of a record, in units of a database page.
* @return externally stored part, in units of a database page */
static
ulint
btr_rec_get_externally_stored_len(
/*==============================*/
const rec_t* rec, /*!< in: record */
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
ulint n_fields;
ulint total_extern_len = 0;
ulint i;
ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec));
if (!rec_offs_any_extern(offsets)) {
return(0);
}
n_fields = rec_offs_n_fields(offsets);
for (i = 0; i < n_fields; i++) {
if (rec_offs_nth_extern(offsets, i)) {
ulint extern_len = mach_read_from_4(
btr_rec_get_field_ref(rec, offsets, i)
+ BTR_EXTERN_LEN + 4);
total_extern_len += ut_calc_align(extern_len,
UNIV_PAGE_SIZE);
}
}
return(total_extern_len / UNIV_PAGE_SIZE);
}
代码分析:
- 检查外部存储:函数首先使用
rec_offs_any_extern函数检查记录是否包含任何外部存储。如果没有,则直接返回 0。 - 遍历字段:如果记录包含外部存储,函数将遍历记录中的所有字段。
- 读取外部存储长度:对于每个包含外部存储的字段,函数使用
mach_read_from_4函数读取外部存储部分的长度。 - 对齐长度:函数使用
ut_calc_align函数将读取的外部存储长度对齐到页面大小。 - 计算总长度:将对齐后的外部存储长度累加到
total_extern_len变量中。 - 返回结果:最后,函数将
total_extern_len除以页面大小,并返回结果。
总结:
btr_rec_get_externally_stored_len 函数的实现比较简单,主要涉及对记录中的字段进行遍历和读取字段中外部存储部分的长度。该函数是 MySQL InnoDB 中管理记录外部存储的重要部分,它确保了记录的外部存储部分能够以正确的方式被访问和管理。
原文地址: https://www.cveoy.top/t/topic/nWUL 著作权归作者所有。请勿转载和采集!