我应该摆脱Guid列上的聚集索引吗

编程入门 行业动态 更新时间:2024-10-27 06:28:23
本文介绍了我应该摆脱Guid列上的聚集索引吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在一个通常使用GUID作为主键的数据库上工作.

I am working on a database that usually uses GUIDs as primary keys.

默认情况下,SQL Server在主键列上放置一个聚集索引.我知道这对于GUID列是一个愚蠢的想法,并且非聚集索引更好.

By default SQL Server places a clustered index on primary key columns. I understand that this is a silly idea for GUID columns, and that non-clustered indexes are better.

您怎么看-我应该摆脱所有聚集索引,并用非聚集索引替换它们吗?

What do you think - should I get rid of all the clustered indexes and replace them with non-clustered indexes?

SQL的性能调节器为什么不提供此建议呢?

Why wouldn't SQL's performance tuner offer this as a recommendation?

推荐答案

聚集索引的一个重要原因是,当您经常想检索给定列的一系列值的行时.由于数据是按物理顺序排列的,因此可以非常有效地提取行.

A big reason for a clustered index is when you often want to retrieve rows for a range of values for a given column. Because the data is physically arranged in that order, the rows can be extracted very efficiently.

像GUID这样的东西虽然对主键非常有用,但可能会对性能产生不利影响,因为插入会增加成本,并且对选择没有明显的好处.

Something like a GUID, while excellent for a primary key, could be positively detrimental to performance, as there will be additional cost for inserts and no perceptible benefit on selects.

是的,不要在GUID上聚集索引.

So yes, don't cluster an index on GUID.

关于为什么不推荐它的原因,我建议调谐器意识到这一事实.

As to why it's not offered as a recommendation, I'd suggest the tuner is aware of this fact.

更多推荐

我应该摆脱Guid列上的聚集索引吗

本文发布于:2023-11-22 09:13:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616832.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   Guid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!