Maintenance Plan Usage3:Task Usage (Maintain Index)

Maintenance Plan用于维护Index Fragmentation 和 Statistics的Task 共有三个,后台是使用相应的TSQL来进行data维护。

Reorganize Index Task

Move index pages into a more efficient search order. This task uses the ALTER INDEX REORGANIZE statement with SQL Server 2012 databases.

Rebuild Index Task

Re-create the indexes on the tables in the database with a new fill factor. The fill factor determines the amount of empty space on each page in the index, to accommodate future expansion. As data is added to the table, the free space fills because the fill factor is not maintained. Reorganizing data and index pages can re-establish the free space. The Rebuild Index Task uses the ALTER INDEX statement.

Update Statistics Task

Update Microsoft SQL Server information about the data in the tables and indexes. This task resamples the distribution statistics of each index created on user tables in the database. The distribution statistics are used by SQL Server to optimize navigation through tables during the processing of Transact-SQL statements. To build the distribution statistics automatically, SQL Server periodically samples the data in the corresponding table for each index. This size of the sample is based on the number of rows in the table and the frequency of data modification. Use this option to perform an additional sampling using the specified percentage of data in the tables. SQL Server uses this information to create better query plans. This task executes the UPDATE STATISTICS statement.

一,Rebuild Index Task

1,Change free space per page percentage to :设置Index每个Leaf-level page的空闲空间。

Drop the indexes on the tables in the database and re-create them with a new, automatically calculated fill factor, thereby reserving the specified amount of free space on the index pages. The higher the percentage, the more free space is reserved on the index pages, and the larger the index grows. Valid values are from 0 through 100.

2,Sort results in tempdb

Use the SORT_IN_TEMPDB option, which determines where the intermediate sort results, generated during index creation, are temporarily stored. If a sort operation is not required, or if the sort can be performed in memory, the SORT_IN_TEMPDBoption is ignored.

The intermediate sort results that are used to build the index are stored in tempdb. If tempdb is on a different set of disks than the user database, this may reduce the time needed to create an index. However, this increases the amount of disk space that is used during the index build.

3,Keep index online while reindexing

Use the ONLINE option which allows users to access the underlying table or clustered index data and any associated nonclustered indexes during index operations.

Online clause Specifies whether underlying tables and associated indexes are available for queries and data modification during the index operation. The default is OFF.

4,Other Rebuild index options

在Rebuild Index Task GUI中无法配置的Index Option 有5个。选项 PAD_INDEX,ALLOW_ROW_LOCKS ,ALLOW_PAGE_LOCKS 使用sys.indexes存储的metadata;Rebuild Index Task使用create index的配置值来设置选项 Data_Compression,STATISTICS_NORECOMPUTE。

View T-SQL 查看后台的TSQL 脚本,示例Sql 脚本

ALTER INDEX [IndexName]
ON SchemeName.TableName
REBUILD
PARTITION = ALL
WITH
(
PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB = OFF, O
NLINE = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON,
FILLFACTOR = 95
)

如果在创建Index时,指定 DATA_COMPRESSION 选项,那么Rebuild Index Task 会使用Create Index的DATA_COMPRESSION 选项设置来生成Rebuild Index的TSQL code。

二,Reorganize Index Task

Compact large objects

Deallocate space for tables and views when possible. This option uses ALTER INDEX LOB_COMPACTION = ON. This is only available for SQL Server 2005 databases.

View T-SQL 查看后台的TSQL 脚本,示例Sql 脚本

ALTER INDEX [index_name]
ON SchemeName.TableName
REORGANIZE
WITH ( LOB_COMPACTION = ON )

WITH ( LOB_COMPACTION = { ON | OFF } )

Specifies that all pages that contain large object (LOB) data are compacted. The LOB data types are image, text, ntext, varchar(max), nvarchar(max), varbinary(max), and xml. Compacting this data can improve disk space use. The default is ON.

ON                  

All pages that contain large object data are compacted.

Reorganizing a specified clustered index compacts all LOB columns that are contained in the clustered index. Reorganizing a nonclustered index compacts all LOB columns that are nonkey (included) columns in the index.

When ALL is specified, all indexes that are associated with the specified table or view are reorganized, and all LOB columns that are associated with the clustered index, underlying table, or nonclustered index with included columns are compacted.

OFF                  

Pages that contain large object data are not compacted.

OFF has no effect on a heap.

The LOB_COMPACTION clause is ignored if LOB columns are not present.

三,Update Statistics Task

View T-SQL 查看后台的TSQL 脚本,示例Sql 脚本

UPDATE STATISTICS
SchemeName.TableName
WITH FULLSCAN,COLUMNS

参考文档:

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

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

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

时间: 2024-08-05 21:46:22

Maintenance Plan Usage3:Task Usage (Maintain Index)的相关文章

Maintenance Plan Usage2:Task Usage (Cleanup)

Maintenance Plan 共有两个Cleanup的Task,Maintenance Cleanup Task 和 History Cleanup Task,这两个Task都能根据File Age 和Info Age 来删除早于一定时间的files. 1,Maintenance Cleanup Task 用于删除Maintenance Plan产生的Report files 和 backup files. Remove old files related to maintenance pl

Maintenance Plan Usage4:Check Integrity and Shrink database

一,Check Database Integrity Task check the allocation and structural integrity of user and system tables, and indexes in the database, by running the DBCC CHECKDB Transact-SQL statement. Running DBCC ensures that any integrity problems with the databa

Spark源码分析之八:Task运行(二)

在<Spark源码分析之七:Task运行(一)>一文中,我们详细叙述了Task运行的整体流程,最终Task被传输到Executor上,启动一个对应的TaskRunner线程,并且在线程池中被调度执行.继而,我们对TaskRunner的run()方法进行了详细的分析,总结出了其内Task执行的三个主要步骤: Step1:Task及其运行时需要的辅助对象构造,主要包括: 1.当前线程设置上下文类加载器: 2.获取序列化器ser: 3.更新任务状态TaskState: 4.计算垃圾回收时间: 5.反

Spark源码分析之六:Task调度(二)

话说在<Spark源码分析之五:Task调度(一)>一文中,我们对Task调度分析到了DriverEndpoint的makeOffers()方法.这个方法针对接收到的ReviveOffers事件进行处理.代码如下: [java] view plain copy // Make fake resource offers on all executors // 在所有的executors上提供假的资源(抽象的资源,也就是资源的对象信息,我是这么理解的) private def makeOffers

Spark源码分析之七:Task运行(一)

在Task调度相关的两篇文章<Spark源码分析之五:Task调度(一)>与<Spark源码分析之六:Task调度(二)>中,我们大致了解了Task调度相关的主要逻辑,并且在Task调度逻辑的最后,CoarseGrainedSchedulerBackend的内部类DriverEndpoint中的makeOffers()方法的最后,我们通过调用TaskSchedulerImpl的resourceOffers()方法,得到了TaskDescription序列的序列Seq[Seq[Tas

Spark源代码分析之六:Task调度(二)

话说在<Spark源代码分析之五:Task调度(一)>一文中,我们对Task调度分析到了DriverEndpoint的makeOffers()方法.这种方法针对接收到的ReviveOffers事件进行处理.代码例如以下: // Make fake resource offers on all executors     // 在全部的executors上提供假的资源(抽象的资源.也就是资源的对象信息,我是这么理解的)     private def makeOffers() {       /

sp_configure命令开启组件Agent XPs,数据库计划(Maintenance Plan)

新建“计划(Maintenance Plan)”时,记得执行计划需把SQL的“代理服务(SQL Server Agent)”也开启 出现对话框:“SQL Server 阻止了对组件 'Agent XPs' 的 过程 'dbo.sp_set_sqlagent_properties' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭.SQL Server 阻止了对组件 'Agent XPs' 的 过程 'dbo.sp_set_sqlagent_properties' 的访问,因为此组件已作为

转:Task任务调度实现生产者消费者模式

我们经常会遇到生产者消费者模式,比如前端各种UI操作事件触发后台逻辑等.在这种典型的应用场景中,我们可能会有4个业务处理逻辑(下文以P代表生产者,C代表消费者): 1. FIFO(先进先出)      P产生1,2,3,4,5,6,3,2      C处理顺序应为1,2,3,4,5,6,3,2 2.LIFO(后进先出)      P产生1,2,3,4,5,6,3,2      C处理顺序应为2,3,6,5,4,3,2,1 3.Dynamic FIFO(我定义为:去掉相同数据的FIFO, 如果产生

编写高质量代码改善C#程序的157个建议——建议85:Task中的异常处理

建议85:Task中的异常处理 在任何时候,异常处理都是非常重要的一个环节.多线程与并行编程中尤其是这样.如果不处理这些后台任务中的异常,应用程序将会莫名其妙的退出.处理那些不是主线程(如果是窗体程序,那就是UI主线程)产生的异常,最终的办法都是将其包装到主线程上. 在任务并行库中,如果对任务运行Wait.WaitAny.WaitAll等方法,或者求Result属性,都能捕获到AggregateException异常.可以将AggregateException异常看做是任务并行库编程中最上层的异