The basic theory of Mysql index transaction

Mysql index transaction

1. Index

  • Mysql is the innodb engine by default, and the index data is stored in a local file;

1.1 Concept

  • Index is a special file that contains reference pointers to all records in the data table. You can create an index on one or more columns in the table, and specify the type of index. Each type of index has its own data structure.

1.2 Application

  • The relationship between tables, data, and indexes in the database is similar to the relationship between books on the shelf, book content, and book catalogs.
  • The index plays a role similar to a book catalog, and can be used to quickly locate and retrieve data.
  • Indexes are of great help to improve the performance of the database.

1.3 Usage scenarios

  • To consider creating an index on a column or columns of a database table, the following points need to be considered:
  1. The amount of data is large, and conditional queries are often performed on these columns.

  2. The frequency of insert operations on the database table and modification operations on these columns is low.

  3. The index will take up additional disk space.

  • Note : When the above conditions are met, consider creating indexes on these fields in the table to improve query efficiency.
    Conversely, if you query columns unconditionally, or frequently insert or modify operations, or when disk space is insufficient, you do not consider creating indexes.

1.4 Use

  • When creating a primary key constraint (PRIMARY KEY), unique constraint (UNIQUE), and foreign key constraint (FOREIGN KEY), the index of the corresponding column will be automatically created.
  • Index characteristics: deleting, inserting, and modifying index fields will have a great impact (the larger the amount of data, the lower the efficiency);

1.4.1 View Index

show index from 表名;

1.4.2 Create Index

create index 索引名 on 表名(字段名);

1.4.3 delete index

drop index 索引名 on 表名;

2. Affairs

  • A transaction refers to a logical set of operations. The units that make up this set of operations either all succeed or all fail. There can be transactions in different environments. Corresponding to the database is the database transaction.
  • characteristic:
  1. Atomicity: Either all execution succeeds, or all execution fails;
  2. Persistence: Once a transaction is committed, the change to the data in the database is permanent, and the operation of committing the transaction will not be lost even if the database system encounters a failure;
  3. consistency;
  4. Isolation: multiple transactions are executed concurrently without affecting each other;
  • Rollback or commit: rollback/commit;
  1. Rollback: As long as an error occurs during the execution of all sql statements, rollback will occur;
start transaction;/*开启事务*/
.../*这里有多条sql语句*/
rollback/commit;

Guess you like

Origin blog.csdn.net/qq_45665172/article/details/109691831