"How does Mysql run" reading notes four

InnoDBIt 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. InnoDBThe 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 . InnoDBStorage engine now has four different types of line format, respectively COMPACT, REDUNDANT, DYNAMIC, COMPRESSED.
Mainly talk about the COMPACTline 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, NULLvalue 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
MySQLsupports some variable-length data types, such as VERCHAR(M),VARBINARY(M),各种TEXT类型,各种BLOBtypes. 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 COMPACTthe 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) NULLValue list
Some columns of a record may be NULLvalues, and the COMPACTrow format manages the columns with NULL values ​​in a record in a unified manner.

  • First, count NULLthe columns that are allowed to store values ​​in the table.
  • If the table is not allowed to store NULLthe column values, the NULLlist of values does not exist, or each storage NULLworth 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 column NULL; when the
    binary bit value is 0, it represents that the value of the column is not NULL;
  • MySQLThe specified NULLvalue 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, MySQLsome 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 InnoDBstorage engine for each recording are added rx_idand roll_pointertwo columns, but row_idis optional (in the absence of a custom master key storage and allowed NULLworth UNIQUEcase where the key will add the column).

Guess you like

Origin blog.csdn.net/weixin_43213064/article/details/111434601