Oracle分区表技术 (Partitioned Tables)
- 性能提升: Select语句只检索本分区的记录,减少了记录总数,可有效的提升了查询性能。另外,可以通过表空间将分区映射到不同的物理磁盘上,分散设备IO,提升性能;
- 分区运维:可以针对不同分区,管理数据的加载、索引的创建(以及重建)、数据备份与恢复。因为可针对分区的管理,所以可以有效的降低了分区间的干扰、影响。
- Tables greater than 2GB should always be considered for partitioning.
- Tables containing historical data, in which new data is added into the newest partition. A typical example is a historical table where only the current month's data is updatable and the other 11 months are read only.
Tip: 计算表大小的SQL
SELECT B.OWNER, B.TABLESPACE_NAME, B.TABLE_NAME, ROUND (SUM (BYTES) / 1024 / 1024 / 1024, 6) GIGS FROM SYS.DBA_EXTENTS A, SYS.DBA_TABLES B WHERE ((B.TABLESPACE_NAME = A.TABLESPACE_NAME) AND (B.OWNER = UPPER ('&OWNER')) AND (B.TABLE_NAME = '&TABLE')) GROUP BY B.OWNER, B.TABLESPACE_NAME, B.TABLE_NAME; |
Partitioning Method |
Brief Description |
Range Partitioning |
Used when there are logical ranges of data. Possible usage: dates, part numbers, and serial numbers |
Hash Partitioning |
Used to spread data evenly over partitions. Possible usage: data has no logical groupings |
List Partitioning |
Used to list together unrelated data into partitions. Possible usage: a number of states list partitioned into a region |
Composite Range-Hash Partitioning |
Used to range partition first, then spreads data into hash partitions. Possible usage: range partition by date of birth then hash partition by name; store the results into the hash partitions |
Composite Range-List Partitioning |
Used to range partition first, then spreads data into list partitions.Possible usage: range partition by date of birth then list partition by state, then store the results into the list partitions |
create tablespace invoices_2011 datafile 'e:\app\TianPan\oradata\tbs02.dbf' size 50m;
create tablespace invoices_2012 datafile 'e:\app\TianPan\oradata\tbs03.dbf' size 50m;
create tablespace invoices_2013 datafile 'e:\app\TianPan\oradata\tbs04.dbf' size 50m;
--创建Range类型的分区表
CREATE TABLE Invoices(
Invoice_NO VARCHAR2(10),
Invoice_Creation_Day DATE,
Invoice_Data VARCHAR2(30)
)
PARTITION BY RANGE(Invoice_Creation_Day)
(
PARTITION part01 VALUES LESS THAN(TO_DATE('2010-12-31 00:00:00','yyyy-mm-dd hh24:mi:ss')) TABLESPACE invoices_2010,
PARTITION part02 VALUES LESS THAN(TO_DATE('2011-12-31 00:00:00','yyyy-mm-dd hh24:mi:ss')) TABLESPACE invoices_2011,
PARTITION part03 VALUES LESS THAN(TO_DATE('2012-12-31 00:00:00','yyyy-mm-dd hh24:mi:ss')) TABLESPACE invoices_2012,
PARTITION part04 VALUES LESS THAN (MAXVALUE) TABLESPACE invoices_2013
);
--按年插入测试数据
insert into Invoices values('1',TO_DATE('2010-06-10 00:00:00','yyyy-mm-dd hh24:mi:ss'), '2010 invoice');
insert into Invoices values('2',TO_DATE('2011-07-20 00:00:00','yyyy-mm-dd hh24:mi:ss'), '2011 invoice');
insert into Invoices values('3',TO_DATE('2012-08-25 00:00:00','yyyy-mm-dd hh24:mi:ss'), '2012 invoice');
insert into Invoices values('4',TO_DATE('2013-08-25 00:00:00','yyyy-mm-dd hh24:mi:ss'), '2013 invoice');
commit;
--查询确认,是不是数据被存储到正确的分区
INVOICE_NO INVOICE_CREATION_DAY INVOICE_DATA
---------- -------------------- ------------------------------
1 2010/6/10 2010 invoice
2 2011/7/20 2011 invoice
3 2012/8/25 2012 invoice
4 2013/8/25 2013 invoice
SQL> select * from Invoices partition(part01);
INVOICE_NO INVOICE_CREATION_DAY INVOICE_DATA
---------- -------------------- ------------------------------
1 2010/6/10 2010 invoice
SQL> select * from Invoices partition(part02);
INVOICE_NO INVOICE_CREATION_DAY INVOICE_DATA
---------- -------------------- ------------------------------
2 2011/7/20 2011 invoice
create tablespace TS01 datafile 'e:\app\TianPan\oradata\list\tbs01.dbf' size 50m;
create tablespace TS02 datafile 'e:\app\TianPan\oradata\list\tbs02.dbf' size 50m;
create tablespace TS03 datafile 'e:\app\TianPan\oradata\list\tbs03.dbf' size 50m;
create tablespace TS04 datafile 'e:\app\TianPan\oradata\list\tbs04.dbf' size 50m;
create tablespace TS05 datafile 'e:\app\TianPan\oradata\list\tbs05.dbf' size 50m;
--把不同的州划分到不同的分区(表空间)中
CREATE TABLE PARTITION_BY_LIST
(DEPTID NUMBER,
DEPTNAME VARCHAR2(15),
STATE VARCHAR2(2) ,
CONSTRAINT PARTITION_BY_LIST_PK PRIMARY KEY (DEPTID))
PARTITION BY LIST (STATE)
(PARTITION DEPTS_IN_NORTH VALUES ('AK') TABLESPACE TS01,
PARTITION DEPTS_IN_EAST VALUES ('NY', 'NJ', 'VA', 'CT') TABLESPACE TS02,
PARTITION DEPTS_IN_SOUTH VALUES ('TX', 'MS', 'GA', 'KY') TABLESPACE TS03,
PARTITION DEPTS_IN_WEST VALUES ('CA', 'AZ', 'OR', 'NV') TABLESPACE TS04,
PARTITION DEPTS_WITH_NO_REGION VALUES (DEFAULT) TABLESPACE TS05)
ENABLE ROW MOVEMENT;
--检查分区是否创建正确
SELECT TABLE_NAME, PARTITION_NAME, HIGH_VALUE, TABLESPACE_NAME
FROM USER_TAB_PARTITIONS
WHERE TABLE_NAME = 'PARTITION_BY_LIST'
ORDER BY TABLESPACE_NAME;
--插入测试数据
INSERT INTO PARTITION_BY_LIST (DEPTID, DEPTNAME, STATE) VALUES (1,'ANCHORAGE' , 'AK');
INSERT INTO PARTITION_BY_LIST (DEPTID, DEPTNAME, STATE) VALUES (2,'NEW YORK' , 'NY');
INSERT INTO PARTITION_BY_LIST (DEPTID, DEPTNAME, STATE) VALUES (3,'DALLAS' , 'TX');
INSERT INTO PARTITION_BY_LIST (DEPTID, DEPTNAME, STATE) VALUES (4,'LOS ANGELES', 'CA');
INSERT INTO PARTITION_BY_LIST (DEPTID, DEPTNAME, STATE) VALUES (5,'WAIKIKI' , 'HI');
COMMIT;
--查询确认,是不是数据被存储到正确的分区
SQL> select * from PARTITION_BY_LIST;
DEPTID DEPTNAME STATE
---------- --------------- -----
1 ANCHORAGE AK
2 NEW YORK NY
3 DALLAS TX
4 LOS ANGELES CA
5 WAIKIKI HI
SQL> select * from PARTITION_BY_LIST partition (depts_in_north);
DEPTID DEPTNAME STATE
---------- --------------- -----
1 ANCHORAGE AK
SQL> select * from PARTITION_BY_LIST partition (depts_in_east);
DEPTID DEPTNAME STATE
---------- --------------- -----
2 NEW YORK NY
SQL> select * from PARTITION_BY_LIST partition (depts_with_no_region);
DEPTID DEPTNAME STATE
---------- --------------- -----
5 WAIKIKI HI
SELECT * FROM dba_part_indexes;
SELECT * FROM dba_ind_partitions WHERE index_name = '<index_name>';
Export: Release 11.2.0.1.0 - Production on Fri Jan 9 16:18:05 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table INVOICES
. . exporting partition PART01 1 rows exported
. . exporting partition PART02 1 rows exported
. . exporting partition PART03 1 rows exported
. . exporting partition PART04 1 rows exported
Export terminated successfully without warnings.
分区表导出
Export: Release 11.2.0.1.0 - Production on Fri Jan 9 16:21:04 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table INVOICES
. . exporting partition PART03 1 rows exported
Export terminated successfully without warnings.
全表导入
expdp scott/tiger directory=dmp dumpfile=tb_pt.dmp logfile=tb_pb.log tables=tb_pt parallel=3
导出多个分区
expdp scott/tiger directory=dmp dumpfile=tb_pts.dmp logfile=tb_pt.log tables=(tb_pt:sal_16,tb_pt:sal_other) parallel=2
导入单个分区
impdp scott/tiger directory=dmp dumpfile=tb_pts.dmp logfile=tb_pt_imp.log tables=tb_pt:sal_other skip_unusable_indexes=y table_exists_action=replace
导入整个表
impdp scott/tiger directory=dmp dumpfile=tb_pt.dmp logfile=tb_pt_fullimp.log tables=tb_pt skip_unusable_indexes=y table_exists_action=replace
Oracle分区表技术 (Partitioned Tables)相关推荐
- Oracle 19c 新特性:混合分区表Hybrid partitioned tables强体验
老张拉呱:thomas zhang,甲骨文云平台事业部资深技术顾问,2008年加入甲骨文公司数据库咨询部门,10+年甲骨文解决方案咨询支持经验,资深系统工程师.Oracle OCM认证专家,具有丰富的 ...
- Oracle 19c 新特性 —— 混合分区表Hybrid partitioned tables
简介 从19c开始,Oracle数据库支持Hybrid partitioned tables,也就是混合分区表,进一步扩展了Oracle分区技术.这里的混合指的是数据的分布,分区表的分区可以一些位于数 ...
- oracle 混合分区表,Oracle 19C Hybrid partitioned tables混合分区表
Oracle 19C支持Hybrid partitioned tables(混合分区表),也就是一一个表部分分区是外部CSV\\TXT文件,部分分区是数据库中的表分区,可以同时查询操作,这在归档数据时 ...
- oracle 分区表的建立方法
Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Oracle的分区表可以包括多 ...
- Oracle 分区表的新增、修改、删除、合并。普通表转分区表方法
一. 分区表理论知识 Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Orac ...
- Oracle 分区表(一)
一. 分区表理论知识 Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Orac ...
- Oracle分区表常用命令
一.Oracle分区简介 ORACLE的分区是一种处理超大型表.索引等的技术.分区是一种"分而治之"的技术,通过将大表和索引分成可以管理的小块,从而避免了对每个表作为一个大的.单独 ...
- 深入学习Oracle分区表及分区索引
关于分区表和分区索引(About Partitioned Tables and Indexes)对于10gR2而言,基本上可以分成几类: ? Range(范围)分区 ? Has ...
- java oracle 分区查询_深入学习Oracle分区表及分区索引
深入学习Oracle分区表及分区索引 关于分区表和分区索引(About Partitioned Tables and Indexes)对于10gR2而言,基本上可以分成几类: • Rang ...
最新文章
- ES5和ES6数组遍历方法详解
- ionic+angularJS+iOS混合开发app的学习资料介绍和基本步骤(干货)
- java收银台打印小票_智慧收银台—小票打印机接入方式
- 【Git教程】入门安装客户端与服务器
- 如何破解linux密码
- qPCR检测基因表达的引物数据库
- java上传微博图床_php上传图片到微博图床
- 微擎系统操作记实--公众号管理员权限设置
- Word 排版:插入题注和引用题注
- 最新iOS高薪面试必备要点总结
- 在谷歌上安装倍速播放的插件video-speed-controller
- 20221219 圣诞节,音乐圣诞树
- 华为服务器gpu芯片怎么样,云服务器gpu有多大
- CAN通讯方式--秉火STM32学习笔记
- vue中使用天地图测距、测面、标点【一】
- 计算机ppt格式化在哪里,计算机安装与维护8(分区、格式化)ppt课件.ppt
- Ubuntu连接上海大学校园网(ShuWlan-1x Shu(For All))
- ERNIE3.0多分类任务应用详细教程代码
- HoloLens开发(配置)
- 量化交易创干货合集送给每一位爱学习的宽客quant
热门文章
- 各个Android 市场的开发者的网址
- 腾讯企业邮箱要实名认证吗?
- EBS开发_费用类采购订单接收
- Office365 - 如何更新Yammer的user profile
- Android的开发文档规范
- 计算机技术与软件技术资格(水平)考试(软考)
- 计算机最炫民族风教案,辽师大版信息技术四下第一单元第6课《最炫民族风》教案3.docx...
- 为什么坐飞机可以玩荣耀刷抖音?可见光通信LiFi告诉你!
- 追踪捕捉-人体追踪-地屏_只是我的类型-追踪字母的演变
- 如何下载SOLIDWORKS块库?