我存储了两列无符号整数(根据http://dev.mysql.com/doc/refman/5.7/en/integer-types.html每个应该是4个字节),我希望表的大小大致在行* 8字节左右。单个表文件(具有.ibd扩展名的文件,如果我认为这个错误,请更正我)从96 KB开始,用于我的所有小表。当我进入具有更多行数的表时,大小会急剧增加,每行的字节数大约为30,如此处所示。每个表的行数为2 ^ k,每个k都有一个表。第一列是主键。
+--------+------------+----------+-------------+-------------+
| Size k | Rows | KB | Bytes | B/R |
+--------+------------+----------+-------------+-------------+
| 1 | 2 | 96 | 98304 | 49152 |
| 2 | 4 | 96 | 98304 | 24576 |
| 3 | 8 | 96 | 98304 | 12288 |
| 4 | 16 | 96 | 98304 | 6144 |
| 5 | 32 | 96 | 98304 | 3072 |
| 6 | 64 | 96 | 98304 | 1536 |
| 7 | 128 | 96 | 98304 | 768 |
| 8 | 256 | 96 | 98304 | 384 |
| 9 | 512 | 96 | 98304 | 192 |
| 10 | 1024 | 128 | 131072 | 128 |
| 11 | 2048 | 160 | 163840 | 80 |
| 12 | 4096 | 208 | 212992 | 52 |
| 13 | 8192 | 336 | 344064 | 42 |
| 14 | 16384 | 560 | 573440 | 35 |
| 15 | 32768 | 9216 | 9437184 | 288 |
| 16 | 65536 | 10240 | 10485760 | 160 |
| 17 | 131072 | 12288 | 12582912 | 96 |
| 18 | 262144 | 15360 | 15728640 | 60 |
| 19 | 524288 | 23552 | 24117248 | 46 |
| 20 | 1048576 | 40960 | 41943040 | 40 |
| 21 | 2097152 | 69632 | 71303168 | 34 |
| 22 | 4194304 | 131072 | 134217728 | 32 |
| 23 | 8388608 | 253952 | 260046848 | 31 |
| 24 | 16777216 | 499712 | 511705088 | 30.5 |
| 25 | 33554432 | 995328 | 1019215872 | 30.375 |
| 26 | 67108864 | 1978368 | 2025848832 | 30.1875 |
| 27 | 134217728 | 3948544 | 4043309056 | 30.125 |
| 28 | 268435456 | 7892992 | 8082423808 | 30.109375 |
| 29 | 536870912 | 15773696 | 16152264704 | 30.0859375 |
| 30 | 1073741824 | 31543296 | 32300335104 | 30.08203125 |
| 31 | 2147483648 | 63074304 | 64588087296 | 30.07617188 |
+--------+------------+----------+-------------+-------------+
查看http://dev.mysql.com/doc/refman/5.5/en/innodb-physical-record.html和Why is my table size more than 4x larger than expected? (rows*bytes/row),我发现这些表以COMPACT格式存储,并且对于大多数表,根据数据库的平均长度大约为28字节(而不是30)。
HEADER = 5 + CEILING(N/8) + 1 = 7 bytes // N = 1 NULL field of the 2
TRANSACTION ID FIELD = 6 = 6 bytes
ROLL POINTER FIELD = 7 = 7 bytes
PRIMARY KEY (YES) = 0? = 0 bytes
ACTUAL DATA (2 UINTS) = 8 bytes
------------------------------------------
= 28 bytes
我做了很多研究,因为我开始提出这个问题并回答了我的大部分问题,但是我想要另一组眼睛以确保我正在看这个问题。另外,其他2个字节来自哪里?