gpt4 book ai didi

database - 意外的 SQLite 大小

转载 作者:太空狗 更新时间:2023-10-30 01:57:13 24 4
gpt4 key购买 nike

我正在测试以下模式在 SQLite 中如何相互比较(空间和查询)。

我的原始模式为每个 bit_* 字段使用 01 值:

CREATE TABLE "original"
(
"id" TEXT NOT NULL,
"bit_a" INTEGER(1) NOT NULL DEFAULT 0,
"bit_b" INTEGER(1) NOT NULL DEFAULT 0,
"bit_c" INTEGER(1) NOT NULL DEFAULT 0
);

我的替代模式使用一个位掩码,而不是值范围从 07:

CREATE TABLE "alternative"
(
"id" TEXT NOT NULL,
"bit_mask" INTEGER(1) NOT NULL DEFAULT 0
);

根据SQLite documentation :

INTEGER

Signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.

我希望 original 表中的每一行比 alternative 表多占用 2 个字节。然而,在两个不同的数据库文件中插入完全相同的数据后,我发现 alternative 版本实际上比 original 版本 5.5%

有人知道为什么会这样吗?

最佳答案

查看 SQLite 文件格式文档,第 2.1 节。 https://www.sqlite.org/fileformat.html

整数值 0 和 1 是特殊情况,它们占用的磁盘空间比其他值少。

关于database - 意外的 SQLite 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22179137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com