Click here to load reader

ايندکس ها مباحث اين جلسه B-Tree ها ، Page ها و Extent ها مفهوم Page Split و پيشگيري از آن ايجاد ، استفاده و تغيير انواع

  • View
    231

  • Download
    0

Embed Size (px)

Text of ايندکس ها مباحث اين جلسه B-Tree ها ، Page ها و Extent ها مفهوم Page...

  • B-Tree Page Extent Page Split XML Index

  • NON-CLUSTERED INDEX On a Heap

  • NON-CLUSTERED INDEX On a CLUSTERED INDEX

  • OLTP (Online Transaction Processing)OLAP (Online Analytical Processing)

  • CREATE [UNIQUE] [CLUSTERED|NONCLUSTERED]INDEX ON ( [ASC|DESC] [,...n])INCLUDE ( [, ...n]) [WITH[PAD_INDEX = { ON | OFF }][[,] FILLFACTOR = ][[,] IGNORE_DUP_KEY = { ON | OFF }][[,] DROP_EXISTING = { ON | OFF }][[,] STATISTICS_NORECOMPUTE = { ON | OFF }][[,] SORT_IN_TEMPDB = { ON | OFF }][[,] ONLINE = { ON | OFF }[[,] ALLOW_ROW_LOCKS = { ON | OFF }[[,] ALLOW_PAGE_LOCKS = { ON | OFF }[[,] MAXDOP = ][ON { | | DEFAULT }]

  • NONCLUSTERED INDEX CREATE TABLE MyTableKeyExample(Column1 int IDENTITYPRIMARY KEY NONCLUSTERED,Column2 int)

  • XML IndexesThe table containing the XML you want to index must have a clustered index on it.A primary XML index must exist on the XML data column before you can create secondary indexesXML indexes can be created only on columns of XML type (and an XML index is the only kind of index you can create on columns of that type).The XML column must be part of a base table you cannot create the index on a view.

  • XML INDEX USE [databaseName] GOSET ARITHABORT ON GOSET CONCAT_NULL_YIELDS_NULL ON GOSET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOSET ANSI_PADDING ON GOSET NUMERIC_ROUNDABORT OFF GO

  • XML INDEX CREATE PRIMARY XML INDEX [test] ON [dbo].[test] ([xmldata] )WITH (PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100)GO

  • ALTER INDEX PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailIDON Sales.SalesOrderDetailREBUILD WITH (FILLFACTOR = 100)

  • ALTER INDEX { | ALL }ON { REBUILD[ [ WITH ([ PAD_INDEX = { ON | OFF } ]| [[,] FILLFACTOR = | [[,] SORT_IN_TEMPDB = { ON | OFF } ]| [[,] IGNORE_DUP_KEY = { ON | OFF } ]| [[,] STATISTICS_NORECOMPUTE = { ON | OFF } ]| [[,] ONLINE = { ON | OFF } ]| [[,] ALLOW_ROW_LOCKS = { ON | OFF } ]| [[,] ALLOW_PAGE_LOCKS = { ON | OFF } ]| [[,] MAXDOP = ) ]

  • | [ PARTITION = [ WITH ( [ ,...n ] ) ] ] ]| DISABLE| REORGANIZE[ PARTITION = ][ WITH ( LOB_COMPACTION = { ON | OFF } ) ]| SET ([ ALLOW_ROW_LOCKS= { ON | OFF } ]| [[,] ALLOW_PAGE_LOCKS = { ON | OFF } ]| [[,] IGNORE_DUP_KEY = { ON | OFF } ]| [[,] STATISTICS_NORECOMPUTE = { ON | OFF } ])} [ ; ]

  • DBCC SHOWCONTIG ([table name], [index name])Pages ScannedExtents ScannedExtent SwitchesAvg. Pages per ExtentScan Density [Best Count: Actual Count]Logical Scan FragmentationExtent Scan FragmentationAvg. Bytes Free per PageAvg. Page Density

  • DBCC DBREINDEX(db.owner.table[,index name[,fill factor]]))DBCC DBREINDEX(OrderDetails,indexName,65]]))

  • Use Indexes (either CI or NCI) in Foreign KeysRange Selects (BETWEEN, ,Aggregate, Sortes) Clustered IndexesHigh Selectivity NON-CLUSTERED IndexesIncrease Index Count Decrease Data Altering InstructionsClustered Indexes decrease Alter Instructions SpeedSo Always Keep Balance in Using Indexes

  • INDEX DECLARE @db_id SMALLINT;DECLARE @object_id INT;SET @db_id = DB_ID(N'AdventureWorks2008');SET @object_id = OBJECT_ID ( N'AdventureWorks2008.Sales.SalesOrderDetail');SELECT database_id, object_id, index_id, index_depth, avg_fragmentation_in_percent, page_countFROM sys.dm_db_index_physical_stats(@db_id,@object_id,NULL,NULL,NULL);

  • **