From what I have read, indexing is like writing index page at the front of the book to make sure the db doesnt have to go through all the pages.
根据我的阅读,索引就像在书的前面编写索引页,以确保数据库不必遍历所有页面。
If primary key is indexed, wouldnt it be exactly same as going through the entire book because they are all unique anyways so the categorization within the index of primary key is same as the number of documents. If so, what is the purpose of indexing primary keys if there is no performance benefit?
如果主键被索引,则不会与遍历整本书完全相同,因为它们都是唯一的,因此主键索引中的分类与文档的数量相同。如果是这样,如果没有性能优势,索引主键的目的是什么?
1 个解决方案
#1
2
The primary key is an index -- keys are indexes! It's just a special name for a special kind of index which is always unique, and which may have an automatically assigned value.
主键是索引 - 键是索引!它只是一种特殊类型索引的特殊名称,它始终是唯一的,并且可能具有自动分配的值。
In some databases, the rows are sometimes (or always) stored in the same order as the primary key. In these situations, the primary key may not need to be separately indexed -- the order of the rows is enough of an index on its own.
在某些数据库中,行有时(或始终)以与主键相同的顺序存储。在这些情况下,主键可能不需要单独编制索引 - 行的顺序本身就足够了索引。
In some other databases, the primary key is not treated differently. The rows are stored in an arbitrary order -- perhaps in the order they were last modified, for example. In these situations, an index is needed on the primary key to look up the rows.
在某些其他数据库中,主键的处理方式不同。例如,行以任意顺序存储 - 可能按照它们上次修改的顺序存储。在这些情况下,主键上需要索引来查找行。
#1
2
The primary key is an index -- keys are indexes! It's just a special name for a special kind of index which is always unique, and which may have an automatically assigned value.
主键是索引 - 键是索引!它只是一种特殊类型索引的特殊名称,它始终是唯一的,并且可能具有自动分配的值。
In some databases, the rows are sometimes (or always) stored in the same order as the primary key. In these situations, the primary key may not need to be separately indexed -- the order of the rows is enough of an index on its own.
在某些数据库中,行有时(或始终)以与主键相同的顺序存储。在这些情况下,主键可能不需要单独编制索引 - 行的顺序本身就足够了索引。
In some other databases, the primary key is not treated differently. The rows are stored in an arbitrary order -- perhaps in the order they were last modified, for example. In these situations, an index is needed on the primary key to look up the rows.
在某些其他数据库中,主键的处理方式不同。例如,行以任意顺序存储 - 可能按照它们上次修改的顺序存储。在这些情况下,主键上需要索引来查找行。