sql索引的填充因子多少最好,填充因子有什么用

和索引重建最相关的是填充因子。当创建一个新索引,或重建一个存在的索引时,你可以指定一个填充因子,它是在索引创建时索引里的数据页被填充的数量。填充因子设置为100意味着每个索引页100%填满,50%意味着每个索引页50%填满。
   
   如果你创建一个填充因子为100的聚集索引(在一个非单调递增的列上),那意味着每当一个记录被插入(或修改)时,页拆分都会发生,因为在现存的页上没有这些数据的空间。很多的页拆分会降低sqlserver的性能。
   
   举个例子:假定你刚刚用缺省的填充因子新创建了一个索引。当sqlserver创建它时,它把索引放在相邻的物理页面上,因为数据能够顺序的读所以这样会有最优的i/o访问。但当表随着、、增加和改变时,发生了页拆分。当页拆分发生时,sqlserver必须在磁盘的某处分配一个新的页,这些新的页和最初的物理页不是连续的。因此,访问使用的是随机的i/o,而不是有顺序的i/o,这样访问索引页会变得更慢。
   
   那么理想的填充因子是多少呢?它依赖于应用程序对sqlserver表的读和写的比率。首要的原则,按照下面的指导:
   
   低更改的表(读写比率为100:1):100%的填充因子
   
   高更改的表(写超过读):50-70%的填充因子
   
   读写各一半的:80-90%的填充因子
   
   在为应用程序找到最优的填充因子前也不得不进行试验。不要假定一个低的填充因子总比高的好。低的填充因子会减少页拆分,它也增加了sqlserver查询期间读的页数量,从而减少性能。太低的填充因子不仅增加i/o开销,也影响缓存。当数据页从磁盘移到缓存中时,整个页(包括空的空间)都移到缓存中。所以填充因子越低,不得不移到sqlserver缓存中的页面就越多,意味着同时为其他重要数据页驻留的空间就少,从而降低性能。
   
   如果你没有指定填充因子,缺省的填充因子时0,意味着100%的填充因子(索引的叶页100%的填满,但索引的中间页有预留的空间)。
   
   作为监控的一部分,你要决定新建索引或重建索引时的填充因子是多少。事实上,除了只读数据库,所有的情况,缺省值0都是不适合的。相反,你想要一个填充因子保留合适的自由空间,按照上面的讨论来做。
posted @   silentmuh  阅读(176)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
Live2D
欢迎阅读『sql索引的填充因子多少最好,填充因子有什么用』
  1. 1 Walk Thru Fire Vicetone
  2. 2 爱你 王心凌
  3. 3 Inspire Capo Productions - Serenity
  4. 4 Welcome Home Radical Face
  5. 5 粉红色的回忆 李玲玉
Walk Thru Fire - Vicetone
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Van Der Voort, Joren Johannes

作曲 : Victor Pool/Justin Gammella/Ruben Christopher den Boer/Meron Mengist/Joren van der Voort

Talk to me

Spill the secrets you've been keeping

Life cuts deep

Let me help pick up the pieces

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

No matter what, I'll make it right

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire

You know I

Don't pretend to be a savior

But let me in, yeah

I promise nobody can break us

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

No matter what, I'll make it right

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire with you

You're not alone, I'm by your side

Don't you know, don't you know

I'll walk through fire with you

I'll walk through fire

I'm not an angel, I'm not a saint

I've been a closed book full of mistakes

But when you're broken, when you're in pain

Oooh, ooh

I'll walk through fire with you

I'll walk through fire with you

I'll walk through fire

I'll walk through fire with you

I'll walk through fire with you

点击右上角即可分享
微信分享提示