Index的填充属性:FillFactor 和 PAD_INDEX

在Create Index时,必须慎重考虑属性FillFactor 和 PAD_INDEX的设置,这两个属性只在create index 或 rebuild index时起作用,表示Index page(Leaf-Level 或 intermediate-Level)的填充程度。如果设置FillFactor=90,那么SQL Server 在create index 或 rebuild index时,不是将Index Page的空间全部用完,而是只使用接近90%的Page空间,预留10%的空闲空间,这预留的Page内部的空间叫做 Internal Fragmentation。预留一定比例的Fragmentation有一定的用途,reduce page split,能够提高数据更新的性能;而Fragmentation 太多,会降低查询性能。

Index 是BTree 结构,分为Leaf-Level Page 和 Intermediate-Level Page(即NonLeaf-Level Page)。

FillFactor 属性指定Index Leaf-Level pages的填充percent,MS建议FillFactor=90。

PAD_INDEX 属性是boolean 类型,指定是否使用FillFactor 来填充Index Intermediate-Level Pages。

An explicit FILLFACTOR setting applies only when the index is first created or rebuilt.  在插入数据时,SQL Server 尽可能使用Page全部的空间,而不会考虑填充属性。

1,PAD_INDEX = { ON | OFF }

Specifies index padding. The default is OFF.

ON  The percentage of free space that is specified by fillfactor is applied to the intermediate-level pages of the index.
OFF or fillfactor is not specified                    

The intermediate-level pages are filled to near capacity, leaving sufficient space for at least one row of the maximum size the index can have, considering the set of keys on the intermediate pages.

The PAD_INDEX option is useful only when FILLFACTOR is specified, because PAD_INDEX uses the percentage specified by FILLFACTOR. If the percentage specified for FILLFACTOR is not large enough to allow for one row, the Database Engine internally overrides the percentage to allow for the minimum. The number of rows on an intermediate index page is never less than two, regardless of how low the value of fillfactor.

2,FILLFACTOR =fillfactor

Specifies a percentage that indicates how full the Database Engine should make the leaf level of each index page during index creation or rebuild. fillfactor must be an integer value from 1 to 100. If fillfactor is 100, the Database Engine creates indexes with leaf pages filled to capacity.The default is 0.

An explicit FILLFACTOR setting applies only when the index is first created or rebuilt.

The FILLFACTOR setting applies only when the index is created or rebuilt. The Database Engine does not dynamically keep the specified percentage of empty space in the pages. To view the fill factor setting, use the sys.indexes catalog view.

                           Important                        

Creating a clustered index with a FILLFACTOR less than 100 affects the amount of storage space the data occupies because the Database Engine redistributes the data when it creates the clustered index.

3,Specify Fill Factor for an index

The fill-factor option is provided for fine-tuning index data storage and performance. When an index is created or rebuilt, the fill-factor value determines the percentage of space on each leaf-level page to be filled with data, reserving the remainder on each page as free space for future growth. For example, specifying a fill-factor value of 80 means that 20 percent of each leaf-level page will be left empty, providing space for index expansion as data is added to the underlying table. The empty space is reserved between the index rows rather than at the end of the index.

The fill-factor value is a percentage from 1 to 100, and the server-wide default is 0 which means that the leaf-level pages are filled to capacity.Fill-factor values 0 and 100 are the same in all respects.

4,Performance Considerations

Page Splits

A correctly chosen fill-factor value can reduce potential page splits by providing enough space for index expansion as data is added to the underlying table.When a new row is added to a full index page, the Database Engine moves approximately half the rows to a new page to make room for the new row. This reorganization is known as a page split. A page split makes room for new records, but can take time to perform and is a resource intensive operation. Also, it can cause fragmentation that causes increased I/O operations. When frequent page splits occur, the index can be rebuilt by using a new or existing fill-factor value to redistribute the data. For more information, see Reorganize and Rebuild Indexes.

Although a low, nonzero fill-factor value may reduce the requirement to split pages as the index grows, the index will require more storage space and can decrease read performance. Even for an application oriented for many insert and update operations, the number of database reads typically outnumber database writes by a factor of 5 to 10. Therefore, specifying a fill factor other than the default can decrease database read performance by an amount inversely proportional to the fill-factor setting. For example, a fill-factor value of 50 can cause database read performance to decrease by two times. Read performance is decreased because the index contains more pages, therefore increasing the disk IO operations required to retrieve the data.

Adding Data to the End of the Table

A nonzero fill factor other than 0 or 100 can be good for performance if the new data is evenly distributed throughout the table. However, if all the data is added to the end of the table, the empty space in the index pages will not be filled. For example, if the index key column is an IDENTITY column, the key for new rows is always increasing and the index rows are logically added to the end of the index. If existing rows will be updated with data that lengthens the size of the rows, use a fill factor of less than 100. The extra bytes on each page will help to minimize page splits caused by extra length in the rows.

5,An Example To specify a fill factor in an existing index

Script1

-- Rebuilds the IX_Employee_OrganizationLevel_OrganizationNode index
-- with a fill factor of 80 on the HumanResources.Employee table.

ALTER INDEX IX_Employee_OrganizationLevel_OrganizationNode
ON HumanResources.Employee
REBUILD
WITH (FILLFACTOR = 80);

Script2

CREATE INDEX IX_Employee_OrganizationLevel_OrganizationNode
ON HumanResources.Employee
(OrganizationLevel, OrganizationNode)
WITH (DROP_EXISTING = ON, FILLFACTOR = 80); 

参考文档:

https://msdn.microsoft.com/en-us/library/ms188783(v=sql.110).aspx

https://msdn.microsoft.com/en-us/library/ms177459(v=sql.110).aspx

时间: 2024-11-08 18:20:55

Index的填充属性:FillFactor 和 PAD_INDEX的相关文章

Spring IOC 容器源码分析 - 填充属性到 bean 原始对象

1. 简介 本篇文章,我们来一起了解一下 Spring 是如何将配置文件中的属性值填充到 bean 对象中的.我在前面几篇文章中介绍过 Spring 创建 bean 的流程,即 Spring 先通过反射创建一个原始的 bean 对象,然后再向这个原始的 bean 对象中填充属性.对于填充属性这个过程,简单点来说,JavaBean 的每个属性通常都有 getter/setter 方法,我们可以直接调用 setter 方法将属性值设置进去.当然,这样做还是太简单了,填充属性的过程中还有许多事情要做.

如何填充属性树?

属性树可以解析4种文件,现在,我就将其一一列出 XML JSON INI INFO XML Parser XML格式是用于以文本形式存储信息的行业标准.不幸的是,在撰写本文时,没有XML解析器.因此,该库包含快速和微小的RapidXML解析器(当前版本1.13),以提供XML解析支持.RapidXML并不完全支持XML标准;它不能解析dtd,因此不能进行完全的实体替换.[说一句废话,其实,也没有要这个东西完全支持XML的解析,因为,完全的XML的解析,可以使用更加专业的库,如TinyXML2之类

padding填充属性

内边距属性: 设置元素的内容与边框之间的距离. 分4个方向(上右下左): padding-top padding-right padding-bottom padding-left 说明:值不能为负值. 盒子在网页中占的空间,不单单与width和height属性有关, 还与padding有关. 原文地址:https://www.cnblogs.com/hugegege/p/9457806.html

索引优化之:创建、填充和查找

在做性能优化时,经常需要创建索引,维护索引,或重建,或重组:在创建索引时,索引的数据页有时需要填充满,有时需要预留一定比例的空闲空间:在分析查询的执行计划之后,推荐创建覆盖索引(covering index),优化查询语句,使用执行计划通过Index Seek来获取少量数据等,这些都是索引优化不得不知的要点. 一,索引的重组(Reorganize)和重建(Rebuild) 在SQL Server中,索引(Index)是B-Tree(balance tree)结构,每个Page之间都有双向指针链接

图解Elasticsearch中的_source、_all、store和index属性

Elasticsearch中有几个关键属性容易混淆,很多人搞不清楚_source字段里存储的是什么?store属性的true或false和_source字段有什么关系?store属性设置为true和_all有什么关系?index属性又起到什么作用?什么时候设置store属性为true?什么时候应该开启_all字段?本文通过图解的方式,深入理解Elasticsearch中的_source._all.store和index属性. 图1 Elasticsearch中的_source._all.stor

bean的创建(五)第五部分 属性填充

AbstractAutowireCapableBeanFactory.populateBean protected void populateBean(String beanName, RootBeanDefinition mbd, BeanWrapper bw) { //获取属性值 PropertyValues pvs = mbd.getPropertyValues(); if (bw == null) { if (!pvs.isEmpty()) { throw new BeanCreatio

SQL Server索引的维护 - 索引碎片、填充因子 <第三篇>

实际上,索引的维护主要包括以下两个方面: 页拆分 碎片 这两个问题都和页密度有关,虽然两者的表现形式在本质上有所区别,但是故障排除工具是一样的,因为处理是相同的. 对于非常小的表(比64KB小得多),一个区中的页面可能属于多余一个的索引或表---这被称为混合区.如果数据库中有太多的小表,混合区帮助SQL Server节约磁盘空间. 随着表(或索引)增长并且请求超过8个页面,SQL Server创建专用于该表(或索引)的区并且从该区中分配页面.这样一个区被称为统一区,它可以为多达8个相同表或索引的

JQ属性和CSS

1.attr(name|properties|key,value|fn) 设置或返回被选元素的属性值 $("img").attr("src"); 返回文档中所有图像的src属性值 $("img").attr({ src: "test.jpg", alt: "Test Image" }); 为所有图像设置src和alt属性 $("img").attr("src",&qu

jQuery入门(2)使用jQuery操作元素的属性与样式

jQuery入门(1)jQuery中万能的选择器 jQuery入门(2)使用jQuery操作元素的属性与样式 一.区分DOM属性和元素属性 对于下面这样一个标签元素: <img id='img' src="images/image.1.jpg" alt='1' class="imgs"></img> 我们通常将id.src.alt.class称为属性,也即元素属性.但是,当浏览器对标签元素进行解析时,会将元素解析为Dom对象,相应的,元素属性