老張拉呱:thomas zhang,甲骨文云平臺事業(yè)部資深技術(shù)顧問(wèn),2008年加入甲骨文公司數據庫咨詢(xún)部門(mén),10+年甲骨文解決方案咨詢(xún)支持經(jīng)驗,資深系統工程師、Oracle OCM認證專(zhuān)家,具有豐富的Cloud /IT項目經(jīng)驗。目前主要負責甲骨文中國北方區(醫院/衛生、交通、制造、教育、政府、證券、媒體、金融、零售等行業(yè))客戶(hù)的數據庫、中間件、IaaS/PaaS、集成系統等相關(guān)技術(shù)解決方案咨詢(xún)工作。
簽名:我為人人,人人為我,三人行,必有我師。
新浪微博: http://weibo.com/tomszrp
Oracle 的分區是一種“分而治之”的技術(shù),通過(guò)將大表、索引分成可以獨立管理的、小的 Segment,從而避免了對每個(gè)對象作為一個(gè)大的、單獨的 Segment 進(jìn)行管理,為海量數據訪(fǎng)問(wèn)提供了可伸縮的性能。自從 Oracle 引入分區技術(shù)以來(lái),Oracle 公司在每次推出重要版本時(shí)都會(huì )對分區方法或功能上有所增強。從后面的分區方法中我們也可以清晰的看到 Oracle 分區技術(shù)的發(fā)展、成長(cháng)歷程。Oracle 公司一直在致力于不斷完善分區技術(shù),確保滿(mǎn)足所有的業(yè)務(wù)需求。
版本
新支持的分區方法
說(shuō)明
7.3.x
邏輯分區/分區視圖
?在Oracle 8版本前,DBAs和Consultants 根據系統需要實(shí)現了"Home-Grown"(自產(chǎn)的/土生土長(cháng)的)分區方法,他們借助UNION-ALL Views或Partition Views(7.3開(kāi)始提供的分區視圖,需要配合初始化參數PARTITION_VIEW_ENABLED=TRUE來(lái)使用Optimizer Prunes特性)實(shí)現,即使到今天,如果不采購Oracle Database Enterprise Edition下的Partitioning Option License,從許可上來(lái)講,也必須借助這種Home-Grown的方法來(lái)實(shí)現。
?這種方法對DML是不透明的
?Partition Views in 7.3: Examples and Tests (文檔 ID 43194.1)
8.0.x
Oracle 8.5 開(kāi)始支持分區表/索引,
首先提供范圍分區(range)
1)使Oracle成為了第一個(gè)支持物理分區的RDBMS供應商
2)Oracle 8 僅支持表和索引級的分區( Clustered tables/indexes and snapshots are not supported)
3)Oracle 8中不可以update partition key columns,否則會(huì )遇到ORA-14402錯誤
4)只實(shí)現了靜態(tài)的分區裁剪功能
5)支持索引的Local and global Range
8i
新增加希分區(hash)
開(kāi)始支持范圍-哈希復合分區(range-hash)
8.1.7實(shí)現了動(dòng)態(tài)智能裁剪(Dynamic partition pruning)和智能連接(Partition-wise joins)
9iR1
新增列表分區(list)
開(kāi)始支持全局索引維護
1)在9i(9.0.1)之前, IOT表只支持range分區,實(shí)際上是從8.1.5版本開(kāi)始支持對IOT的range分區
2)從9i開(kāi)始支持對IOT的range、hash分區
3)在9iR2 hash分區支持IOT表中包含lob列(9i中暫不支持包含lob類(lèi)型的IOT hash 分區)
4)支持Global index maintenance
9iR2
開(kāi)始支持范圍-列表復合分區(range-list)
1)Fast Split
2)DEFAULT Partition for LIST
10gR1
1)增加了對索引組織表(IOT) 列表(list)分區功能
2)增加了對全局分區索引的hash分區策略
3)10gR2開(kāi)始一個(gè)表可以支持1024K-1個(gè)分區(以前是64K-1)
1)擴展了global indexes on partitioned IOTs的維護支持
2)Local partitioned bitmap indexes on partitioned IOTs
3)LOB columns are now supported in all types of partitioned IOTs.
4)fast split partition支持分區IOT表
10gR2
11g
Interval Partitioning
實(shí)現了范圍分區的自動(dòng)化
System Partitioning(系統分區)
在這個(gè)新的類(lèi)型中,我們不需要指定任何分區鍵,數據會(huì )進(jìn)入哪個(gè)分區完全由應用程序決定,實(shí)際上也就是由SQL來(lái)決定,終于我們在Insert語(yǔ)句中可以指定插入哪個(gè)分區了
More Composite Partitioning (更多的復合分區)
在9i、10g中,復合分區只支持Range-List和Range-Hash
在11gR1中復合分區的類(lèi)型大大增加,現在Range,List,Interval都可以作為T(mén)op level分區,而Second level則可以是Range,List,Hash,也就是在11gR1中可以有3*3=9種復合分區,可以滿(mǎn)足更多的業(yè)務(wù)需要.
在11gR2中,又增加了hash-hash復合分區
Reference Partitioning(外鍵也叫引用分區)
分區方案的引入是以相關(guān)表格通過(guò)相同的分區策略獲得好處作為前提設想的。Detail表格通過(guò)PK-FK關(guān)系從master表格繼承相同的分區方案.我們不需要把分區鍵存儲在detail表格中,通過(guò)關(guān)鍵詞“PARTITION BY REFERENCE,detail表格獲得master表格的分區方案
虛擬列分區(Virtual Column-Based Partitioning)
在11g之前,只有分區鍵存在于表格中才可以實(shí)現對表格的分區功能。而Oracle 11g的新功能“虛擬列”打破了這一限制,允許通過(guò)使用表格中的一列或多列的計算式作為分區鍵。
分區建議器
SQL Access Advisor 不但可以為索引、物化視圖和物化視圖日志提供建議,還可以生成分區建議。執行 SQL Access Advisor 生成的建議,您將會(huì )看到預期的性能收益??梢允謩?dòng)實(shí)施生成的腳本,也可以將其提交給 Oracle Enterprise Manager 中的一個(gè)隊列。借助分區建議擴展,客戶(hù)不僅可以獲得專(zhuān)門(mén)針對分區的建議,還可以獲得 SQL Access Advisor 的更全面的整體建議,從而在總體上提高 SQL 語(yǔ)句的整體性能。
Partition Advisor 已集成到 SQL Access Advisor 中,是 Oracle Tuning Pack(一個(gè)額外的許可選件)的組成部分。
12cR1
Online Partition 維護
1)在線(xiàn)移動(dòng)、壓縮分區或子分區,不阻賽DML操作
alter table sales move partition p1 tablespace lowtbs update indexes online;
alter table sales move partition p1 ROW STORE COMPRESS BASIC update indexes online;
alter table sales move partition p1 ROW STORE COMPRESS ADVANCED update indexes online;
alter table sales move partition p1 COLUMN STORE COMPRESS FOR QUERY LOW update indexes online;
alter table sales move partition p1 COLUMN STORE COMPRESS FOR QUERY HIGH update indexes online;
alter table sales move partition p1 COLUMN STORE COMPRESS FOR ARCHIVE LOW update indexes online;
alter table sales move partition p1 COLUMN STORE COMPRESS FOR ARCHIVE HIGH update indexes online;
select table_name,compression,compress_for from dba_tables;
select table_name,partition_name, compression,compress_for from dba_tab_partitions;
參見(jiàn)示例
2)Restrictions on the ONLINE Clause --詳見(jiàn)官方文檔里的說(shuō)明
(1)不支持sys用戶(hù)下表
(2)不支持索引組織表(IOT)
(3)不支持包含對象類(lèi)型或bitmap join indexes以及domain indexes的表
(4)當打開(kāi)database-level supplemental logging 時(shí)不支持online維護
(5)Parallel DML and direct path INSERT operations require an exclusive lock on the table. 所以, these operations are not supported concurrently with an ongoing online partition MOVE, due to conflicting locks.
Reference Partitioning的增強
1)支持Interval-Reference分區
2)提供truncate partition、exchange [SUB]partition操作的CASCADE級聯(lián)選項
多分區維護操作
add/truncate/drop/split/merge分區操作允許在一個(gè)操作中一次操作多個(gè)分區
部分索引
Local和Global indexes可以在部分分區上創(chuàng )建,這個(gè)特性(Partial Indexing on Partitioned Tables)是通過(guò)表表上的indexing屬性來(lái)控制的。注意,部分索引不能創(chuàng )建全局唯一索引。
全局索引異步維護
1)對于Drop和Truncate Parition 操作,支持異步維護全局索引,Update Indexes字句僅僅維護metadata,真正的索引維護是通過(guò)一個(gè)JOB(SYS.PMO_DEFERRED_GIDX_MAINT_JOB)異步完成的。缺省情況下該job是每天凌晨2:00執行,也可手工調用dbms_part.cleanup_gidx來(lái)完成
PROCEDURE CLEANUP_GIDX - To clean up the global indexes
PROCEDURE CLEANUP_GIDX_INTERNAL - To clean up the internal tables
PROCEDURE CLEANUP_ONLINE_OP - To clean up the online partition movements
2)DBA_INDEXES 和DBA_IND_PARTITIONS新增加了ORPHANED_ENTRIES列。該列用來(lái)指出whether or not a global index (partition) contains stale entries due to deferred index maintenance during DROP/TRUNCATE PARTITION, or MODIFY PARTITION operations. 有三種取值:
YES: The index (partition) contains orphaned entries
NO: The index (partition) does not contain any orphaned entries
N/A: The property is not applicable – this is the case for local indexes, or indexes on non-partitioned tables.
12cR2
Multi-Column List Partition
1)12.2.0.1.0開(kāi)始支持,最大16個(gè)列
2)支持分區和子分區
3)支持heap tables、external tables
4)支持Reference Partitioning and Auto-List
Auto-List Partitioning
1)實(shí)現了list分區的自動(dòng)化管理,類(lèi)似11g版本開(kāi)始支持的Interval Partitioning
2)沒(méi)有default分區,必須至少指定一個(gè)分區
3)系統自動(dòng)增加的分區會(huì )自動(dòng)命名
4)list分區到Auto-List可以轉換,前提是List分區表定義上沒(méi)有DEFAULT分區
Interval Subpartioning
1) 從11g版本中開(kāi)始支持的Interval Partitioning技術(shù)不支持子分區,從12cR2版本開(kāi)始支持。
2) Interval Subpartioning和Interval Partitioning的使用條件及要求是一樣的,如:
--沒(méi)有MAXVALUE
--沒(méi)有Add Partition
3) Interval-subpartitoning strategy set at table level
--Subpartiton template mandatory
--Interval identical for all partitions
4) 每個(gè)表最大100萬(wàn)個(gè)[sub]partitions
--From one partition with one million subpartitions ..
--..To one million partitions with one subpartition each
Partitioned External Tables
Partitioned external tables will provide both the functionality to map partitioned Hive tables into the Oracle ecosystem as well as providing declarative partitioning on top of any Hadoop Distributed File System (HDFS) based data store.
分區與Sharding
–數據垂直分區到多個(gè)獨立的數據庫中
–線(xiàn)性擴展
–自動(dòng)部署
–支持HASH、RANGE、LIST和復合方式的自動(dòng)數據分區
–自動(dòng)Rebalance和Resharding
分區表相關(guān)維護維護方面的增強
Online分區維護(DDL)的
11g
Create index
Add column
Add constraint
12cR1
Drop index
Drop Constraint
Alter table set unused column
Alter table move partition
12cR2
Alter table modify non-partitioned table to partitioned table
Alter table move online for heap tables
Alter table split partition online
Filtered分區維護操作
該特性允許我們在維護(Move/merge/split)分區表的時(shí)候進(jìn)行數據過(guò)濾
alter table orders_move_part
move partition Q1_2015 tablespace tbs_archive compress
INCLUDE ROWS where order_state='open';
快速創(chuàng )建分區交換中間表
Oracle Database 12c 第 2 版中的FOR EXCHANGE WITH子句消除了分區交換的檢測性工作,Indexes are not created as part of this command. eg:
create table sales_exch for exchange with sales;
只讀分區
分區/子分區可以被設置為read only或read write(default)。
注意:只讀分區不允許drop,但對應的base table是可以被drop的,所以不要寄望于這個(gè)做更加級別的安全保護,還是要配合權限和其他安全措施來(lái)保護。
tips:這樣從12cR2/18c開(kāi)始,可以做到Service->Oracle_Home->Instance-->PDB->Tablespace ->Table/MV/外部表->Partition->subpartition等各個(gè)級別的只讀設置,配合對象只讀權限(read)、系統只讀權限(read any table)及Schema Only Accounts等特性,可以滿(mǎn)足各個(gè)層次的數據保護需求。
18c
18.1.0
Enhanced Parallel Partition-wise Operations
參見(jiàn)這里
· Partition-Wise Operations
· Partition-Wise Joins in a Data Warehouse
相關(guān)知識:Partition-Wise Operations – New Features in 12c and 18c
Modifying the Partitioning Strategy 參見(jiàn)這里的文檔說(shuō)明。
Online Merging of Partitions and Subpartitions
這是18c(18.1.0)中針對分區技術(shù)的一個(gè)很酷的改進(jìn),在不影響業(yè)務(wù)的情況下,可以在線(xiàn)合并分區或子分區。參見(jiàn)這里的文檔說(shuō)明。
19c
19.2
Hybrid partitioned tables--混合分區表
原創(chuàng ):老張拉呱
資源下載
關(guān)注公眾號:數據和云(OraNews)回復關(guān)鍵字獲取
2018DTCC , 數據庫大會(huì )PPT
2018DTC,2018 DTC 大會(huì ) PPT
DBALIFE ,“DBA 的一天”海報
DBA04 ,DBA 手記4 電子書(shū)
122ARCH ,Oracle 12.2體系結構圖
2018OOW ,Oracle OpenWorld 資料
產(chǎn)品推薦云和恩墨Bethune Pro企業(yè)版,集監控,巡檢,安全于一身,你的專(zhuān)屬數據庫實(shí)時(shí)監控和智能巡檢平臺,漂亮的不像實(shí)力派,你值得擁有!