您的位置:首页 > 其它

hobt_id 和 partition_ID 理解

2015-12-03 14:43 531 查看
查找一些资料,总结:这两个字段的值是相同的。

1,HOBT_ID refers to Heap or B-Tree ID. As you know, data in tables is stored as HEAP or a B-Tree (Balanced tree); If there is a clustered index on the table, it is stored as a B-Tree, if not it’s a HEAP. Either way, they are stored in data pages that are all put together and referred to as one logical location. This logical location of data pages (or index pages) are referred using an ID called hobt_id. In essence, its just an ID used to refer to that logical storage.

When a table is partitioned, each partition will get a partition_ID and HOBT_ID, but when a table is not partition, it still has partition ID and HOBT_ID as it is referred to as a single partition table.

2,There is 2 columns in sys.partitions view - partition_id and hobt_id. From my point of view/experience for any given row from this view partition_id always equal hobt_id and I never see the 2 different values. It's seems reasonable, because (simplifying complex thing) we can say: "partition is hobt, hobt is partition". But at the same time article about another view - sys.allocation_units tell us:

If type = 1 or 3, container_id = sys.partitions.hobt_id.

If type is 2, then container_id = sys.partitions.partition_id.

So - these 2 values can ever be NOT equal?? As I said I had never see this in practical. Can you please give the example of table (and DB, if it needs), for which partition_id and hobt_id will be NOT equal?

They're the same thing. They were added as separate columns to support a feature that was planned, partially added to SQL 2005 and later scrapped.

3, HOBT is short for a Heap Or B-Tree. In SQL Server, a table without a clustered index is called a heap. A table with a clustered index is called….a table with a clustered index.Table With A Clustered Index isn’t very cool sounding. Fortunately for us, clustered indexes are implemented in SQL Server as B-Trees .

Now technically, a HOBT isn’t always representative of the entire Heap Or B-Tree. It’s actually the subset of a table that lies on a given partition. So if you have a table split across five partitions, you have five HOBT’s in the table.

You’ll see HOBTs referenced throughout SQL Server documentation and literature, and within SQL Server itself. For example, the hobt_id in sys.partitions is a direct reference to the same HOBT we’re discussing here. You’ll notice that the hobt_id is the same as the partition_id if you query sys.partitions. There is currently a 1:1 relationship between HOBTs and partitions, although the fact that they’re tracked out as separate identifiers might lead one to believe that this could very well change in the future.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: