为索引指定填充因子Specify Fill Factor for an Index

02/17/2017

本文内容

适用于:

SQL Server 2016 及更高版本

Azure SQL 数据库

Azure Synapse Analytics

并行数据仓库

本主题说明什么是填充因子以及如何使用 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 或 SQL Server Management StudioSQL Server Management Studio 在 Transact-SQLTransact-SQL中指定索引的填充因子值。This topic describes what fill factor is and how to specify a fill factor value on an index in SQL Server 2019 (15.x)SQL Server 2019 (15.x) by using SQL Server Management StudioSQL Server Management Studio or Transact-SQLTransact-SQL.

提供填充因子选项是为了优化索引数据存储和性能。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. 例如,指定填充因子的值为 80 表示每个叶级页上将有 20% 的空间保留为空,以便随着向基础表中添加数据而为扩展索引提供空间。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.

填充因子的值是 1 到 100 之间的百分比,服务器范围的默认值为 0,这表示将完全填充叶级页。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.

备注

填充因子的值 0 和 100 在所有方面都是相同的。Fill-factor values 0 and 100 are the same in all respects.

本主题内容In This Topic

开始之前Before You Begin

性能注意事项Performance Considerations

页拆分Page Splits

正确选择填充因子值可提供足够的空间,以便随着向基础表中添加数据而扩展索引,从而降低页拆分的可能性。如果向已满的索引页添加新行, 数据库引擎Database Engine 将把大约一半的行移到新页中,以便为该新行腾出空间。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. 此外,它还可能造成碎片,从而导致 I/O 操作增加。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. 有关详细信息,请参阅 重新组织和重新生成索引。

虽然采用较小的非零填充因子值可减少随着索引的增长而拆分页的需求,但是索引将需要更多的存储空间,并且会降低读取性能。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. 即使对于面向许多插入和更新操作的应用程序,数据库的读取次数一般也会超过数据库写入次数的 5 到 10 倍。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. 例如,当填充因子的值为 50 时,数据库的读取性能会降低两倍。For example, a fill-factor value of 50 can cause database read performance to decrease by two times. 读取性能降低是因为索引包含较多的页,因此增加了检索数据所需的磁盘 I/O 操作。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

如果新数据在表中均匀分布,则不是 0 或 100 的非零填充因子对性能有利。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. 例如,如果索引键列是 IDENTITY 列,则新行的键将总是增加,并且索引行在逻辑意义上将添加到索引的末尾。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. 如果将用加长行的大小的数据来更新现有行,则请使用小于 100 的填充因子。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.

SecuritySecurity

权限Permissions

要求对表或视图具有 ALTER 权限。Requires ALTER permission on the table or view. 用户必须是 sysadmin 固定服务器角色的成员,或者是 db_ddladmin 和 db_owner 固定数据库角色的成员。User must be a member of the sysadmin fixed server role or the db_ddladmin and db_owner fixed database roles.

使用 SQL Server Management StudioUsing SQL Server Management Studio

使用表设计器指定填充因子To specify a fill factor by using Table Designer

在对象资源管理器中,单击加号以便展开包含你要指定索引填充因子的表的数据库。In Object Explorer, click the plus sign to expand the database that contains the table on which you want to specify an index's fill factor.

单击加号以便展开 “表” 文件夹。Click the plus sign to expand the Tables folder.

右键单击你要指定索引的填充因子的表,然后选择“设计”。Right-click the table on which you want to specify an index's fill factor and select Design.

在“表设计器”菜单上,单击“索引/键”。On the Table Designer menu, click Indexes/Keys.

选择您要指定填充因子的索引。Select the index with the fill factor that you want to specify.

展开 “填充规范”,选择 “填充因子” 行并在行中输入所需的填充因子。Expand Fill Specification, select the Fill Factor row and enter the fill factor you want in the row.

单击“关闭” 。Click Close.

在“文件”菜单上,选择“保存”以保存 table_name。On the File menu, select Savetable_name.

使用对象资源管理器为索引指定填充因子To specify a fill factor in an index by using Object Explorer

在对象资源管理器中,单击加号以便展开包含你要指定索引填充因子的表的数据库。In Object Explorer, click the plus sign to expand the database that contains the table on which you want to specify an index's fill factor.

单击加号以便展开 “表” 文件夹。Click the plus sign to expand the Tables folder.

单击加号以展开要指定索引的填充因子的表。Click the plus sign to expand the table on which you want to specify an index's fill factor.

单击加号以便展开 “索引” 文件夹。Click the plus sign to expand the Indexes folder.

右键单击要指定填充因子的索引,然后选择“属性”。Right-click the index with the fill factor that you want to specify and select Properties.

在 “选择页” 下,选择 “选项” 。Under Select a page, select Options.

在 “填充因子” 行中,输入所需的填充因子。In the Fill factor row, enter the fill factor that you want.

单击“确定”。Click OK.

使用 Transact-SQLUsing Transact-SQL

在现有索引中指定填充因子To specify a fill factor in an existing index

在 “对象资源管理器” 中,连接到 数据库引擎Database Engine的实例。In Object Explorer, connect to an instance of 数据库引擎Database Engine.

在标准菜单栏上,单击 “新建查询” 。On the Standard bar, click New Query.

将以下示例复制并粘贴到查询窗口中,然后单击“执行” 。Copy and paste the following example into the query window and click Execute. 该示例重新生成现有索引,并在重新生成操作过程中应用指定的填充因子。The example rebuilds an existing index and applies the specified fill factor during the rebuild operation.

USE AdventureWorks2012;

GO

-- 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);

GO

为索引指定填充因子的其他方法Another way to specify a fill factor in an index

在 “对象资源管理器” 中,连接到 数据库引擎Database Engine的实例。In Object Explorer, connect to an instance of 数据库引擎Database Engine.

在标准菜单栏上,单击 “新建查询” 。On the Standard bar, click New Query.

将以下示例复制并粘贴到查询窗口中,然后单击“执行” 。Copy and paste the following example into the query window and click Execute.

USE AdventureWorks2012;

GO

/* Drops and re-creates the IX_Employee_OrganizationLevel_OrganizationNode index on the HumanResources.Employee table with a fill factor of 80.

*/

CREATE INDEX IX_Employee_OrganizationLevel_OrganizationNode ON HumanResources.Employee

(OrganizationLevel, OrganizationNode)

WITH (DROP_EXISTING = ON, FILLFACTOR = 80);

GO

mysql的填充因子_为索引指定填充因子相关推荐

  1. java我的世界填充方块_我的世界填充指令 填充TNT的指令是什么

    我的世界填充指令 填充TNT的指令是什么.在我的世界里面有一些指令是具有填充效果的,那下面游戏园小编就给大家将我的世界填充指令介绍一下吧!还有TNT填充指令又是什么都会一一介绍的,那感兴趣的玩家不妨进 ...

  2. hive能加快MySQL查询速度吗_建立索引可以加快表中数据查询的速度吗

    首先明白为什么索引会增加速度,DB在执行一条Sql语句的时候,默认的方式是根据搜索条件进行全表扫描,遇到匹配条件的就加入搜索结果集合. 如果我们对某一字段增加索引,查询时就会先去索引列表中一次定位到特 ...

  3. 创建mysql制定字符集语句_创建数据库指定字符集语句

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

  4. pandas用众数填充缺失值_数据处理之缺失值填充

    点赞.关注再看,养成良好习惯 Life is short, U need Python 初学Python,快来点我吧 1. 概述 首先对数据缺失的原因.类型以及处理方法做一个简单地总结,如下图所示: ...

  5. 中信所怎么查期刊影响因子_年sci期刊影响因子分区中信所.xls

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp学术论文&nbsp>&nbsp期刊/会议论文 年sci期刊影响因子分区中信所.xls236页 ...

  6. 怎么用python找因子_在python中有大量因子

    将数字乘以顺序, for i in range(1, n + 1): r *= i return r 很快就会产生一个很大的数字(如数万个比特),然后你就会有一个很大的数字和一个小数字的乘法.其中至少 ...

  7. java 填充字符串_如何用Java填充字符串?

    素胚勾勒不出你 从Java 1.5开始,String.format()可用于左/右衬垫给定的字符串.public static String padRight(String s, int n) { r ...

  8. python 条形图填充疏密_如何用箭头填充pyplot条形图的条形图?

    这里有一个解决方案,它使用ax.annotate在每个条内绘制箭头.由于OP不太清楚箭头应该是什么样子,所以我把每个条分成矩形(在代码中我称它们为squares,但如果你确定了绘图的纵横比,它们就只是 ...

  9. mysql中groupby会用到索引吗_开发人员不得不知的MySQL索引和查询优化

    本文主要总结了工作中一些常用的操作及不合理的操作,在对慢查询进行优化时收集的一些有用的资料和信息,本文适合有 MySQL 基础的开发人员. 索引相关 索引基数 基数是数据列所包含的不同值的数量,例如, ...

  10. mysql 左连接 怎么走索引_数据库索引、左连接、右连接、等值连接

    在MySQL中,主要有四种类型的索引,分别为:B-Tree索引,Hash索引,Fulltext索引(MyISAM 表)和R-Tree索引,本文讲的是B-Tree索引. 一.Mysql索引主要有两种结构 ...

最新文章

  1. 网络推广——如何在网站内容优化工作中实现更好的网络推广?
  2. 分享我设计的iOS项目目录结构
  3. Javascript中的arguments数组对象
  4. JAVA写同步栈_tomcat实现的同步队列和同步栈
  5. POJ2718【DFS】
  6. 魅族前副总裁李楠谈“苹果对5G判断”,理解万岁!
  7. this全面解析(二)
  8. js中filter函数
  9. python selenium 打开新窗口
  10. 浅谈一下前后端分离(什么是前后端分离以及前后端分离的原理)
  11. JMX MBean class xxx does not implement DynamicMBean, and neither follows the Standard MBean conventi
  12. Unity学习推荐书籍
  13. jaeger,zipkin,datadog,skywalking等分布式追踪工具
  14. Dubbo---升级Dubbo2.7.13依赖问题
  15. java集合入门和深入学习,看这篇就差不多了
  16. FPGA零基础学习:基于FPGA的音乐蜂鸣器设计(附代码)
  17. bread 块设备读取函数解析(1)
  18. Flutter 弹幕组件hi_barrage封装
  19. 迎风破局·守正创新,2021未来商业生态链接大会暨第六届金陀螺奖颁奖典礼成功举办!...
  20. 整洁架构读书笔记(Clean Architecture)

热门文章

  1. NUC8 i5beh 黑苹果macOS Monterey 12.3.1安装教程
  2. signature=c7580760a679f082e2d4960e4c2c7772,Signatures of moiré-trapped valley excitons in MoSe
  3. 【颜纠日记】如何清除cookie方法,保护你的隐私。
  4. 干货!怎么写满意度调查报告?
  5. VS2019 添加一组控件到工具箱
  6. You can be happy no matter what.
  7. glib使用之哈希表
  8. 《黑匣子思维:我们如何更理性地犯错》ipad部分
  9. 阿里云短信服务接口触发天级流控Permits:10
  10. ROS实践1:publisher详解