What do you know about the "index"

image

  1. 01

The nature of the index


In fact, when it comes to the term index, we don't understand this term well in some abstractions. You change your thinking and learning methods. You will find that indexes are everywhere in life.

image

such as:

When we go to the toilet, we have to look at the index signs for boys and girls so that we can't go wrong.

When we visit the mall, we have to look at the floor index signs so that we can understand what is on sale and what to play on each floor.

We do daily lives index posted rules, tell us 6 : 50 to get up, 7 : 00 to eat breakfast  7 : 30 work or school ........


With these indexes, it allows us to have order and goals in our lives.
Let’s talk about the index today, I hope you like it.
  1. 02

What is the essence of database indexes?


The essence of database index: Index is a distributed storage data structure created to speed up the retrieval of data rows in the table. Emphasize that it is a data structure. (Extension: Data structure can be understood as a way of computer storage and organization of data.)


image


What did you find in this picture?


I said: It is a tree with many branches.


I said: Green  green , frog is green , the trees are green. yellow  yellow , banana yellow. Pur ple is  purple , and grapes are purple. Orange is  orange, and oranges are orange. Blue  blue. You can learn a lot of colors through this tree.


I said: Each arrow indicates a direction.

  1. 03

How does the index work?


The working mechanism of the index is: in fact, during the query and retrieval, the object is directly pointed to the target object through the index.


image


What did you find in this picture?

 

I said: It is a syllable tree. The syllable has three branches, which are divided into initials, finals and tones.

 

I said: The initial line points to the letters bpmfdtnlgkhjqx zh ch sh rzcsyw.

 

I said: this line which vowel pointing AOE ai AO ou AN EI EN Ang ENG Ong i ia IE IAO IOU ian in IANG iong U UA UAI UAN uen uang ueng ü üe üan ün  which these objects .    

 

In fact, the initials, vowels, and tones are indexes and classifications.

  1. 04

What is the role of the index?


The function of index is actually a means to improve data retrieval performance.

image

This is a piece of student data, which contains information such as student name age phonenum .

 

What did you find in this picture?
I said: You can directly retrieve the personnel information of the 103 object by ID=103  . Searching for value through this ID will quickly find the catalog data, thereby improving the speed of data query. This is the actual role of the index.
  1. 05

What data structure can be used as an index?


Through what we said, these data structures can be used as indexes: array, hashMap  hashtable  , tree index. The execution speed of array index is fast but it must be a positive integer. HashMap can be understood as a container; hashTable  is stored in the form of key-value key-value pairs. They can all be used for index creation. But they all have advantages and disadvantages. The execution speed of array index is fast but it must be a positive integer; hashMap  thread is not safe and the traversal speed is slow; hash index has disadvantages: it is not conducive to range query and has no advantage of comparing size .


image


What did you find in this picture?


In fact, everything has its advantages and disadvantages in its existence, and it is not 100% complete.

  1. 06

Commonly used tree index Tree search is an index method for databases , and it is also the most commonly used index method in indexes.


Binary search tree Binary Search Tree ( Binary Search Tree ) ( Binary Search Tree , Binary Sort Tree) It is either an empty tree or a binary tree with the following properties :  if its left subtree is not empty, then the left subtree The value of all nodes is less than the value of its root node;  if its right subtree is not empty, the values ​​of all nodes on the right subtree are greater than the value of its root node;  its left and right subtrees The trees are also binary sort trees respectively .

 

image

You only need to remember its characteristics: "Left is smaller than right, and each node has two forks";二叉搜索树的平均查找长度及时间复杂度给它带来的问题就是:IO性能差,如果树很高的话,深度很深的话,查询起来非常麻烦。

 

B-(B-tree) 比如:二叉查找树,平衡二叉查找树 , 他们查找效率的时间复杂度O(log2n),跟树的深度有关系,那么怎么样才能提高效率呢?当然最快捷的方式就是减少树的深度了。那么怎么减少树的深度呢?

 

image

基本思想是:采用多叉树结构。
也就是说, 因为磁盘的操作费时费资源,过于频繁的多次查找势必效率低下。 也就是说, 只要我们通过某种较好的树结构减少树的结构尽量减少树的高度,便能有效减少磁盘查找存取的次数。   那这种有效的树结构是一种怎样的树呢?

B-(B-tree) 可以理解是种:多路平衡树,它实际就是体现在数据中就是多个关键字,通过多个关键字的索引创建,就能在大数据量的数据中查询检索出你想定位的数据信息。

  1. 07

其实讲了这么多,那最后咱们总结一下吧。


索引本质是什么?


image

你在这张图中发现并看到了什么?


索引就是一种指示、一种方向标。

  1. 08

image(公众号)
image(微信)

  1. 09

[ Writing instructions ] The above content is shared with programmers who like to program and have dreams, and hope to help you. The above article belongs to the original public account. If you need to reprint, please indicate the source. [ Disclaimer ] This public platform is not an advertiser, nor does it advertise for other third-party websites or individuals. The source code and articles shared here are some of the projects that I think are good in the project and study. Some voluntary download or payment behaviors generated by users. There is no direct relationship with the platform [ Submission Email ] [email protected]  Welcome to contribute and share your high-quality source code or articles



Guess you like

Origin blog.51cto.com/15067267/2576571