mysql database

Index disk is placed above a data structure, disk space for a single value corresponding to the index field, and the address data corresponding to a recording disk of this value, if no index, determining one by one, according to whether the value of the disk address query the same value, there is space index later retrieved directly to the index value will also be able to find this record corresponding disk addresses.

The only difference between the primary key index and the index is the primary key index can not be null, unique index can have a null value.

Binary search data, start from the middle value filter, can screen out every half value. Left subtree is smaller than the parent node, right-child node is greater than the number of parent

Balanced binary tree (ABLTree): depth difference of about sub-trees must not be more than one

When inserted in the order number may be in only the left or right node node, right-handed or left-handed balanced binary tree by left and right subtrees do difference in depth not more than 1

Balanced binary tree, each node stores: index field value, the disk should address records, left subtree reference points address, a reference node of the right subtree

innodb each operation is the smallest unit of disk page 16KB, data is loaded from disk into memory, the default data around the data will be accessed, it is loaded into memory, locality principle. Access a node is a disk IO, each node placeholder for the 16KB = 16384 bytes, if each disk block storage node rarely wasted a lot of time addressing. Number of depth too deep

B number, use split and merge ensure a balanced B-tree, called multi-channel balanced search tree, the number of child nodes have called degrees, the number of keywords is N, the degree of N + 1, each node is a page, that page merge and split

Index storage structures using B + Tree, enhanced version of the multi-channel balanced search tree, the number of child nodes have called degrees, the number of keywords is N, the degree N, only leaf nodes only store the complete index data corresponding to the disk address records. All data are placed in the leaf node, the number of IO find all the data, depth data is the same, to ensure the stability of the IO efficiency, each adjacent leaf node, leaf node has a pointer pointing to the adjacent .

B + Tree, Tree solve the deep problems, the number of IO solve many problems, sweep library, strong ability to sweep the table, will be able to sweep the table to get all the data according to the pointer adjacent leaf nodes, do not always look for the root node. Sort stronger, leaf nodes are ordered lists, stable efficiency.

Hash values ​​can be specified for the index, according to Hash code, find records, only the equivalent of its discovery, taking the index to find support not

mysql storage engine is innodb, is to table storage engine type, the way table data storage and management of data, each table can have its own storage engine, did not specify the default is innodb, supports row-level locking, support things.

In myisam storage engine, indexes are B + Tree structure, the index file in .MYI leaf node corresponding to the record is placed disk address. .MYD specific data on file, according to disk address, access to data.

In innodb, the index is a B + Tree structure, the primary key index, the storage engine innodb full data corresponding to the index into all fields of the leaf nodes. The key sequence primary key determines the order of the physical store, the physical order of the master key with the same key index called the clustered index, only the primary key index is clustered index.

It determines the physical storage of data index called the clustered index.

If there is no primary key for a table, then determine the physical order is unique only non-empty field, and if they are not, there will be a hidden rowid as a clustered index to determine the physical disk order.

innodb, in addition to other primary key index index index called secondary or secondary index

Only one copy of the complete data, stored in the leaf nodes only the primary key index. Other indices, except leaf nodes store the value of the index field, and also holds the value of the primary key index corresponding to the recorded article.

His assistant, the index corresponds to a B + Tree, when looking from the secondary node with the index, find the leaf nodes to find the value corresponding to get the value of the primary key index, primary key index scan corresponds to B + Tree leaf nodes come, get the final value which records all fields. Than one primary key index scan multiple B + Tree.

Joint index, the leftmost match

In mysql can not be used in the index are optimizer (Optimizer) decision, he will immediately calculate the cost of deciding whether to use the index to find

Use function is to calculate the index column or expression can not take the index.

String without the quotes, implicit conversions do not take the index appears

like conditions do not go preceded by the prefix index%, you can go behind the increase in the index%

not like, not in, <> if this does not necessarily take the index

Database Optimization:

Table III Model building: a Paradigm: Field atomic, can not be divided; second paradigm: first normal form no part dependent, is not the primary key business processes. Third Pattern: second normal, not passed dependent.

The three-paradigm little redundancy, update delete operation simple, but also according to demand a reasonable construction of the table.

Try to use the correct minimum data structure for storing data

Try to use a string that represents an integer, try to use not null, null and statistics so that the index is more complex, the index try not to be built in the empty field.

Published 15 original articles · won praise 0 · Views 1063

Guess you like

Origin blog.csdn.net/ma316110/article/details/105346956