pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

UniqueIdentifier 聚集索引上的 NewSequentialId

NewSequentialId on UniqueIdentifier Clustered Index(UniqueIdentifier 聚集索引上的 NewSequentialId)
本文介紹了UniqueIdentifier 聚集索引上的 NewSequentialId的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在為我公司正在啟動的新數(shù)據(jù)庫制定數(shù)據(jù)庫標準.我們試圖定義的一件事是與 UniqueIdentifiers 相關(guān)的主鍵和聚集索引規(guī)則.

I am working on database standards for a new database my company is starting. One of the things we are trying to define is Primary Key and Clustered Index rules in relation to UniqueIdentifiers.

(注意:我不想討論使用 UniqueIdentifier 作為主鍵或聚集索引的利弊.網(wǎng)絡(luò)上有大量關(guān)于此的信息.這不是 那個討論.)

(NOTE: I do not want a discussion on the pros and cons of using a UniqueIdentifier as a primary key or clustered index. There is a ton of info on the web about that. This is not that discussion.)

所以這是讓我擔心的場景:

So here is the scenario that has me worried:

假設(shè)我有一個表,它有一個 UniqueIdentifier 作為聚集索引和主鍵.讓我們稱之為可樂.我將 ColA 的默認值設(shè)置為 NewSequentialId().

Say I have a table with a UniqueIdentifier as the clustered index and primary key. Lets call it ColA. I set the default value for ColA to be NewSequentialId().

使用 NewSequentialId() 我插入三個連續(xù)的行:

Using that NewSequentialId() I insert three sequential rows:

{72586AA4-D2C3-440D-A9FE-CC7988DDF065}
{72586AA4-D2C3-440D-A9FE-CC7988DDF066}
{72586AA4-D2C3-440D-A9FE-CC7988DDF067}

{72586AA4-D2C3-440D-A9FE-CC7988DDF065}
{72586AA4-D2C3-440D-A9FE-CC7988DDF066}
{72586AA4-D2C3-440D-A9FE-CC7988DDF067}

然后我重新啟動我的服務(wù)器.NewSequentialId 的文檔 說重新啟動 Windows 后,GUID 可以啟動再次來自較低的范圍,但仍然是全球唯一的."

Then I reboot my server. The docs for NewSequentialId say that "After restarting Windows, the GUID can start again from a lower range, but is still globally unique."

所以下一個起點可以低于上一個范圍.

So the next starting point can be lower than the previous range.

所以在重新啟動后,我又插入了 3 個值:

So after the restart, I insert 3 more values:

{35729A0C-F016-4645-ABA9-B098D2003E64}
{35729A0C-F016-4645-ABA9-B098D2003E65}
{35729A0C-F016-4645-ABA9-B098D2003E66}

{35729A0C-F016-4645-ABA9-B098D2003E64}
{35729A0C-F016-4645-ABA9-B098D2003E65}
{35729A0C-F016-4645-ABA9-B098D2003E66}

(我不確定該 guid 在數(shù)據(jù)庫中的確切表示方式,但讓我們假設(shè),因為這個 guid 以 3 開頭,而前一個以 7 開頭,所以 3 個比 7 個小".)

(I am not sure exactly how the guid is represented in the database, but lets assume since this one starts with 3 and the previous ones started with 7 that the 3 ones are "smaller" than the 7 ones.)

當您在聚集索引中間執(zhí)行插入操作時,必須重新映射索引.(至少我的 DBA 是這么告訴我的.)而且每次我重新啟動時,我都會冒著讓我的新 UniqueIdentifier 范圍正好位于其他先前范圍中間的風險.

When you do an insert that is in the middle of a clustered index, a remapping of the index has to happen. (At least so my DBA has told me.) And every time I reboot I run the risk of having my new UniqueIdentifier range be right in the middle of other previous ranges.

所以我的問題是:由于下一組 UniqueIdentifiers 將小于上一組,所以每次插入都會導(dǎo)致我的聚集索引混洗嗎?

So my question is: Since the next set of UniqueIdentifiers will be smaller than the last set, will every insert cause my clustered index to shuffle?

如果沒有,為什么?SQL Server 知道我在使用 NewSequentialId 嗎?有什么辦法彌補嗎?

And if not, why? Does SQL Server know that I am using NewSequentialId? Does it some how compensate for that?

如果沒有,那么它怎么知道我接下來要插入什么?也許接下來的一百萬次插入將從 3 開始.或者他們可能會從 7 開始.它怎么知道?

If not, then how does it know what I will insert next? Maybe the next million inserts will start with 3. Or maybe they will start with 7. How does it know?

或者它不知道并保持一切井然有序.如果是這種情況,那么一次重新啟動可能會嚴重影響性能.(這讓我覺得我需要自己的不受重啟影響的自定義 NewSequentialId.)對嗎?還是有什么我不知道的魔法?

Or does it not know and just keeps everything in order. If that is the case then one reboot could massively affect performance. (Which makes me think I need my own custom NewSequentialId that is not affected by reboots.) Is that correct? Or is there some magic I am not aware of?

在我的標準中強烈不鼓勵將 GUID 作為聚集索引.正如我上面所說,有很多原因表明這是一個壞主意.我想知道這是否是另一個原因.

GUID as a clustered index is strongly discouraged in my standard. As I said above, there are many reasons that this is a bad idea. I am trying to find out if this is another reason why.

推薦答案

通常,您將使用適當?shù)?FILL FACTOR 創(chuàng)建索引,以便在所有頁面中為這種情況留出空白空間.也就是說,一旦空白空間被填滿,聚集索引就會重新排序.

Normally you will create your indexes with an appropriate FILL FACTOR to leave empty space in all your pages for just such a scenario. That being said, the clustered index does get reordered once the empty space is filled.

我知道您不想討論使用 GUID 作為聚集鍵,但這是不推薦做法的原因之一.

I know you don't want to discuss using GUID as a clustered key, but this is one of the reasons that it's not a recommended practice.

將會發(fā)生的情況是,您將有越來越多的頁面拆分,這將在您不斷插入行時導(dǎo)致非常高的碎片水平,并且您將需要以更高的頻率重建索引以保持性能線.

What will happen is that you will have an increasing volume of page splits, which will lead to a very high level of fragmentation as you keep inserting rows, and you will need to rebuild your index at a higher frequency to keep performance in line.

有關(guān)該主題的完整處理,沒有比

For a full treatment on the topic, there's no better source than


Tripp 的
博客

附帶說明,當您考慮創(chuàng)建自己的 NewSequentialID 創(chuàng)建函數(shù)時,您可能遇到了設(shè)計問題,應(yīng)該重新考慮您的計劃.

As a side note, when you are considering creating your own NewSequentialID creation function, you probably have a design issue and should reconsider your plan.

這篇關(guān)于UniqueIdentifier 聚集索引上的 NewSequentialId的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類型來存儲字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉(zhuǎn)換為其整數(shù)表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉(zhuǎn)換為 mm/dd/yyyy?)
主站蜘蛛池模板: 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 咖啡加盟-咖啡店加盟-咖啡西餐厅加盟-塞纳左岸咖啡西餐厅官网 | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 免费B2B信息推广发布平台 - 推发网 | DWS物流设备_扫码称重量方一体机_快递包裹分拣机_广东高臻智能装备有限公司 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 联系我们-腾龙公司上分客服微信19116098882 | 泰安塞纳春天装饰公司【网站】| 济南菜鸟驿站广告|青岛快递车车体|社区媒体-抖音|墙体广告-山东揽胜广告传媒有限公司 | 玉米深加工设备-玉米深加工机械-新型玉米工机械生产厂家-河南粮院机械制造有限公司 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 非小号行情 - 专业的区块链、数字藏品行情APP、金色财经官网 | 砂尘试验箱_淋雨试验房_冰水冲击试验箱_IPX9K淋雨试验箱_广州岳信试验设备有限公司 | 家乐事净水器官网-净水器厂家「官方」 | 哈希PC1R1A,哈希CA9300,哈希SC4500-上海鑫嵩实业有限公司 | 济南菜鸟驿站广告|青岛快递车车体|社区媒体-抖音|墙体广告-山东揽胜广告传媒有限公司 | 沈阳庭院景观设计_私家花园_别墅庭院设计_阳台楼顶花园设计施工公司-【沈阳现代时园艺景观工程有限公司】 | 细沙回收机-尾矿干排脱水筛设备-泥石分离机-建筑垃圾分拣机厂家-青州冠诚重工机械有限公司 | 非小号行情 - 专业的区块链、数字藏品行情APP、金色财经官网 | 桁架机器人_桁架机械手_上下料机械手_数控车床机械手-苏州清智科技装备制造有限公司 | 仿真茅草_人造茅草瓦价格_仿真茅草厂家_仿真茅草供应-深圳市科佰工贸有限公司 | 踏板力计,制动仪,非接触多功能速度仪,逆反射系数测试仪-创宇 | 能耗监测系统-节能监测系统-能源管理系统-三水智能化 | 慈溪麦田广告公司,提供慈溪广告设计。 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 世纪豪门官网 世纪豪门集成吊顶加盟电话 世纪豪门售后电话 | 广州企亚 - 数码直喷、白墨印花、源头厂家、透气无手感方案服务商! | 高温链条油|高温润滑脂|轴承润滑脂|机器人保养用油|干膜润滑剂-东莞卓越化学 | 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 南京兰江泵业有限公司-水解酸化池潜水搅拌机-絮凝反应池搅拌机-好氧区潜水推进器 | 粘度计,数显粘度计,指针旋转粘度计 | 热缩管切管机-超声波切带机-织带切带机-无纺布切布机-深圳市宸兴业科技有限公司 | 硬质合金模具_硬质合金非标定制_硬面加工「生产厂家」-西迪技术股份有限公司 | 河南凯邦机械制造有限公司 | 天津散热器_天津暖气片_天津安尼威尔散热器制造有限公司 | 中空玻璃生产线,玻璃加工设备,全自动封胶线,铝条折弯机,双组份打胶机,丁基胶/卧式/立式全自动涂布机,玻璃设备-山东昌盛数控设备有限公司 | 郑州宣传片拍摄-TVC广告片拍摄-微电影短视频制作-河南优柿文化传媒有限公司 | 扬州汇丰仪表有限公司 | 破碎机_上海破碎机_破碎机设备_破碎机厂家-上海山卓重工机械有限公司 |