简体   繁体   English

索引数据库

[英]Indexing databases

如果我们在表的主键上建立索引,它将如何提高性能,就像创建索引后所需的记录可能出现在索引列表的末尾一样!!

I think you're mistaken in your understanding of how indexes work. 我认为您对索引如何工作的理解是错误的。 They're not lists. 他们不是清单。

For introductory reading on indexes, see the Wikipedia article . 有关索引的介绍性阅读,请参阅Wikipedia文章

Modern databases always have an index on the primary key. 现代数据库总是在主键上有一个索引。 Creating another one would -- at best -- do nothing to your performance. 最好再创建一个对您的性能没有任何帮助。

Once you create an index on a table, any actions on that table (inserts, updates & deletes) will also be made to the index, keeping the table and the index in sync. 在表上创建索引后,该表上的所有操作(插入,更新和删除)也将对索引进行,以使表和索引保持同步。

So if a row is added after the index is created, it will be put in the index in the correct place. 因此,如果在创建索引后添加了一行,它将被放置在索引中的正确位置。

If it's correct place IS at the end of the list, it's still faster because the database will use a Binary Search (or other optimised search algorithm) to find the item, resulting in far fewer reads than a full table scan. 如果将正确的IS放在列表的末尾,则它仍然会更快,因为数据库将使用Binary Search (或其他优化的搜索算法)来查找项目,从而导致读取次数远少于全表扫描。

Hope this helps, 希望这可以帮助,

The index is typically sorted. 通常对索引进行排序。 The database can then use a binary search and other mechanisms to ensure finding the desired item is efficient. 然后,数据库可以使用二进制搜索和其他机制来确保找到所需项目的效率很高。 Additionally, a table uses the primary key as a clustered index (typically) - the data in the table is laid out in the same order as this index which means that searching for data by this index is even faster. 此外,表使用主键作为聚簇索引(通常)-表中的数据与该索引的排列顺序相同,这意味着通过该索引搜索数据甚至更快。

这是否意味着没有搜索算法索引就没有好处????

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM