創(chuàng)建、查看分區(qū)表的Metadata

今天小編給大家分享的是創(chuàng)建、查看分區(qū)表的Metadata的詳細介紹,相信大部分人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,話不多說,一起往下看吧。    

網(wǎng)站制作、成都網(wǎng)站設計服務團隊是一支充滿著熱情的團隊,執(zhí)著、敏銳、追求更好,是創(chuàng)新互聯(lián)的標準與要求,同時竭誠為客戶提供服務是我們的理念。成都創(chuàng)新互聯(lián)公司把每個網(wǎng)站當做一個產(chǎn)品來開發(fā),精雕細琢,追求一名工匠心中的細致,我們更用心!

未分區(qū)的表,只能存儲在一個FileGroup中;對table進行分區(qū)后,每一個分區(qū)都存儲在一個FileGroup中。表分區(qū)是將邏輯上一個完整的表,按照特定的字段拆分成Partition set,分散到(相同或不同的)FileGroup中,每一個Partition在FileGroup中都獨立存儲,每一個parititon都屬于唯一的表對象,每一個Partition 都有唯一的ID。

 

在創(chuàng)建表時,使用On 子句指定table存儲的邏輯位置:

On  filegroup | "default" 表示邏輯存儲位置是單一的FileGroup;

ON  partition_scheme_name ( partition_column_name ) 表示邏輯存儲位置是多個FileGroup,按照partition_column_name將table拆分成多個partition,每一個partition都存儲在一個指定的Filegroup中。

CREATE TABLE  [schema_name . ] table_name 
(  <column_definition>  )[ ON { partition_scheme_name ( partition_column_name ) | filegroup | "default" } ] 
[ WITH ( <table_option> [ ,...n ] ) ][ ; ]

 

Partition的含義就是table的一部分邏輯存儲空間。

跟邏輯存儲空間相對應的是物理存儲空間,物理存儲空間是由File指定的,F(xiàn)ileGroup是File的集合,每一個File都屬于唯一的FileGroup。將table的存儲空間拆分到不同的FileGroup中,邏輯上是將table的存儲管理體系增加了一層 Partition,介于Table和FileGroup中間,Table的數(shù)據(jù)存儲在Partition,Partition存儲在FileGroup中,F(xiàn)ileGroup管理著File,F(xiàn)ile是實際存儲data的物理文件。

 

table為什么要增加Parition?因為FileGroup是所有的Table共享,Partition是由一個table獨占,每一個Partition都唯一屬于一個table。這樣,對某個parititon進行操作,而不影響table的其他parition,也不會影響其他table。

 

一:創(chuàng)建分區(qū)表的步驟

Step1, 創(chuàng)建分區(qū)函數(shù)

分區(qū)函數(shù)的作用是提供分區(qū)字段的類型和分區(qū)的邊界值

CREATE PARTITION FUNCTION [pf_int](int) 
AS RANGE LEFT FOR VALUES (10, 20)


pf_int 的含義是按照int類型分區(qū),分區(qū)的邊界值是10,20,left表示邊界值屬于左邊界。兩個邊界值能夠分成三個分區(qū),別是(-infinite,10],(10,20],(20,+infinite)。

Step2,創(chuàng)建分區(qū)scheme

分區(qū)scheme的作用是為Parition分配FileGroup,Partition Scheme和FileGroup在邏輯上等價,都是數(shù)據(jù)存儲的邏輯空間,只不過Partition Scheme指定的是多個FileGroup。

CREATE PARTITION SCHEME [ps_int] AS PARTITION [pf_int] TO ([PRIMARY], [db_fg1], [db_fg1])


不管是在不同的FileGroup中,還是在相同的FileGroup中,分區(qū)都是獨立存儲的。

 

Step3,創(chuàng)建分區(qū)表

創(chuàng)建分區(qū)表,實際上是使用on子句指定table存儲的邏輯位置。

創(chuàng)建、查看分區(qū)表的Metadata

create table dbo.dt_test
(
    ID int,
    code int)on [ps_int] (id)

創(chuàng)建、查看分區(qū)表的Metadata


二,查看Partition的Metadata

1, 查看partition function

select *from sys.partition_functions

創(chuàng)建、查看分區(qū)表的Metadata

 

查看partition function定義的邊界值

select * from sys.partition_range_values

創(chuàng)建、查看分區(qū)表的Metadata

 

查看partition function 定義的parmeter,這個Parmeter是一個data type,system_type_id標識該data type。

select *from sys.partition_parameters

創(chuàng)建、查看分區(qū)表的Metadata

 

根據(jù)system_type_id查看data type

select * from sys.typeswhere system_type_id=56

創(chuàng)建、查看分區(qū)表的Metadata

 

2, 查看Partition scheme和 filegroup

select *from sys.partition_schemes

創(chuàng)建、查看分區(qū)表的Metadata

data_space_ID 是數(shù)據(jù)空間ID,每一個Parition Scheme都有一個ID。

 

select *from sys.filegroups

創(chuàng)建、查看分區(qū)表的Metadata

data_space_ID 是數(shù)據(jù)空間ID,每一個FileGroup都有一個ID。

 

3, 查看Data Space

select *from sys.data_spaces

Each filegroup has one row, and each partition scheme has one row. If the row refers to a partition scheme, data_space_id can be joined with sys.partition_schemes.data_space_id. If the row referes to a file, data_space_id can be joined with sys.filegroups.data_space_id.

創(chuàng)建、查看分區(qū)表的Metadata

 

sys.data_spaces 是sys.filegroups 和 sys.partition_schemes 結(jié)果的交集,充分說明,partition scheme和filegroup都是數(shù)據(jù)存儲的邏輯空間。

4,partition scheme和filegroup 之間的關系

一個partition scheme能夠使用多個filegroup存儲數(shù)據(jù),同時一個filegroup可以被多個partition scheme使用,partition scheme和filegroup 之間的關系是many-to-many,sql server使用 sys.destination_data_spaces 提供partition scheme和filegroup 之間的關系。

select *from sys.destination_data_spaces

創(chuàng)建、查看分區(qū)表的Metadata

partition_scheme_id  是 sys.partition_schemes的data_space_id,標識一個Partition Scheme。

data_space_id  是 sys.filegroups的data_space_id,標識partition scheme使用的filegroup。

destination_id  是 Partition number。Partition Number是一個數(shù)字,從1開始,標識table的parition的編號。表的partition number從左向右開始編號,最左邊的分區(qū),其partition number 是1。

 

5,查看分區(qū)的信息

select *from sys.partitionswhere object_id=object_id('dbo.dt_test')

創(chuàng)建、查看分區(qū)表的Metadata

partition_id:每一個partition都有一個ID,唯一標識該分區(qū)。

rows:分區(qū)包含的數(shù)據(jù)行數(shù)目

data_compression和data_compression_desc:partition 使用的數(shù)據(jù)壓縮類型

 

6,查看分區(qū)的統(tǒng)計信息

select *from sys.dm_db_partition_statswhere object_id=object_id('dbo.dt_test')

創(chuàng)建、查看分區(qū)表的Metadata

創(chuàng)建、查看分區(qū)表的Metadata

 

 

used_page_count

bigint

Total number of pages used for the partition. Computed as in_row_used_page_count + lob_used_page_count +row_overflow_used_page_count.

reserved_page_count

bigint

Total number of pages reserved for the partition. Computed as in_row_reserved_page_count + lob_reserved_page_count +row_overflow_reserved_page_count.

row_count

bigint

The approximate number of rows in the partition.

 

sys.dm_db_partition_stats displays information about the space used to store and manage in-row data, LOB data, and row-overflow data for all partitions in a database. One row is displayed per partition.

The counts on which the output is based are cached in memory or stored on disk in various system tables.

In-row data, LOB data, and row-overflow data represent the three allocation units that make up a partition. The sys.allocation_units catalog view can be queried for metadata about each allocation unit in the database.

If a heap or index is not partitioned, it is made up of one partition (with partition number = 1); therefore, only one row is returned for that heap or index. Thesys.partitions catalog view can be queried for metadata about each partition of all the tables and indexes in a database.

The total count for an individual table or an index can be obtained by adding the counts for all relevant partitions.

 以上就是創(chuàng)建、查看分區(qū)表的Metadata的方法介紹,詳細使用情況還得要大家自己使用過才能知道具體要領。如果想了解更多相關內(nèi)容,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

標題名稱:創(chuàng)建、查看分區(qū)表的Metadata
瀏覽地址:http://muchs.cn/article46/jcgpeg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、電子商務App開發(fā)、用戶體驗微信小程序、關鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站