InnoDB
It is a storage engine that stores the data in the table to disk. Even if we shut down and restart the server, the data still exists. InnoDB
The storage engine does not read the records from the disk one by one, but divides the data into several pages, using the page as the basic unit of interaction between the disk and the memory.
We usually are in the recording unit of the data inserted into the table, which is stored in the form recorded on the disk is also called row format or recording format . InnoDB
Storage engine now has four different types of line format, respectively COMPACT
, REDUNDANT
, DYNAMIC
, COMPRESSED
.
Mainly talk about the COMPACT
line format:
Variable length field length list | List of NULL values | Record header information | Column 1 value | Column 2 value | ··· | Column 3 value |
---|
A complete record can be the extra information of the record (variable length field length list, NULL
value list, record header list) and the real data of the record (column 1 value, column 2 value, ..., column 3 value).
1. Additional information recorded
(1) The variable-length field length list
MySQL
supports some variable-length data types, such as VERCHAR(M),VARBINARY(M),各种TEXT类型,各种BLOB
types. The number of bytes of data stored in a variable-length byte field is not fixed, so when we store real data Need to store the byte page occupied by these data by the way.
In COMPACT
the row format, the variable length fields of the number of bytes occupied by the real data are stored in the head position of the recording, so as to form a variable length field length of the list, the real data of each sequence of variable length fields occupy bytes pressing column Store in reverse order.
(2) NULL
Value list
Some columns of a record may be NULL
values, and the COMPACT
row format manages the columns with NULL values in a record in a unified manner.
- First, count
NULL
the columns that are allowed to store values in the table. - If the table is not allowed to store
NULL
the column values, theNULL
list of values does not exist, or each storageNULL
worth column corresponds to a binary bit, bit reverse order by pressing order of the columns, the binary representation of the meaning of the following:
bins When the value is 1, it represents the value of the columnNULL
; when the
binary bit value is 0, it represents that the value of the column is notNULL
; MySQL
The specifiedNULL
value must be represented by an integer number of bytes. If the number of binary bits used is not the entire number of bytes, the high bit of the byte should be filled with 0;
(3) Recording header information The
recording header information consists of fixed 5 bytes, which are used to describe some attributes.
2. The recorded
real data In addition to the data in the columns defined by ourselves, MySQL
some columns (also called hidden columns) will be added to each record by default, as follows:
Column name | Do you have to | take up space | description |
---|---|---|---|
row_id | no | 6 bytes | Row ID, which uniquely identifies a record |
trx_id | Yes | 6 bytes | Transaction ID |
roll_pointer | Yes | 7 bytes | Rollback pointer |
As can be seen from the table, the InnoDB
storage engine for each recording are added rx_id
and roll_pointer
two columns, but row_id
is optional (in the absence of a custom master key storage and allowed NULL
worth UNIQUE
case where the key will add the column).