sql-server-2005 – newid()vs newsequentialid()有什么区别/利弊?

前端之家收集整理的这篇文章主要介绍了sql-server-2005 – newid()vs newsequentialid()有什么区别/利弊?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在所有主键都是GUID的数据库中,使用newid()和newsequentialid()作为“默认值或绑定”的差异/含义和/或优缺点是什么.

我唯一不同的是,newid()创建一个新的随机GUID而不是newsequentialid()创建一个新的GUID基于表中的最后一个增量的方式.

解决方法

据了解,当您在DB中执行插入操作时,将以相对于表中其他PK的顺序插入.通过正常的指导,这可以在桌子的任何地方.一个newsequentialid()将始终添加到表的末尾.

因此插入物的性能得到改善.

This site解释了两种不同方法之间的区别和基准.

更新 – 引用的博客文章已被移动.该链接现在指的是web.archive.org链接.这是关键外卖:

Most striking is the number of writes required by the NEWID system function. This,coupled with the average page density of 69%,is evidence of the page splitting caused by the random distribution of inserts at the leaf level. As soon as a page fills up,it needs to be split into 2 pages of 50% each for the insert to complete. Not only has page splitting resulted in poor page density,it has fragmented the data pages quite badly (there is a 99% probability that the next data page is not next to the current one). In our tests the most likely place for a free page required for the page split is at the end of the table irrespective of where the row is being inserted. Therefore to read the rows in order the scan needs to keep jumping back and forth between widely distributed split pages,hence the appalling fragmentation.

– 斯特凡德尔马科

原文链接:https://www.f2er.com/mssql/83094.html

猜你在找的MsSQL相关文章