Unexpected SQLite Size

I tested how the following schemas are compared with each other in SQLite (space and queries / s).

My original schema uses the value 0or 1for each field bit_*:

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
);

My alternative scheme uses a bitmask instead with values ​​from 0to 7:

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

According to SQLite documentation :

INTEGER

A signed integer stored in 1, 2, 3, 4, 6, or 8 bytes, depending on the value.

I expect each row in the table to originaltake 2 bytes than the table alternative. However, after pasting the exact data into two different database files, I found that the version alternativeis actually 5.5% larger than the version original.

- , ?

+4
1
+2

Source: https://habr.com/ru/post/1530066/


All Articles