聚集索引和非聚集索引的区别

Difference between clustered and nonclustered index(聚集索引和非聚集索引的区别)
本文介绍了聚集索引和非聚集索引的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的表格中添加适当的 index 并且需要一些帮助.

I need to add proper index to my tables and need some help.

我很困惑,需要澄清几点:

I'm confused and need to clarify a few points:

  • 我应该对 non-int 列使用索引吗?为什么/为什么不

  • Should I use index for non-int columns? Why/why not

我已经阅读了很多关于 clusterednon-clustered 索引的内容,但我仍然无法决定何时使用一个而不是另一个.一个很好的例子将帮助我和许多其他开发人员.

I've read a lot about clustered and non-clustered index yet I still can't decide when to use one over the other. A good example would help me and a lot of other developers.

我知道我不应该对经常更新的列或表使用索引.在进入测试阶段之前,我还应该注意什么?我怎么知道一切都很好?

I know that I shouldn't use indexes for columns or tables that are often updated. What else should I be careful about and how can I know that it is all good before going to test phase?

推荐答案

你真的需要把两个问题分开:

You really need to keep two issues apart:

1) 主键 是一种逻辑结构 - 唯一且可靠地标识表中每一行的候选键之一.这实际上可以是任何东西 - 一个 INT、一个 GUID、一个字符串 - 选择最适合您的场景的内容.

1) the primary key is a logical construct - one of the candidate keys that uniquely and reliably identifies every row in your table. This can be anything, really - an INT, a GUID, a string - pick what makes most sense for your scenario.

2) 聚簇键(在表上定义聚簇索引"的一列或多列)——这是一个物理存储相关的东西,这里, 小型、稳定、不断增加的数据类型是您的最佳选择 - INT 或 BIGINT 作为您的默认选项.

2) the clustering key (the column or columns that define the "clustered index" on the table) - this is a physical storage-related thing, and here, a small, stable, ever-increasing data type is your best pick - INT or BIGINT as your default option.

默认情况下,SQL Server 表上的主键也用作集群键 - 但不必如此!

By default, the primary key on a SQL Server table is also used as the clustering key - but that doesn't need to be that way!

我要应用的一个经验法则是:任何常规"表(用于存储数据的表,即查找表等)都应该有一个集群键.没有聚集键真的没有意义.实际上,与人们普遍认为的相反,拥有一个集群键实际上可以加快所有常见的操作——甚至是插入和删除(因为表的组织是不同的,而且通常比使用更好——一个没有集群的表键).

One rule of thumb I would apply is this: any "regular" table (one that you use to store data in, that is a lookup table etc.) should have a clustering key. There's really no point not to have a clustering key. Actually, contrary to common believe, having a clustering key actually speeds up all the common operations - even inserts and deletes (since the table organization is different and usually better than with a heap - a table without a clustering key).

金伯利特里普,The Queen of Indexing 有很多优秀的文章,主题是为什么要使用集群键,以及哪种列最适合用作您的集群键.由于每个表只能获得一个,因此选择正确的聚类键至关重要 - 而不仅仅是任何聚类键.

Kimberly Tripp, the Queen of Indexing has a great many excellent articles on the topic of why to have a clustering key, and what kind of columns to best use as your clustering key. Since you only get one per table, it's of utmost importance to pick the right clustering key - and not just any clustering key.

  • GUID 作为PRIMARY KEY 和/或聚集键
  • 聚集索引的争论还在继续
  • 曾经- 增加聚集键 - 聚集索引辩论.......... 再次!
  • 磁盘空间很便宜 - 不是 重点!

马克

这篇关于聚集索引和非聚集索引的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)