The principle of Mysql

  The article has a brief introduction to the basics Mysql index , this article focuses on the realization of the principle explain it. The definition of the index is actually very complex, the need to use a strict definition of the concept of relational algebra, not within the scope of our discussion, here we only discuss the common index mysql engines, and these engines Why choose B + Tree?

The nature of the index

  MySQL is the official definition of the index: the index (Index) to help MySQL efficiently get the data structure of the data. Extracting a sentence trunk, you can get the essence of the index: the index is a data structure.

  We know that the database query is one of the most important functions of the database. We all want to query the data rate can be as fast as possible, so designers can optimize the database system from the perspective of query algorithms. Of course, the most basic query algorithm is a sequential search (linear search), this complexity is obviously a bad time O (n) algorithm in a large amount of data, and good development of computer science provides a lot better search algorithm , for example, binary search (binary search), a binary tree lookup (binary tree search) and the like. If Little analysis will find that each search algorithm can only be applied on top of specific data structures, such as binary search request was ordered to retrieve the data, and binary tree can be applied only to find a binary search tree on, but the data itself structure is impossible to completely satisfy various data structures (e.g., theoretically impossible while the two are organized in sequence), so that, in addition to data, the database system also maintains data structures satisfy a particular search algorithm, the data structure reference (point) data in some way, so that you can achieve the advanced search algorithm on these data structures. This data structure is indexed.

  Figure 1 shows a possible indexing. On the left is a data table, a total of two seven records, the far left is the physical address of the data record (adjacent to the attention logically recorded on the disk are also not necessarily physically adjacent). To accelerate the lookup Col2, can maintain a binary search tree shown on the right, respectively, each node includes an index key and a pointer to the data record corresponding to a physical address, so that you can use a binary search in O ( L O G 2 n- ) the complexity of O (log2n) corresponding to the acquired data.

  While this is a genuine index, but almost no actual database system using a binary search tree or evolutionary species red-black tree (red-black tree) to achieve, the reason will be introduced below.

 

  In general, the index itself is also great, the disk can not all be stored in memory, so the index is often stored in the form of an index file. In this case, index lookup process will produce a disk I / O consumption, with respect to the memory access, I / O access to high consumption of several orders of magnitude, so the evaluation of the merits of a data structure as an index of the most important indicator is the disk I / O operations of progressive complexity in the discovery process. In other words, the structural organization of the index to minimize the number of accesses lookup process disk I / O's.

  For this purpose, the disk read demand, the required length every time the prefetch is generally an integer multiple of the page. And a node database system will be set equal to the size of a page, so that each node requires only one I / O can be fully loaded. Each time a new node to directly apply a page space, thus ensuring on one physical node be stored in a page, the computer memory allocations are combined page-aligned, a node is realized with a single I / O. M and the value set in the B-tree is very large, it will allow to reduce the height of the tree, in favor of a fully loaded

B-tree principle of

 

B + tree principle

 

The difference between B-tree and B + tree of

 

Why choose Mysql B + Tree?

 

MYISAM and the difference between InnoDB

 

Guess you like

Origin www.cnblogs.com/htyj/p/10995630.html