当前位置:网站首页>MySQL brochure notes 5 InnoDB record storage structure

MySQL brochure notes 5 InnoDB record storage structure

2022-06-23 08:03:00 morningcat2018

MySQL Booklet notes 5 InnoDB Record storage structure

  1. InnoDB yes MySQL The default storage engine

  2. The speed of reading and writing to disk is very slow , And memory read and write a few orders of magnitude

Dividing data into pages , With page As an interface between disk and memory Basic unit ,InnoDB The size of the middle page is generally 16 KB.
That is to say, in general , Read at least from disk at a time 16KB In memory , Put at least... In memory at a time 16KB Refresh content to disk .

  1. We usually use Record Unit to insert data into the table , The way these records are stored on disk is also called Line format perhaps Record format .

4 A common row format is CompactRedundantDynamic and Compressed Line format .

  1. Specify the row format

CREATE TABLE Table name ( Column information ) ROW_FORMAT= Line format name ;

ALTER TABLE Table name ROW_FORMAT= Line format name ;

CREATE TABLE record_format_demo (
    c1 VARCHAR(10),
    c2 VARCHAR(10) NOT NULL,
    c3 CHAR(10),
    c4 VARCHAR(10)
) CHARSET=ascii ROW_FORMAT=COMPACT;

INSERT INTO record_format_demo(c1, c2, c3, c4) VALUES('aaaa', 'bbb', 'cc', 'morningcat2018'), ('eeee', 'fff', NULL, NULL);

+------+-----+------+---------------------+
| c1   | c2  | c3   |          c4         |
+------+-----+------+---------------------+
| aaaa | bbb | cc   |   morningcat2018    |
| eeee | fff | NULL |         NULL        |
+------+-----+------+---------------------+
  1. Compact Line format
  • Additional information recorded
    • Variable length field length list
      • MySQL Support some variable length data types , such as VARCHAR(M)、VARBINARY(M)、 Various TEXT type , Various BLOB type ; Columns of these data types are called Variable length field
      • The storage space occupied by these variable length fields is divided into two parts :1 Real data content ,2 Number of bytes occupied
      • The number of bytes occupied by the variable length field data is in the order of columns Storage in reverse order
        • In the first record c1、c2、c4 Columns are variable length fields , The lengths are 4,2,14 ; therefore Variable length field length list The value of is 0E0204 ( Hexadecimal representation )
        • In the second record c4 by NULL Don't record ; therefore Variable length field length list The value of is 0304
    • NULL List of values
      • Use 1bit Storage ,1 The value representing the column is NULL;0 The value representing the column is not NULL
      • Storage in reverse order
      • Zero up for high position
      • Only possible NULL Columns of are stored here ; therefore record_format_demo Tabular NULL List of values by 0000 0 c4 c3 c1
        • In the second record ,c3 c4 by NULL, The value is 1 ; therefore NULL List of values by 0000 0110 ; Hexadecimal is expressed as 06
    • Record header information
      • fixed 5 Bytes form (40 bit)
        • reserved 1 1bit
        • reserved 2 1bit
        • delete_mask 1bit Mark whether the record is deleted
        • min_rec_mask 1bit B+ This flag is added to the minimum record in each non leaf node of the tree
        • n_owned 4bit Indicates the number of records owned by the current record
        • heap_no 13bit Represents the location information of the current record in the record heap
        • record_type 3bit Indicates the type of current record ,0 It means ordinary record ,1 Express B+ Tree non leaf node records ,2 Represents the minimum record ,3 Indicates the maximum record
        • next_record 16bit Indicates the relative position of the next record
  • Real data recorded
    • In addition to custom column data ,MySQL Some columns will be added by default for each record ( Also known as Hide columns
      • DB_ROW_ID Not necessary 6byte That's ok ID, Uniquely identify a record
      • DB_TRX_ID must 6byte Business ID
      • DB_ROLL_PTR must 7byte rollback pointer
    • InnoDB Table generation strategy for primary key
      • User defined primary key is preferred
      • No primary key defined , Then choose one Unique Key as primary key
      • even Unique If there's no definition of a key , be InnoDB A table named... Is added by default row_id As the primary key
    • The first 1 In records
      • c3 The value of the column , It is CHAR(10) Type of , The string it actually stores is :‘cc’, and ascii The byte representation in the character set is ’0x6363’, Although it means that this string only takes 2 Bytes , But the whole c3 Columns still occupy 10 Bytes of space ,
      • Other than real data 8 All bytes are filled with space characters , The space character is in ascii The representation of a character set is 0x20
  1. Redundant Line format

Redundant The line format is MySQL5.0 A line format used before

  1. line overflow

A page is usually 16KB, When there is too much data in the record , When the current page doesn't fit , The extra data will be stored in other pages , This phenomenon is called line overflow

原网站

版权声明
本文为[morningcat2018]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230737149495.html