久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

包含列的索引,有什么區別?

Indexes with included columns, what#39;s the difference?(包含列的索引,有什么區別?)
本文介紹了包含列的索引,有什么區別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我從來沒有真正理解這兩個索引之間的區別,誰能解釋一下區別是什么(性能方面,索引結構在數據庫中的外觀,存儲方面等)?

I've never really understood the difference between these two indexes, can someone please explain what the difference is (performance-wise, how the index structure will look like in db, storage-wise etc)?

包含索引

CREATE NONCLUSTERED INDEX IX_Address_PostalCode  
ON Person.Address (PostalCode) 
INCLUDE (AddressLine1, AddressLine2, City, StateProvinceID); 

'普通'索引

CREATE NONCLUSTERED INDEX IX_Address_PostalCode  
ON Person.Address (PostalCode, AddressLine1, AddressLine2, City, StateProvinceID);

推薦答案

索引的內部存儲采用 B-Tree 結構,由索引頁"(根頁和所有中間頁)和索引數據頁"(僅葉頁).

The internal storage of indexes uses a B-Tree structure and consists of "index pages" (the root and all intermediate pages) and "index data pages" (the leaf pages only).

注意不要將索引數據頁"與存儲大部分實際數據列的數據頁"(聚集索引的葉頁)混淆.

Note do not confuse "index data pages" with the "data pages" (leaf pages of clustered indexes) which store most of the columns of actual data.

  • 只有索引列存儲在索引頁上.
  • 通過在 INCLUDE 部分放置一些列,每個索引鍵存儲在每個頁面上的數據更少.
  • 意味著需要更少的頁面來保存索引鍵.(更輕松地將這些常用頁面緩存在內存中更長時間.)
  • 樹中的級別可能更少.(在這種情況下,性能優勢會更大,因為每個樹級別遍歷都是另一次磁盤訪問.)
    • Only the index columns are stored on the index pages.
    • By placing some columns in the INCLUDE section, less data per index key is stored on each page.
    • Meaning fewer pages are needed to hold the index keys. (Making it easier to cache these frequently used pages in memory for longer.)
    • And possibly fewer levels in the tree. (In such a case performance benefits can be much bigger because every tree level traversal is another disk access.)
    • 當使用索引時,索引鍵用于通過索引頁導航到正確的索引數據頁.

      When an index is used, the index key is used to navigate through the index pages to the correct index data page.

      • 如果索引具有 INCLUDE 列,則該數據在查詢需要時立即可用.
      • 如果查詢需要在索引鍵或 INCLUDE 列中不可用的列,則需要對聚集索引中的正確行(或堆,如果沒有聚集索引)進行額外的書簽查找"已定義索引).
      • If the index has INCLUDE columns, that data is immediately available should the query need it.
      • If the query requires columns not available in either the index keys or the INCLUDE columns, then an additional "bookmark lookup" is required to the correct row in the clustered index (or heap if no clustered index defined).

      一些注意事項,希望能解決您的一些困惑:

      Some things to note that hopefully addresses some of your confusion:

      • 如果您的索引的鍵和查詢中的過濾器選擇性不夠,那么該索引將被忽略(無論您的 INCLUDE 列中有什么內容).
      • 您創建的每個索引都有 INSERT 和 UPDATE 語句的開銷;對于更大"的索引更是如此.(更大的也適用于 INCLUDE 列.)
      • 因此,雖然理論上您可以創建大量包含列的大索引以匹配訪問路徑的所有排列:這會適得其反.
      • If the keys of your index and filters in your query are not selective enough, then the index will be ignored (regardless of what's in your INCLUDE columns).
      • Every index you create has overhead for INSERT and UPDATE statements; more so for "bigger" indexes. (Bigger applies to INCLUDE columns as well.)
      • So while you could in theory create a multitude of big indexes with include columns to match all the permutations of access paths: it would be very counter-productive.

      值得注意的是,在 INCLUDE 列被添加為一項功能之前:

      It's worth noting that before INCLUDE columns were added as a feature:

      • 擴展索引的鍵以包含索引/過濾器中不需要的列是一種常見的索引調整技巧".(稱為覆蓋索引.)
      • 這些列通常在輸出列中需要,或者作為連接到其他表的參考列.
      • 這將避免臭名昭著的書簽查找",但缺點是使索引比嚴格需要的更寬".
      • 事實上,索引中較早的列通常已經確定了唯一行,這意味著如果不是為了避免書簽查找",額外包含的列將是完全多余的" 好處.
      • INCLUDE 列基本上可以更有效地獲得相同的好處.
      • It was a common index tuning 'trick' to expand the keys of an index to include columns that weren't needed in the index/filter. (Known as a covering index.)
      • These columns were commonly required in output columns or as reference columns for joins to other tables.
      • This would avoid the infamous "bookmark lookups", but had the disadvantage of making the index 'wider' than strictly necessary.
      • In fact very often the earlier columns in the index would already identify a unique row meaning the extra included columns would be completely redundant if not for the "avoiding bookmark lookups" benefit.
      • INCLUDE columns basically allow the same benefit more efficiently.

      注意 需要指出的一點很重要.如果您養成總是將查詢編寫為 SELECT * ... 的懶惰習慣,那么您通常從索引中的 INCLUDE 列中獲得零收益.通過返回所有列,您基本上可以確保在任何情況下都需要進行書簽查找.

      NB Something very important to point out. You generally get zero benefit out of INCLUDE columns in your indexes if you're in the lazy habit of always writing your queries as SELECT * .... By returning all columns you're basically ensuring a bookmark lookup is required in any case.

      這篇關于包含列的索引,有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

SQL trigger on Truncate(截斷時的 SQL 觸發器)
sql search query with multiple optional search parameters(具有多個可選搜索參數的 sql 搜索查詢)
SQL Efficiency: WHERE IN Subquery vs. JOIN then GROUP(SQL 效率:WHERE IN 子查詢 vs. JOIN 然后 GROUP)
Retrieving XML element name using t-SQL(使用 t-SQL 檢索 XML 元素名稱)
Insert double quotes into SQL output(在 SQL 輸出中插入雙引號)
Delete rows from CTE in SQL SERVER(從 SQL SERVER 中的 CTE 中刪除行)
主站蜘蛛池模板: 操操操操操 | 中文字幕一区二区三区日韩精品 | 91免费在线 | 国产成人在线一区二区 | 久久久www成人免费精品张筱雨 | 国产精品欧美精品 | 91污在线| 日韩精品区 | 一道本一区二区 | 青青久久 | 国产综合欧美 | 成人免费福利视频 | 日韩在线一区二区三区 | 自拍视频一区二区三区 | 好好的日在线视频 | 三区四区在线观看 | 久久久久久亚洲 | 日韩日韩日韩日韩日韩日韩日韩 | 中文字幕一区二区三区在线观看 | 日韩一级| 狠狠色狠狠色综合系列 | 国产黄视频在线播放 | 日日摸天天添天天添破 | 精品国产一区二区三区av片 | 2022国产精品| 黄毛片| 久久精品国产一区二区电影 | 日韩中出 | 午夜小电影 | 成人欧美一区二区三区黑人孕妇 | 久久久久免费精品国产小说色大师 | 日韩一区二区在线视频 | 亚洲国产成人久久综合一区,久久久国产99 | 国产精品久久久久久久久免费相片 | av免费网站在线观看 | 中文字幕免费中文 | aaa在线| 涩涩视频在线看 | 中文字幕在线二区 | 在线观看国产视频 | 亚洲一区在线日韩在线深爱 |