SQL Server - Bài 11

31 491 0
SQL Server - Bài  11

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

SQL Server - Bài

Planning and Creating IndexVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftOutlineIntroduction to IndexesUnderstanding Index ArchitectureRetrieving Stored Data with SQL ServerDefining IndexesCreating Indexes Maintaining Index2 MicrosoftMicrosoftIndexData storageRows are stored in data pagesHeaps are a collection of data pages for a tableData accessScanning all data pages in a tableUsing an index that points to data on a pageData PagesPage 7 Page 8 Page 9AkhtarFunkSmithMartin .Page 4 Page 5 Page 6 .ConFunkWhite RuddWhiteBarr SmithOtaJones MartinPhuaJonesSmith .GanioJonesHall . MicrosoftMicrosoftCreating Index or not ?Creating indexSpeeds up data accessEnforces uniqueness of rowsDonot creating indexConsumes disk spaceIncurs overheadPrimary and foreign keysFrequently searched in rangesFrequently accessed in sorted orderSeldom referenced in queriesContaining few unique valuesDefined with bit, text, or image data types MicrosoftMicrosoftIndex ArchitectureHow SQL Server Uses IndexesMaintaining HeapsUsing Clustered IndexesUsing Nonclustered IndexesAccessing a Range of Data in a HeapAccessing a Range of Data with Clustering Keys MicrosoftMicrosoftHow SQL Server Uses Indexes1. Determining if index exists on an appropriate column for the query2. If an index does not existScanning each data page of the table.3. If an index exists, Determining whether that index is useful for retrieving the desired data. 3.1 If the index is useful, SQL Server then uses it to access the rows in the table3.2 If the index is not user full databaseScanning each data page in table MicrosoftMicrosoftMaintaining Heaps Using index allocation map pagesContaining information on where the extents of a heap are storedNavigating through the heap and find available space for new rows being insertedConnecting data pagesReclaiming space for new rows in the heap when a row is deleted MicrosoftMicrosoftUsing Clustered IndexesEach table can have only one clustered indexThe physical row order of the table and the order of rows in the index are the sameKey value uniqueness is maintained explicitly or implicitly MicrosoftMicrosoftUsing Non-clustered IndexesNon-clustered indexes are the SQL server defaultExisting non-clustered indexes are automatically rebuilt when:An existing clustered index is droppedA clustered index is createdThe DROP_EXISTING option is used to change which columns define the clustered index MicrosoftMicrosoftAccessing a Range of Data in a HeapData PagesPage 7 Page 8 Page 9AkhtarFunkSmithMartin 470601470602470603470604 .Page 4 Page 5 Page 6 ConFunkWhite .470401470402470403 RuddWhiteBarr .470501470502470503 SmithOtaJones .470701470702470703 MartinPhuaJonesSmith 470801470802470803470804 .GanioJonesHall .470901470902470904 Index PagesNon-leafLevelPage 12 - RootPage 37 Page 28Leaf Level(Key Value)Page 41 Page 51 Page 61 Page 71 Akhtar .MartinAkhtarBarrConFunkFunk470601470503470401470602470402MartinMartinOtaPhuaRudd470801470604470702470802470501MartinSmith .SmithSmithSmithWhiteWhite470603470804470701470403470502AkhtarGanio .GanioHallJonesJonesJones470901470904470902470803470703SELECT lastname, firstanmeFROM memberWHERE lastnameBETWEEN 'Martin' AND 'Rudd'Data PagesPage 7 Page 8 Page 9AkhtarFunkSmithMartin 470601470602470603470604 .Page 4 Page 5 Page 6 ConFunkWhite .470401470402470403 RuddWhiteBarr .470501470502470503 SmithOtaJones .470701470702470703 MartinPhuaJonesSmith 470801470802470803470804 .GanioJonesHall .470901470902470904 Index PagesNon-LeafLevelPage 12 - RootPage 37 Page 28Leaf Level(Key Value)Page 41 Page 51 Page 61 Page 71 Akhtar .MartinAkhtarBarrConFunkFunk470601470503470401470602470402MartinMartinOtaPhuaRudd470801470604470702470802470501MartinSmith .SmithSmithSmithWhiteWhite470603470804470701470403470502AkhtarGanio .GanioHallJonesJonesJones470901470904470902470803470703MartinMartinMartinMartinMartinMartin470801470801MartinMartin470604470604OtaOta470702470702PhuaPhua470802470802RuddRudd470501470501MartinMartin 470801470801PhuaPhua 470802470802OtaOta 470702470702MartinMartin 470604470604RuddRudd 470501470501 [...]... title_no 5 10 4 35 35 35 Column 1 Composite Key Microsoft Column 2 member_no 3744 5278 3445 out_date 199 8-0 1-0 6 199 8-0 1-0 4 199 8-0 1-0 4 Creating Index Option   Using the FILLFACTOR option Using the PAD_INDEX option Microsoft Using the FILLFACTOR Option   Specifies how much to fill the page Impacts leaf-level pages Data Pages Full Con 470401 Funk 470402 White 470403 Rudd 470501 White 70502 4 Barr... 1634White9355 2634 Jones6002 6078 Rudd 8078 Hall Clustered Index Page 141 Akhtar Ganio Microsoft Non-Leaf Non-leaf Level 2334 Akhtar 5678 Barr Barr 2534 Con 1334 Funk 1534 Funk 4705 Page 100 Akhtar Martin Page 140 - Root 7678Ganio 8078 Hall 2434Jones 5978Jones 5788 5788 2634Jones 6002 Page 110 Page 145 Martin Smith 1234 Martin 7778 Martin 7206 5878 Ota Ota 7878 Phua 6078 Rudd ... library CREATE UNIQUE INDEX title_ident ON title (title_no) title title_no title author synopsis 10 11 12 The Night-Born Lemon Walking Jack London ~~~ Motojirou ~~~ Henry David Thoreau ~ ~ ~ Duplicate key values are not allowed when a new row is added to the table 12 Microsoft Le Petit Prince Antoine de Saint-Exupery ~~~ Creating Composite Indexes USE library CREATE UNIQUE INDEX loan_ident ON loan (isbn,... Barr 470503 Smith 470603 Ota 470702 Jones 470803 White 470902 Microsoft Using the PAD_INDEX Option    Specifies percentage to which to fill index page Must use with FILLFACTOR option Impact Non-Leaf-Level Index pages Microsoft Obtaining Information on Existing Indexes  Using the sp_helpindex system stored procedure  Using the sp_help tablename system stored procedure USE library EXEC sp_helpindex... fragmentation Index tuning wizard DBCC SHOWCONTIG Statement DROP_EXISTING Option Statistical information Index analysis Microsoft Data Fragmentation  How fragmentation occurs    Managing fragmentation    SQL Server reorganizes index pages when data is modified Reorganization causes index pages to split Dropping and recreating an index and specifying a fillactor value Rebuild an index and specify a fillfactor...Accessing a Range of Data in Clustering Key 1234 5678 Page 12 - Root Index Pages Page 37 Page 28 1234 5678 2234 7678 SELECT lastname, firstanme Page 41 FROM member Page 51 Page 61 Page 71 Leaf Level 2234 White 5678 Barr 7678 Ganio 1234 Martin WHERE 2334 Akhtar . copy_no title_no member_no3423423435104353535374452783445out_date199 8-0 1-0 6199 8-0 1-0 4199 8-0 1-0 4 MicrosoftMicrosoftCreating Index OptionUsing the FILLFACTOR. implicitly MicrosoftMicrosoftUsing Non-clustered IndexesNon-clustered indexes are the SQL server defaultExisting non-clustered indexes are automatically

Ngày đăng: 15/11/2012, 10:59

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan