database index

Depending on the capabilities of the database, three types of indexes can be created in the database designer:

    唯一索引

    主键索引

    聚集索引。

Difference between primary key and unique index

    (1)主键是特殊的唯一索引,唯一索引不一定是主键

    (2)一个表可以有多个唯一索引,但只能有一个主键(可以是联合主键)

    (3)主键列不允许空值,而唯一索引列允许空值

The nature of indexes

  • MySQL's official definition of an index is: An index is a data structure that helps MySQL efficiently obtain data.

Commonly used database query algorithms

  • The most basic query algorithm is a sequential search (linear search) with a time complexity of O(n), which is obviously very inefficient when the amount of data is large.
  • Binary search
    Optimized search algorithms such as binary search, binary tree search, etc., although the search efficiency is improved.

    但是各自对检索的数据都有要求:
    二分查找要求被检索数据有序,而二叉树查找只能应用于二叉查找树上,但是数据本身的组织结构不可能完全满足各种数据结构(例如,理论上不可能同时将两列都按顺序进行组织)。所以,在数据之外,数据库系统还维护着满足特定查找算法的数据结构。
     这些数据结构以某种方式引用(指向)数据,这样就可以在这些数据结构上实现高级查找算法。这种数据结构就是索引。
    
  • Binary tree search

    B-tree和B+tree就是数据结构中的二叉树的父子节点来存储信息,加快信息的搜索和查询。插入信息只能在子节点中插入,父节点不动 。
    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324585110&siteId=291194637