SQL Server 2008读书笔记(4):设计SQL Server索引

Lesson 1: Index Architecture

Quick Check
1. What type of structure does SQL Server use to construct an index?
2. What are the three types of pages within an index?
Quick Check Answers
1. SQL Server uses a B-tree structure for indexes.
2. An index can contain root, intermediate, and leaf pages. An index has a single
root page defi ned at the top of the index structure. An index can have one or
more levels of intermediate pages, but it is optional. The leaf pages are the
lowest-level page within an index.

Lesson Summary
? SQL Server creates an index using a B-tree structure .
? Each index has a single root-level page and if all the entries do not fi t on a single page,
the index can create pages at intermediate and leaf levels.

Lesson 2: Designing Indexes

CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON <object> ( column [ ASC | DESC ] [ ,...n ] )
[ INCLUDE ( column_name [ ,...n ] ) ]
[ WHERE <filter_predicate> ]
[ WITH ( <relational_index_option> [ ,...n ] ) ]
[ ON { partition_scheme_name ( column_name ) | filegroup_name | default } ]
[ FILESTREAM_ON { filestream_filegroup_name | partition_scheme_name | "NULL" } ][ ;
]
CREATE [ PRIMARY ] XML INDEX index_name
ON <object> ( xml_column_name )
[ USING XML INDEX xml_index_name
[ FOR { VALUE | PATH | PROPERTY } ] ]
[ WITH ( <xml_index_option> [ ,...n ] ) ][ ; ]
CREATE SPATIAL INDEX index_name
ON <object> ( spatial_column_name )
{[ USING <geometry_grid_tessellation> ]
WITH ( <bounding_box>
[ [,] <tessellation_parameters> [ ,...n ] ]
[ [,] <spatial_index_option> [ ,...n ] ] )
| [ USING <geography_grid_tessellation> ]
[ WITH ( [ <tessellation_parameters> [ ,...n ] ]
[ [,] <spatial_index_option> [ ,...n ] ] ) ]
} [ ON { filegroup_name | "default" } ];

Quick Check
1. What is the difference between a clustered and a nonclustered index?
2. How does the FILLFACTOR option affect the way an index is built?

Quick Check Answers
1. A clustered index imposes a sort order on the data pages in the table. A nonclustered index does not impose a sort order.
2. The FILLFACTOR option reserves space on the intermediate and leaf levels of the index.

CREATE NONCLUSTERED INDEX idx_city ON Person.Address(City) INCLUDE (AddressLine1)
CREATE NONCLUSTERED INDEX idx_city2 ON Person.Address(City)
INCLUDE (AddressLine1, AddressLine2)
WHERE AddressLine2 IS NOT NULL
CREATE SPATIAL INDEX sidx_spatiallocation
ON Person.Address(SpatialLocation)
USING GEOGRAPHY_GRID
WITH (GRIDS = (MEDIUM, LOW, MEDIUM, HIGH ),
CELLS_PER_OBJECT = 64)

Lesson Summary
? Clustered indexes specify a sort order for data pages in a table.
? You can create up to 1,000 nonclustered indexes on a table.
? Nonclustered indexes can include columns in the leaf level of the index to cover more
queries.
? You can specify a WHERE clause for a nonclustered index to limit the data set that the
index is built upon.
? You can create three different types of XML indexes; PATH, VALUE, and PROPERTY.
? Spatial indexes can be defi ned for either geography or geometry data types.
? If you are indexing a geometry data type, the BOUNDING_BOX parameter is required
to provide limits to the two-dimensional plane.

Lesson 3: Maintaining Indexes
The FILLFACTOR option for an index determines the percentage of free space that is reserved
on each leaf-level page of the index when an index is created or rebuilt.

ALTER INDEX { index_name | ALL }
ON <object>
{ REBUILD
[ [ WITH ( <rebuild_index_option> [ ,...n ] ) ]
| [ PARTITION = partition_number
[ WITH ( <single_partition_rebuild_index_option>
[ ,...n ] )] ] ]
| DISABLE | REORGANIZE
[ PARTITION = partition_number ]
[ WITH ( LOB_COMPACTION = { ON | OFF } ) ]
| SET ( <set_index_option> [ ,...n ] ) }[ ; ]
ALTER INDEX { index_name | ALL }
ON <object>
DISABLE [ ; ]
ALTER INDEX { index_name | ALL }
ON <object>
REBUILD [ ; ]

 

Quick Check
1. What is the difference between the REBUILD and REORGANIZE options of ALTER
2. What happens when an index is disabled?

Quick Check Answers
1. REBUILD defragments all levels of an index. REORGANIZE defragments only the
leaf level of the index.
2. An index that is disabled is no longer used by the optimizer. In addition, as data
changes in the table, any disabled index is not maintained.

ALTER INDEX ALL
ON Person.Address
REBUILD

ALTER INDEX IX_Person_LastName_FirstName_MiddleName
ON Person.Person
REORGANIZE

ALTER INDEX PK_Address_AddressID
ON Person.Address
DISABLE

SELECT * FROM Person.Address

ALTER INDEX PK_Address_AddressID
ON Person.Address
REBUILD

SELECT * FROM Person.Address

Lesson Summary
? You can defragment indexes using either the REBUILD or REORGANIZE options.
? The REBUILD option defragments all levels of an index. Unless the ONLINE option is
specifi ed, a REBUILD acquires a shared table lock and block any data modifi cations.
? The REORGANIZE option defragments only the leaf level of an index and does not
cause blocking.
? You can disable an index to exclude the index from consideration by the optimizer
or any index maintenance due to data changes. If the clustered index is disabled, the
entire table becomes inaccessible.

转载于:https://www.cnblogs.com/thlzhf/archive/2013/01/30/2883406.html

【事件触发一致性】研究多智能体网络如何通过分布式事件驱动控制实现有限时间内的共识(Matlab代码实现)内容概要:本文围绕多智能体网络中的事件触发一致性问题,研究如何通过分布式事件驱动控制实现有限时间内的共识,并提供了相应的Matlab代码实现方案。文中探讨了事件触发机制在降低通信负担、提升系统效率方面的优势,重点分析了多智能体系统在有限时间收敛的一致性控制策略,涉及系统模型构建、触发条件设计、稳定性与收敛性分析等核心技术环节。此外,文档还展示了该技术在航空航天、电力系统、机器人协同、无人机编队等多个前沿领域的潜在应用,体现了其跨学科的研究价值和工程实用性。; 适合人群:具备一定控制理论基础和Matlab编程能力的研究生、科研人员及从事自动化、智能系统、多智能体协同控制等相关领域的工程技术人员。; 使用场景及目标:①用于理解和实现多智能体系统在有限时间内达成一致的分布式控制方法;②为事件触发控制、分布式优化、协同控制等课题提供算法设计与仿真验证的技术参考;③支撑科研项目开发、学术论文复现及工程原型系统搭建; 阅读建议:建议结合文中提供的Matlab代码进行实践操作,重点关注事件触发条件的设计逻辑与系统收敛性证明之间的关系,同时可延伸至其他应用场景进行二次开发与性能优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值