创建分区表和查看分区表的Metadata

未分区的表,只能存储在一个FileGroup中;对table进行分区后,每一个分区都存储在一个FileGroup中。表分区是将逻辑上一个完整的表,按照特定的字段拆分成Partition set,分散到(相同或不同的)FileGroup中,每一个Partition在FileGroup中都独立存储,每一个parititon都属于唯一的表对象,每一个Partition 都有唯一的ID。

在创建表时,使用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指定的,FileGroup是File的集合,每一个File都属于唯一的FileGroup。将table的存储空间拆分到不同的FileGroup中,逻辑上是将table的存储管理体系增加了一层 Partition,介于Table和FileGroup中间,Table的数据存储在Partition,Partition存储在FileGroup中,FileGroup管理着File,File是实际存储data的物理文件。

table为什么要增加Parition?因为FileGroup是所有的Table共享,Partition是由一个table独占,每一个Partition都唯一属于一个table。这样,对某个parititon进行操作,而不影响table的其他parition,也不会影响其他table。

一:创建分区表的步骤

Step1, 创建分区函数

分区函数的作用是提供分区字段的类型和分区的边界值

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

pf_int 的含义是按照int类型分区,分区的边界值是10,20,left表示边界值属于左边界。两个边界值能够分成三个分区,别是(-infinite,10],(10,20],(20,+infinite)。

Step2,创建分区scheme

分区scheme的作用是为Parition分配FileGroup,Partition Scheme和FileGroup在逻辑上等价,都是数据存储的逻辑空间,只不过Partition Scheme指定的是多个FileGroup。

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

不管是在不同的FileGroup中,还是在相同的FileGroup中,分区都是独立存储的。

Step3,创建分区表

创建分区表,实际上是使用on子句指定table存储的逻辑位置。

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

二,查看Partition的Metadata

1, 查看partition function

select *from sys.partition_functions

查看partition function定义的边界值

select * from sys.partition_range_values

查看partition function 定义的parmeter,这个Parmeter是一个data type,system_type_id标识该data type。

select *from sys.partition_parameters

根据system_type_id查看data type

select * from sys.typeswhere system_type_id=56

2, 查看Partition scheme和 filegroup

select *from sys.partition_schemes

data_space_ID 是数据空间ID,每一个Parition Scheme都有一个ID。

select *from sys.filegroups

data_space_ID 是数据空间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.

sys.data_spaces 是sys.filegroups 和 sys.partition_schemes 结果的交集,充分说明,partition scheme和filegroup都是数据存储的逻辑空间。

4,partition scheme和filegroup 之间的关系

一个partition scheme能够使用多个filegroup存储数据,同时一个filegroup可以被多个partition scheme使用,partition scheme和filegroup 之间的关系是many-to-many,sql server使用 sys.destination_data_spaces 提供partition scheme和filegroup 之间的关系。

select *from sys.destination_data_spaces

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是一个数字,从1开始,标识table的parition的编号。表的partition number从左向右开始编号,最左边的分区,其partition number 是1。

5,查看分区的信息

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

partition_id:每一个partition都有一个ID,唯一标识该分区。

rows:分区包含的数据行数目

data_compression和data_compression_desc:partition 使用的数据压缩类型

6,查看分区的统计信息

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


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.

时间: 2024-08-09 02:58:26

创建分区表和查看分区表的Metadata的相关文章

mysql数据库的基本操作:创建数据库、查看数据库、修改数据库、删除数据库

本节相关: 创建数据库,查看数据库,修改数据库,删除数据库 首发时间:2018-02-13 20:47 创建数据库  : 语法  : create database 数据库名字[库选项]; 库选项说明  : 库选项是可选项,可以不写 库选项有两项:字符集和校对集. 库选项的字符集是数据库识别或存储数据使用的字符集.常用字符集有utf8和gbk; 库选项的校对集是数据库校对数据时使用的校对集[校对数据时依据校对集的规则来校对,比如有些校对集忽略大小写]. 但凡是创建数据库时不指定库选项的,都将使用

spring项目篇15 --- 商城小项目创建订单以及查看所有订单

深圳肺炎患者突破80了,现在心里慌慌的,不知什么时候返深啊...既来之,则安之! 今天,这个简单的小项目最后一步,创建订单以及查看所有订单状态,我们的订单只需要点击一下付款即可完成支付,没有接入第三方支付.下面计划开始学习mybatis. 因为大多是业务代码,我们直接看就可以 先看dao层,在创建订单的时候,因为设计多表操作,因此需要开启事务 // IOrderDao package com.yang.dao; import com.yang.domain.Car; import com.yan

查看分区表使用的partition scheme 和 partition function

分区表和partition scheme之间的关系是由sys.indexes 确定的,当index_id=0,表示分区表是个heap,表没有创建聚集索引,当index_id=1,表示分区表是个BTree,表存在聚集索引. sys.indexes Contains a row per index or heap of a tabular object, such as a table, view, or table-valued function. sys.indexes 有一个非常关键的字段 d

Oracle -&gt;&gt; 查看分区表的每个分区的数据行分布情况

ora_hash函数用来返回分区号,而dbms_rowid.rowid_object()函数用来返回object_id select dbms_rowid.rowid_object(rowid) obj_id, ora_hash ( id, 31, 0) part_id ,count(*) from sales_fact_part group by dbms_rowid.rowid_object(rowid), ora_hash(id,31,0) order by 1;

创建跟踪和查看执行计划需要的权限

多看书,多积累,温故知新.只有要用的时候,才会发现知识欠缺.不要说知道有这么回事,要很有底气的回答应该怎么做.查看跟踪和查看执行计划需要怎样的权限?sysadmin/db_owner肯定可以,但不应该给这么大的权限.创建登录名 --create login use master go create login TracePlan with password='123qwe' go 创建用户 --create user use AdventureWorks2008R2 go create user

MongoDB索引管理——创建索引,查看索引,删除索引,重建索引

先给users集合插入两条记录,然后用users集合来进行索引管理的演示: > user1={"name":"liming","age":20,"gender":"F"} { "name" : "liming", "age" : 20, "gender" : "F" } > db.users.in

mysql中,如何查看数据库元数据(metadata)的字符集?

需求描述: mysql中,数据库的元数据也是有字符集的. 操作过程: 1.查看mysql数据库元数据的字符集 mysql> show variables like 'character_set_system'; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | character_set_system | utf8 | +-------------------

spark 中如何查看单个RDD分区的内容(创建分区,查看分区数)

spark 创建分区 val scores = Array(("Fred", 88), ("Fred", 95), ("Fred", 91), ("Wilma", 93), ("Wilma", 95), ("Wilma", 98)) val input = sc.parallelize(scores,3)   #这里创建了3个分区 查看分区数: input.partitions.size

【linux】创建用户,查看用户

查看用户:cat /etc/passwd 创建sudo+NOPASSWD的权限的用户: useradd admin id admin passwd admin (abc123) visudo 设置admin ALL=(ALL) NOPASSWD: ALL 原文地址:https://www.cnblogs.com/Calinayc/p/11581756.html