SQLite:仅从其字节识别页面类型?
SQLite: identify page type just from its bytes?
从 https://www.sqlite.org/fileformat.html 看来 SQLite 数据库中有 9 种类型的页面:
- 锁定字节页面
- 一个空闲列表主干页面
- 一个自由列表叶页
- 一个tableb-tree内页
- 一个table b树叶页
- 索引b-tree内页
- 一个索引 b-tree 叶页
- 负载溢出页面
- 指针映射页面
仅给定单个页面的字节数,是否可以识别其类型?
其实我是倾向于不,这不可能。例如,因为溢出页面
The first four bytes of each overflow page are a big-endian integer which is the page number of the next page in the chain
这意味着某些溢出页面可能看起来像基于其第一个字节的 b 树页面:
The one-byte flag at offset 0 indicating the b-tree page type.
- A value of 2 (0x02) means the page is an interior index b-tree page.
- A value of 5 (0x05) means the page is an interior table b-tree page.
- A value of 10 (0x0a) means the page is a leaf index b-tree page.
- A value of 13 (0x0d) means the page is a leaf table b-tree page.
但是...我希望我忽略了一些事情。 (例如,是否可以查看除第一个以外的某些字节来确定类型?)
根据我目前对文件格式的了解,我认为这是不可能的。我的推理:
只有前 13 页不是摘要的溢出页才有可能。
如果数据超过叶子页面上嵌入的负载限制,则使用溢出页面。
最小的table只是一个叶页作为根页。
最小的叶页是一行。
第 1 页用于页眉和母版 table。
因此,最小的数据库有一个主数据库 table(第 1 页),只有 table(第 2 页)中有一行。从一行溢出最大负载部分的那一刻起,就会创建一个溢出页。那将是第 3 页。
从 https://www.sqlite.org/fileformat.html 看来 SQLite 数据库中有 9 种类型的页面:
- 锁定字节页面
- 一个空闲列表主干页面
- 一个自由列表叶页
- 一个tableb-tree内页
- 一个table b树叶页
- 索引b-tree内页
- 一个索引 b-tree 叶页
- 负载溢出页面
- 指针映射页面
仅给定单个页面的字节数,是否可以识别其类型?
其实我是倾向于不,这不可能。例如,因为溢出页面
The first four bytes of each overflow page are a big-endian integer which is the page number of the next page in the chain
这意味着某些溢出页面可能看起来像基于其第一个字节的 b 树页面:
The one-byte flag at offset 0 indicating the b-tree page type.
- A value of 2 (0x02) means the page is an interior index b-tree page.
- A value of 5 (0x05) means the page is an interior table b-tree page.
- A value of 10 (0x0a) means the page is a leaf index b-tree page.
- A value of 13 (0x0d) means the page is a leaf table b-tree page.
但是...我希望我忽略了一些事情。 (例如,是否可以查看除第一个以外的某些字节来确定类型?)
根据我目前对文件格式的了解,我认为这是不可能的。我的推理:
只有前 13 页不是摘要的溢出页才有可能。
如果数据超过叶子页面上嵌入的负载限制,则使用溢出页面。
最小的table只是一个叶页作为根页。
最小的叶页是一行。
第 1 页用于页眉和母版 table。
因此,最小的数据库有一个主数据库 table(第 1 页),只有 table(第 2 页)中有一行。从一行溢出最大负载部分的那一刻起,就会创建一个溢出页。那将是第 3 页。