[Reserved] Why use an auto-increment primary key

Why use an auto-increment primary key

If we define the primary key (PRIMARY KEY), then InnoDB will choose as the primary key clustered index

If the primary key is not explicitly defined, it selects the first InnoDB a unique index that does not contain a NULL value as there are primary key index,

If there is no such unique index, the built InnoDB selects ROWID 6 bytes long, as implied clustered index (writing rows ROWID as the primary key of the record is incremented, the ROWID ORACLE ROWID is not available as a reference, is implied).

The leaf node is stored in the data record itself, the main index (a B + Tree) is. This requires the same within a leaf node the respective data (the size of a memory page or disk page) records stored primary key sequence, so whenever there is a new record is inserted into, MySQL according to its primary key which is inserted into the appropriate node and location, if the page load factor reached (InnoDB as the default 15/16), then open a new page (node)

If the table using increment primary key , then each time a new record is inserted, it will record a subsequent sequence added to the current position of the index node, when a filled, it will automatically open up a new page

If non-increment primary key (if the ID number or student number, etc.), because each insertion primary key value is approximated by a random, each time a new record is to be inserted into the middle of an existing index page a position in which the MySQL had to order a new record into the proper position and movement data, even the target page may have been written back to disk and cleared from the cache, then have to read back from the disk, which adds a lot of overhead, frequent moves, paging operation caused a lot of debris, was not compact index structure, the follow-up had to rebuild the table by oPTIMIZE tABLE and optimize fill the page.

Guess you like

Origin www.cnblogs.com/smallwangmusk/p/11355448.html