php interview topics --- Mysql index type, description and advantages

php interview topics --- Mysql index type, description and advantages

A summary

Sentence summary:

Quality video to explain the sources of information which are also a variety of information, such as blog, books, etc., but is based on process knowledge to explain who has collated

 

1, B-Tree index three advantages?

1, the index server scans significantly reduce the amount of data
2, the index server to help avoid sorts and temporary tables
3, the index may be reduced random I / O becomes sequential I / O

 

2, whether the index is the best solution?

1, very small tables, full table scans in most cases more efficient
2, medium to large tables, indexes very effective
3, large tables TB [level, partitioning may be used, techniques for making substitution block-level metadata index

 

 

 

 

 

Two, Mysql index type, and advantages of the introduction (rpm)

Transfer: Mysql index type, description and advantages - simple book
https://www.jianshu.com/p/e9844e5d7e68

 

EDITORIAL:
Online index for classification of various definitions chaos, now do the sorting for index classification. Deficiencies, welcome to correct me.


In MySql, the index is stored in the engine rather than the server layer layer implementation.

First, the index type classification:

1. B-Tree index

Definitions and principles

B-Tree index tree generally means that all values are by sequentially stored , and each leaf page is the same distance from the root .

B-Tree index tree can speed up the access speed, access to data because the storage engine does not have to be a full table scan, but start the search from the root of the index. Storing groove root pointers to child nodes, according to the underlying storage engine to find these pointers. Find the right child node pointer into the underlying value and the value you're looking for relatively node pages, these pointers actually defines worthy of the upper and lower sub-node page. The final storage engine either find the corresponding value, or the record does not exist.

With the depth of the tree table size is directly related.

Using B-tree index type

Application type: Full key, key range, key prefix [only for the most left-prefix, which is Mysql relevant characteristics, even in a version]

Because the index tree nodes are ordered, so that the key may look, ORDER BY sequential search.

B-Tree indexing restrictions

  1. He did not follow the index of the most left-prefix lookup
  2. You can not skip a column index
  3. A column to find the range , then the right of all columns can not use the index to find. Case parties as follows:
 WHERE name='zhangsan' AND city LIKE 'shen%' AND `date` ='2019-12-07' 

2. hash indexes

The hash index is valid hash table implementation, only an exact match queries based on an index of all columns.
Each row, the storage engine will compute a hash code for all columns, hash code value is smaller, and different key row computed hash code is not the same.
In MySql Only Memory engines display support hash indexes. Memory is the default index type, also supports B-Tree index.
Memory engine supports non-unique index.

Hash indexing restrictions
  • Hash index and row pointers contain only values, without storing the field value, it can not use the index value to avoid reading lines.
  • Hash index can not be used for sorting, Yin Haxi index is not stored in index order.
  • Hash indexes do not support the part of the index to find matches, Yin Haxi index is always the entire contents of the column using an index to calculate the hash value.

3. The full-text index

To query filtered through keyword matching, based on the similarity to the query. The basic principle of full-text indexing Antilles Internet search engine.

To be further improved ...

4. Space Index

MyISAM tables support spatial indexing, geographic data can be used for storage.

Second, the advantages of index

1. B-Tree indexes three advantages:

Index substantially reduce the amount of data the server scans
the index server helps avoid sorting and temporary table
index can reduce the random I / O becomes sequential I / O

2. The index "Samsung System"

The index records are put together to get a satellite
index and search data in order to get the two stars have been sorted
index column contains all you need to query the Samsung column

3. whether the index is the best solution

Very small tables, in most cases more efficient full table scan
medium to large tables, indexes are effective
King [Table TB level, partitioning may be used, techniques for making substitution block-level metadata index

End the index embellishment

The full value of my favorite matches, the most left-prefix to follow;
take the lead in Big Brother can not die, the middle brother can not be broken;
less computationally index column, after the failure of the whole range;
the LIKE percentage rightmost write, do not write index covering the star;
ranging from air value there or, the index failed to use less.



 

 

 

 

 

Reproduced in: https: //www.cnblogs.com/Renyi-Fan/p/11073586.html

Guess you like

Origin blog.csdn.net/weixin_34161083/article/details/93572375