当前位置:网站首页>Index principle and filling factor in database
Index principle and filling factor in database
2022-06-24 00:02:00 【One night, Nara mountain was at odds】
SQL SERVER Index principle and filling factor
stay SQL Server in , The index is by B Trees ( Balance tree ) Structured , Indexes B Each page in the tree is called an inode ,B The top node of the tree is called the root node , The underlying nodes in the index are called leaf nodes , Any index level between root node and leaf node is called intermediate level , When adding new data , To ensure that you need the same number of reads to find each page , Intermediate level pages will be split to generate new layers , As shown in the figure .

The width of each layer is increased to the number of pages that the previous layer can record , When the existing tree cannot record more pages , A new layer will be created , The size of an indexed record is affected by the size of the indexed column , So the narrower the indexed column , The more indexes you can put on a page , Thus, the index requires fewer layers , Each floor needs 1 Sub logical reading , So the fewer levels of the index tree, the better .
The fill factor is the percentage of page fill data for each leaf layer , The fill factor option is provided to optimize index data storage and performance , Use fill factor Option to specify Microsoft SQL Server How full each page is when creating a new index using existing data .fill factor Option is an advanced option , If you use sp_configure System stored procedure to change this setting , Only in show advanced options Set to 1 Can only be changed fill factor, The settings take effect after the server is restarted .
When an index is created or rebuilt , The fill factor value determines the percentage of space on each leaf page to be filled with data , So as to reserve a certain percentage of free space for future expansion of the index . for example , Specifies that the value of the fill factor is 80 Indicates that each leaf level page will have 20% The space for is left empty , To provide space for the extended index as data is added to the underlying table .
The fill factor can be set to 1 To 100 A percentage between , in the majority of cases , The default value for server scope is 0, If the fill factor is set to 0, It means that the entire leaf level page is filled , However, in the actual test process, it is generally not set to fill full leaf pages , Because at least one more index row needs to be added , Use this setting to effectively use leaf level space , However, some space should be reserved for limited expansion before the page has to be split .
Be careful : Fill because it is set to 0 And set to 100 Same meaning , Means that the entire leaf level page is filled . And only after the index is created or regenerated , To apply the fill factor ,SQL Server Database Engine The specified percentage of free space is not dynamically maintained in the page , If you try to keep extra space on the data page , It will be against the original intention of using fill factor , Because with the input of data , The database engine will have to split pages on each page , To maintain the percentage of free space specified by the fill factor .
If you add a new row to a full index page , The database engine will move about half of the rows to the new page , To make room for this new line , This reorganization is called page splitting . Page splitting can make room for new records , But performing page splitting may take some time , This operation consumes a lot of resources . Besides , It can also cause debris , Which leads to I/O Operation increased , This will directly affect the performance of the database . Choosing the fill factor value correctly provides enough space to expand the index as you add data to the underlying table , Thus reducing the possibility of page splitting . If page splitting occurs frequently , The index can be rebuilt by using new or existing fill factor values , To redistribute data .
Although lower fill factor values are used ( Not 0) Reduce the need to split pages as the index grows , But indexing will require more storage space , And it will reduce the reading performance , Even for applications that target many insert and update operations , The number of database reads generally exceeds the number of database writes 5 To 10 times . therefore , Specifying a fill factor that is different from the default value will reduce the read performance of the database , The decrease ratio is inversely proportional to the fill factor setting . for example , When the fill factor is 50 when , The read performance of the database will be reduced by two times , Read performance is degraded because the index contains more pages , Therefore, the disk needed to retrieve data is increased I/O operation .
What does the fill factor in the index mean
If you have a glass full of water , You will try to add more water to this glass . What will happen ? The water will overflow .
SQL Server The same is true of . When the index page is full , If you try to add a new row , be SQL Server About half of the rows will be moved to the new page , To make room for newly added rows . This is what is usually said “ Page segmentation ”. Page splitting makes room for new records , But it is time-consuming and very resource consuming , And will produce fragments , Thus it is possible to I/O Operation has a negative impact . that , How to avoid this kind of situation ?
To prevent this kind of situation , The fill factor value must be determined proactively . After the index is created or rebuilt , The fill factor value determines the percentage of space used to fill data in each leaf page , The rest is reserved for future expansion . for example , Configure the fill factor value to 60 It means that for each leaf level page 40% Are empty , To provide space for index expansion when adding data to the underlying table .
The default fill factor value is always 0, This value applies in most cases . In general , The fill factor value is 0 This means that the leaf level is almost full , But there is some room , At least one more index row can be added .( Please note that , Fill factor is 0 and 100 Is similar to that of .)
sql Index fill factor is the best , What is the use of fill factors ?
The most relevant to index reconstruction is the fill factor . When creating a new index , Or rebuild an existing index , You can specify a fill factor , It is the number of data pages in the index that are filled when the index is created . Fill factor is set to 100 It means every index page 100% fill ,50% It means every index page 50% fill .
If you create a fill factor of 100 Clustered index of ( On a nonmonotonically increasing column ), That means whenever a record is inserted ( Or modify ) when , Page splits happen , Because there is no space for this data on the existing page . Many page splits will reduce sqlserver Performance of .
for instance : Suppose you just created a new index with the default fill factor . When sqlserver When it was created , It places the index on adjacent physical pages , Because the data can be read in sequence, this will have the optimal i/o visit . But when the watch follows 、、 Add and change , A page split has occurred . When page splitting occurs ,sqlserver A new page must be allocated somewhere on the disk , These new pages are not contiguous with the original physical pages . therefore , The access is random i/o, Not in order i/o, This makes it slower to access index pages .
So what is the ideal filling factor ? It depends on the application to sqlserver The ratio of reading to writing a table . The first principle , Follow the instructions below :
Low change table ( The reading / writing ratio is 100:1):100% Filling factor of
High change table ( Write more than read ):50-70% Filling factor of
Half read and half write :80-90% Filling factor of
You have to experiment before you can find the best fill factor for your application . Don't assume that a low fill factor is better than a high one . A low fill factor reduces page splitting , It also increases sqlserver Number of pages read during query , This reduces performance . Too low a fill factor not only increases i/o expenses , It also affects the cache . When data pages are moved from disk to cache , The whole page ( Including empty space ) All moved to the cache . So the lower the fill factor , Have to move to sqlserver The more pages in the cache , It means less space for other important data pages at the same time , This reduces performance .
If you do not specify a fill factor , The default fill factor is 0, signify 100% Filling factor of ( The leaf of the index 100% Filling of , But the middle page of the index has reserved space ).
As part of monitoring , You have to decide what the fill factor is when you create a new index or rebuild an index . in fact , Except read-only database , In all cases , The default value 0 Are not suitable . contrary , You want a fill factor to keep the right free space , Follow the above discussion .
Reprint :
SQL SERVER Index principle and filling factor - You know
边栏推荐
- Idea automatically generates unit tests, doubling efficiency!
- [proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)
- WPF效果之Expander+ListBox
- Unity text component space newline problem
- Synthetic big watermelon games wechat applet source code / wechat game applet source code
- Wechat applet picture verification code display
- I was cheated by my colleagues to work overtime on weekends. I haven't seen redis used like this...
- 日化用品行业集团采购管理系统改变传统采购模式,降低采购成本
- Loop caused by add of sublist in list
- Setting method of bar code local segment data variable
猜你喜欢

I was cheated by my colleagues to work overtime on weekends. I haven't seen redis used like this...

Return, const, volatile keywords

抖音实战~手机号密码一键注册登录流程(限制手机终端登录)

windows10安全模式进入循环蓝屏修复

2. camera calibration

How to ensure reliable power supply of Expressway

1. < tag dynamic programming and path combination problem > lt.62 Different paths + lt.63 Different paths II

extern、struct等关键字

How to achieve energy-saving and reasonable lighting control in order to achieve the "double carbon" goal

混沌工程,了解一下
随机推荐
windows10安全模式进入循环蓝屏修复
CPU取指到发出控制、微程序控制原理详细过程
【面试经验包】面试被吊打经验总结(一)
2.摄像机标定
[things about gbase] gbase 8s high availability technology and case analysis (issue 02)
String s = new string ("XYZ") how many string objects are created?
APP性能优化之启动流程分析
The easycvr program started abnormally as a service, but the process started normally. What is the reason?
2021-11-23: Regulations: l[1] corresponds to a, l[2] corresponds to B, l[3] corresponds to C
量化投资模型——高频交易做市模型相关(Avellaneda & Stoikov’s)研究解读&代码资源
Idea automatically generates unit tests, doubling efficiency!
.NET 中的 Worker Service 介绍
1.< tag-动态规划和路径组合问题>lt.62. 不同路径 + lt.63. 不同路径 II
Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)
What is the difference between concurrency and parallelism?
Loop caused by add of sublist in list
迷茫的测试/开发程序员,不同人有着不同的故事、有着不同的迷茫......
B2B transaction management system of electronic components industry: improve the data-based driving ability and promote the growth of enterprise sales performance
Quantitative investment model -- research interpretation of high frequency trading market making model (Avellaneda & Stoikov's) & code resources
EasyCVR程序以服务启动异常,进程启动却正常,是什么原因?