innodb table-official website learning

Official website translation: INNDODB best practices

  1. InnoDB not only allows concurrent read and write access to the same table, it also caches modified data to simplify disk I/O. The performance advantage is not limited to huge tables with long-running queries. When the same row is accessed again and again from a table, a feature called an adaptive hash index takes over, making these lookups faster, as if they came from the hash table.
  2. By default, innodb will create a primary key index based on the primary key. If the primary key index is not created, it will build the index based on the self-incremented row value;
  3. When using join for multi-table association queries, pay attention to the use of foreign keys on the join columns;
  4. When you don't want to submit frequently, that is, when you perform frequent operations such as insert, update, and delete for a few hours, you can use start transations and commit batch operations;
  5. The lock table statement lock tables will not be used. When multiple session windows operate the same table at the same time, performance will not be lost. You can use the select * for update operation when obtaining exclusive access to a row of data;
  6. Enable the innodb_file_per_table option, or use a regular table space to put the table data and indexes in a separate file instead of the system table space. It is closed by default;
  7. View the default storage engine
    show engines,
  8. Innodb is a multi-version execution engine that saves multiple version information for each row to ensure the accuracy and concurrency of transactions. The mvcc multi-version control protocol used at the bottom layer cooperates with cas to maintain the accuracy of the data;
  9. Introduction to innodb lock mechanism
    a. Shared locks and exclusive locks:
    MySQL implements two row-level locks, one is shared locks, and the other is exclusive locks;
    if transaction T1 holds a shared (S) lock on row r, Then the processing
    of requesting a lock on row r from a different transaction T2 is as follows: T2's request for S lock can be granted immediately. Therefore, both T1 and T2 hold S locks on r.
    T2's request for the X lock cannot be granted immediately.
    If transaction T1 holds an exclusive (X) lock on row r, it cannot immediately grant a request for any type of lock on r from a different transaction T2. Instead, transaction T2 must wait for transaction T1 to release its lock on row r.
    b. Intention locks:
    Intention locks are table-level locks that indicate which type of lock (shared or exclusive) a transaction requires later for a row in a table.
    Intention locks are used to indicate that a transaction will operate on a row later mark lock
    there are two types of intention locks: there are two intent lock
    intent shared lock: that a transaction intends to set up a shared lock on the table in a row;
    intent exclusive lock: that a transaction intended for a row design row of the table It locks;
    that is, before acquiring the shared lock, you should first obtain the intent shared lock for the table; before acquiring the exclusive lock, you should first acquire the intent exclusive lock for the table;
    c: record lock
    record lock is a lock on the index record, The purpose is to lock a row to prevent the addition, deletion and modification of other transactions;
    d: gap lock
    A gap lock is a lock on the gap between index records, or on the gap before the first index record or after the last index record. For example, SELECT c1 FROM t WHERE c1 BETWEEN 10 and 20 FOR UPDATE;to prevent other transactions is inserted in a column that t.c1 15, whether such value already exists regardless of whether the column, because the spacing between all existing values within the range is locked.

Guess you like

Origin blog.csdn.net/qq_43079376/article/details/108674901
Recommended