Well you know MySQL

1. mysql index

1.1 index type

  1. Primary key index: the index column values required will not be repeated and not the null value
  2. The only index: the index column value requires unique and can be null
  3. Full-text indexing: with large text objects listed as an index
  4. Composite index: a plurality of combination index column, values in the column does not allow nulls
  5. Ordinary Index: ordinary table column as an index, there is no limit

The difference between 1.2 and the primary key index unique index

  1. Primary key index and unique index is slightly different requirements on the values ​​in the column, primary key index is more stringent.
  2. Each table can have only one primary key index, the index can have a plurality of unique.
  3. Primary key as a foreign key, not a unique index.
  4. After the primary key is created, including some unique index, a unique index is not necessarily the primary key.
  5. A primary key is a constraint, the index is a unique index, both of essentially different

1.3 composite index

The most left-prefix following the combination of the index, the most commonly used as a search or sort on the leftmost column, in descending order, is equivalent to the establishment of a composite index, a composite index because the column name is too long may lead to the index too large, thereby reducing the efficiency, the first few characters of the column can be taken as an index standards.

2. mysql storage engine

InnoDB MyISAM
Table definition and data indexing information stored separately, .frm description file format is used to define a table, .ibd used to store data files Into three files stored on the disk, and InnoDB .frm as .myd file format used to store data, the file format used to store .myi index file.
Requires more memory and storage space, it creates a buffer pool in memory for caching data and indexes May be compressed, small footprint (Table dynamic, static table, compressed table)
You can copy the data files for backup, when a large amount of data is difficult to top Data stored as files, cross-platform to facilitate transfer
Transaction-safe (ACID) supports transactions, foreign keys with the transaction, rollback, and crash repair capacity type table MyISAM stressed that the high performance, it does not support transactions, each query is atomic, execution speed than InnoDB
Supports row-level locking, improved concurrency (row locks only the primary key in the where are effective, where non-primary key will lock the entire table) A case where only the table lock support, will add the CRUD table lock, if the lock table satisfies concurrent insert, data can be inserted (tail insertion of new data)
Does not support full-text indexing of FULLTEXT (plug-ins can be used to achieve better performance) FULLTEXT support full-text index
Supports primary keys, if no non-null primary key or a unique index, will automatically generate a 6-byte primary key (not visible) No primary key and indexes exist, the index is
B + tree leaf node is stored in the data line data B + tree leaf node is stored in the address data of the data
Clustered index Non-clustered index

3. clustered index and non-clustered index

3.1 clustered index:

  1. The physical order of the rows database table and logical data in the same order, clustered indexes faster query speed.
  2. In order to maintain this order, every time a data is inserted in the database table when the shift operation will be a lot.
  3. A table can have only one clustered index.

3.2 non-clustered index

  1. The physical order of the rows database table and the data does not match the logical sequence, with insertion deleting more convenience.
  2. A table can have multiple non-clustered index

4. B, and the difference between the B + tree Tree

B-tree and B + trees are used in the database index, it is more than balanced search trees.

4.1 B-tree (M-order B-tree)

  1. Any non-leaf node has at most M son, and M> 2
  2. Son of the root node K, 2 <= K <= M, the number of non-leaf nodes of the son is P, M / 2 (rounded up) <= P <= M
  3. Number of key non-leaf node is the son of minus one
  4. All leaf nodes at the same level
  5. Keywords distributed in whole tree, each keyword appears in only one node
  6. Search may end in a non-leaf node
  7. Search performance is equivalent to doing a binary search

4.2 B + tree (M-order B + tree)

B + tree is a B tree modification, query performance better

  1. Non-leaf node contains keywords that do not hold data, used only as an index, all the data stored in the leaf nodes
  2. All leaf nodes contain all the key information, the leaf nodes of a small to large sorted by the keyword list
  3. B + tree typically has two pointers, a pointer to the root node, pointing to a leaf node minimum
  4. The same number will appear in different nodes, the root node is the largest element of the B + tree largest element

4.3 B + tree with respect to the advantages of the B-tree

  1. B + tree leaf nodes of non-data is not stored, the disk can accommodate more page nodes
  2. B + tree to be found once for each leaf node, and a B-tree node has any possibility, so the B + tree is more stable
  3. B + tree, to find the direct range can traverse the list, and B-trees require tree traversal repeated

Search time 4.4 B + tree

O (Math.log (N, M))
N - total number of records
M - order

5. Transaction of four properties

ACID

  1. Atomic: refers to the transaction is an atomic operation in which the various operations either all succeed or all fail
  2. Consistency: refers to the database before and after the transaction must ensure consistency
  3. Isolation: refers to the concurrent circumstances, creates a transaction for every user, every transaction can not interfere with each other to mutual isolation between transactions
  4. Persistence: refers to the transaction is committed, permanent changes to the database, the data will not be lost due to external causes.
Published 56 original articles · won praise 3 · Views 1190

Guess you like

Origin blog.csdn.net/qq_40788718/article/details/103179037