我在使用
hexdump -C demo.ibd
学习mysql存储数据的过程中遇到了一些问题。这是我的演示表。
CREATE TABLE `demo` (
`id` int NOT NULL,
`age` int NOT NULL,
`name` varchar(20000) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=ascii
INSERT INTO demo(id, age, name)
VALUES
(1, 10, 'joker'),
(2, 11, 'tom'),
(3, 12, 'jerry'),
(4, 12, 'aaaa...20000 in total...a'),
(5, 16, NULL);
MySQL 8.0.32,行格式动态。
以下是我根据
hexdump
看到的,我拆分了二进制数据进行分析
05 # lengths of variable-length columns
00 # a bit vector for indicating NULL columns
00 00 10 00 21 # 5-byte record header
80 00 00 01 # id: 1 [1]
00 00 00 00 05 1c # transaction_id
82 00 00 01 0a 01 10 # roll_pointer
80 00 00 0a # age: 10
6a 6f 6b 65 72 # name: "joker"
03 # lengths of variable-length columns
00 # a bit vector for indicating NULL columns
00 00 18 00 1f # 5-byte record header
80 00 00 02 # id: 2
00 00 00 00 05 1e # transaction_id
82 00 00 01 17 01 10 # roll_pointer
80 00 00 0b # age: 11
74 6f 6d # name: "tom"
05 # lengths of variable-length columns
00 # a bit vector for indicating NULL columns
00 00 20 00 20 # 5-byte record header
80 00 00 03 # id: 3
00 00 00 00 05 23 # transaction_id
81 00 00 01 10 01 10 # roll_pointer
80 00 00 0c # age: 12
6a 65 72 72 79 # name: jerry
# lengths of variable-length columns [2]
01 # a bit vector for indicating NULL columns
00 00 28 ff 91 # 5-byte record header
80 00 00 04 # id: 4
00 00 00 00 05 25 # transaction_id
81 00 00 01 11 01 10 # roll_pointer
80 00 00 0c # age: 12
# name: NULL
14 c0 # lengths of variable-length columns [3]
00 # a bit vector for indicating NULL columns
00 00 30 ff 74 # 5-byte record header
80 00 00 05 # id: 5
00 00 00 00 05 2d # transaction_id
82 00 00 01 10 01 10 # roll_pointer
80 00 00 10 # age: 16
00 00 00 02 00 00 00 05 # This is a 20-byte pointer which point to overflow page
00 00 00 01 00 00 00 00 # name: "aaa..." which length is 24000 Bytes
00 00 5d c0 # 0x5dc0 = 24000
我有三个问题,在第 4 行,第 28 行和第 37 行。
[1] 为什么MySQL不使用二进制补码来存储有符号整数?
[2] 当行的变长字段都为NULL时,长度是否没有额外的字节?
[3] 当变长字段过长导致页面溢出时,多出的字节表示什么?
如果您能为我解释一下,我将不胜感激