oracle 12cR2 过滤分区维护操作
2017-10-17 14:16
489 查看
Filtered Partition Maintenance Operations in Oracle Database 12c Release 2 (12.2)
Oracle Database 12c Release 2 (12.2) allows you to add a filter condition when you move, split or merge a partition, move a table or convert a non-partitioned table to a partitioned table. Only those rows matching the filter condition are included in the resultingobject.
Oracle 12cR2允许在移动、拆分和合并分区,移动表或者将普通表转换为分区表时增加过滤条件。只有满足过滤条件的行在结果对象中。
The filter condition is only allowed on heap tables, can only reference columns from the table and can be used in conjunction with online operations with some additional
considerations.
过滤条件仅允许在堆组织表上使用,只能引用表中的列及结合一些在线操作的额外条件。
This article provides some simple examples using filter conditions with maintenance operations. The examples in this article are mostly based on partition management operations, but this functionality applies equally to subpartition maintenance operations.
该文提供一些使用过滤条件的维护操作的简单示例。本文中的示例主要基于分区维护操作,但该功能同样使用于子分区的维护操作。
Move a Table 移动表
Convert a Non-Partitioned Table to a
Partitioned Table 非分区表转换为分区表
Move a Partition
移动分区
Split a Partition 拆分分区
Merge Partitions 合并分区
Related articles.
All Partitioning Articles
Partitioning Enhancements in Oracle Database 12c Release 2 (12.2)
Online Move of Partitions and Sub-Partitions in Oracle
12c Release 1
Online Conversion of a Non-Partitioned
Table to a Partitioned Table in Oracle Database 12c Release 2 (12.2)
Online Move of a Table in Oracle Database 12c Release 2 (12.2)
Move a Table
移动表Create and populate a new test table.
创建和填充新测试表
DROP TABLE t1 PURGE; CREATE TABLE t1 AS SELECT level AS id, 'Description for ' || level AS description FROM dual CONNECT BY level <= 100; COMMIT;
Check the contents of the table.
检查表内容
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 100 1 100 SQL>
Move the table, filtering out rows with an
IDvalue greater than 50.
移动表,过滤掉ID大于50的值:
ALTER TABLE t1 MOVE ONLINE INCLUDING ROWS WHERE id <= 50;
Check the contents of the table.
检查表内容
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 50 1 50 SQL>
The rows with an
IDvalue between 51 and 100 have been removed.
可见ID在51至100之间的值已经被移除。
Convert a Non-Partitioned Table to a Partitioned Table
普通表转为分区表
Create and populate a new test table.DROP TABLE t1 PURGE; CREATE TABLE t1 AS SELECT level AS id, 'Description for ' || level AS description FROM dual CONNECT BY level <= 100; COMMIT;
Check the contents of the table.
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 100 1 100 SQL>
Convert the table to a partitioned, filtering out rows with an
IDvalue greater than 50.
转为分区表,过滤掉ID值大于50的值.
ALTER TABLE t1 MODIFY PARTITION BY RANGE (id) ( PARTITION t1_le_50 VALUES LESS THAN (51), PARTITION t1_le_101 VALUES LESS THAN (101) ) INCLUDING ROWS WHERE id <= 50;
Check the contents of the partitions.
EXEC DBMS_STATS.gather_table_stats(USER, 'T1');
COLUMN table_name FORMAT A20
COLUMN partition_name FORMAT A20
COLUMN high_value FORMAT A20
SELECT table_name, partition_name, high_value, num_rows
FROM user_tab_partitions
WHERE table_name = 'T1'
ORDER BY 1,2;
TABLE_NAME PARTITION_NAME HIGH_VALUE NUM_ROWS
-------------------- -------------------- -------------------- ----------
T1 T1_LE_101 101 0
T1 T1_LE_50 51 50
SQL>
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 50 1 50 SQL>
The rows with an
IDvalue between 51 and 100 have been removed.
Move a Partition
移动分区
Create and populate a new test partitioned table.DROP TABLE t1 PURGE; CREATE TABLE t1 ( id NUMBER, description VARCHAR2(50) ) PARTITION BY RANGE (id) ( PARTITION t1_le_50 VALUES LESS THAN (51), PARTITION t1_le_101 VALUES LESS THAN (101) ); INSERT INTO t1 SELECT level AS id, 'Description for ' || level AS description FROM dual CONNECT BY level <= 100; COMMIT;
Check the contents of the partitions.
EXEC DBMS_STATS.gather_table_stats(USER, 'T1');
COLUMN table_name FORMAT A20
COLUMN partition_name FORMAT A20
COLUMN high_value FORMAT A20
SELECT table_name, partition_name, high_value, num_rows
FROM user_tab_partitions
WHERE table_name = 'T1'
ORDER BY 1,2;
TABLE_NAME PARTITION_NAME HIGH_VALUE NUM_ROWS
-------------------- -------------------- -------------------- ----------
T1 T1_LE_101 101 50
T1 T1_LE_50 51 50
SQL>
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 100 1 100 SQL>
Move a partition, filtering out rows with an
IDvalue greater than 50.
移动分区,过滤掉ID大于50的值:
ALTER TABLE t1 MOVE PARTITION t1_le_101 ONLINE TABLESPACE users INCLUDING ROWS WHERE id <= 50;
Check the contents of the partitions.
EXEC DBMS_STATS.gather_table_stats(USER, 'T1');
COLUMN table_name FORMAT A20
COLUMN partition_name FORMAT A20
COLUMN high_value FORMAT A20
SELECT table_name, partition_name, high_value, num_rows
FROM user_tab_partitions
WHERE table_name = 'T1'
ORDER BY 1,2;
TABLE_NAME PARTITION_NAME HIGH_VALUE NUM_ROWS
-------------------- -------------------- -------------------- ----------
T1 T1_LE_101 101 0
T1 T1_LE_50 51 50
SQL>
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 50 1 50 SQL>
The rows with an
IDvalue between 51 and 100 have been removed.
Split a Partition
拆分分区
Create and populate a new test partitioned table.DROP TABLE t1 PURGE; CREATE TABLE t1 ( id NUMBER, description VARCHAR2(50) ) PARTITION BY RANGE (id) ( PARTITION t1_le_101 VALUES LESS THAN (101) ); INSERT INTO t1 SELECT level AS id, 'Description for ' || level AS description FROM dual CONNECT BY level <= 100; COMMIT;
Check the contents of the partition.
EXEC DBMS_STATS.gather_table_stats(USER, 'T1');
COLUMN table_name FORMAT A20
COLUMN partition_name FORMAT A20
COLUMN high_value FORMAT A20
SELECT table_name, partition_name, high_value, num_rows
FROM user_tab_partitions
WHERE table_name = 'T1'
ORDER BY 1,2;
TABLE_NAME PARTITION_NAME HIGH_VALUE NUM_ROWS
-------------------- -------------------- -------------------- ----------
T1 T1_LE_101 101 100
SQL>
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 100 1 100 SQL>
Split the partition, filtering out rows with an
IDvalue greater than 50.
拆分分区,过滤掉ID值大于50的值:
ALTER TABLE t1 SPLIT PARTITION t1_le_101 AT (51) INTO (PARTITION t1_le_51, PARTITION t1_le_101) INCLUDING ROWS WHERE id <= 50 ONLINE;
Check the contents of the partitions.
EXEC DBMS_STATS.gather_table_stats(USER, 'T1');
COLUMN table_name FORMAT A20
COLUMN partition_name FORMAT A20
COLUMN high_value FORMAT A20
SELECT table_name, partition_name, high_value, num_rows
FROM user_tab_partitions
WHERE table_name = 'T1'
ORDER BY 1,2;
TABLE_NAME PARTITION_NAME HIGH_VALUE NUM_ROWS
-------------------- -------------------- -------------------- ----------
T1 T1_LE_101 101 0
T1 T1_LE_51 51 50
SQL>
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 50 1 50 SQL>
The rows with an
IDvalue between 51 and 100 have been removed.
Merge Partitions
合并分区
Create and populate a new test partitioned table.DROP TABLE t1 PURGE; CREATE TABLE t1 ( id NUMBER, description VARCHAR2(50) ) PARTITION BY RANGE (id) ( PARTITION t1_le_51 VALUES LESS THAN (51), PARTITION t1_le_101 VALUES LESS THAN (101) ); INSERT INTO t1 SELECT level AS id, 'Description for ' || level AS description FROM dual CONNECT BY level <= 100; COMMIT;
Check the contents of the partitions.
EXEC DBMS_STATS.gather_table_stats(USER, 'T1');
COLUMN table_name FORMAT A20
COLUMN partition_name FORMAT A20
COLUMN high_value FORMAT A20
SELECT table_name, partition_name, high_value, num_rows
FROM user_tab_partitions
WHERE table_name = 'T1'
ORDER BY 1,2;
TABLE_NAME PARTITION_NAME HIGH_VALUE NUM_ROWS
-------------------- -------------------- -------------------- ----------
T1 T1_LE_101 101 50
T1 T1_LE_51 51 50
SQL>
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 100 1 100 SQL>
Merge the partitions, filtering out rows with an
IDvalue greater than 50.
合并分区,过滤掉ID值大于50的值:
ALTER TABLE t1 MERGE PARTITIONS t1_le_51, t1_le_101 INTO PARTITION t1_le_101 INCLUDING ROWS WHERE id <= 50;
Check the contents of the partitions.
EXEC DBMS_STATS.gather_table_stats(USER, 'T1');
COLUMN table_name FORMAT A20
COLUMN partition_name FORMAT A20
COLUMN high_value FORMAT A20
SELECT table_name, partition_name, high_value, num_rows
FROM user_tab_partitions
WHERE table_name = 'T1'
ORDER BY 1,2;
TABLE_NAME PARTITION_NAME HIGH_VALUE NUM_ROWS
-------------------- -------------------- -------------------- ----------
T1 T1_LE_101 101 50
SQL>
SELECT COUNT(*) AS total_rows, MIN(id) AS min_id, MAX(id) AS max_id FROM t1; TOTAL_ROWS MIN_ID MAX_ID ---------- ---------- ---------- 50 1 50 SQL>
The rows with an
IDvalue between 51 and 100 have been removed.
相关文章推荐
- 柯南君 :Oracle 分区技术 之 如何支撑大数据操作?
- Oracle 11gR2 RAC 常用维护操作
- Oracle 分区信息操作
- 转 -- Oracle 11gR2 RAC 常用维护操作 说明
- Oracle的分区操作和修改分区主键
- oracle 复合分区相关操作
- Oracle 10g 物理Dataguard日常操作维护(一)
- Linux系统Oracle 12cR2 RAC集群安装与维护管理(12.2)专题
- Oracle 12C 新特性之表分区带 异步全局索引异步维护(一次add、truncate、drop、spilt、merge多个分区)
- Oracle 10g 物理Dataguard日常操作维护(二)
- Oracle 11gR2 RAC 常用维护操作 说明
- Oracle data guard常用维护操作命令
- Oracle 11gR2 RAC 常用维护操作 说明
- oracle 分区操作常用命令
- Oracle常用维护管理操作[收集中]
- Oracle data guard常用维护操作命令
- ORA-14048: 分区维护操作不能与其它操作组合
- Oracle 10g 物理Dataguard日常操作维护(一)
- Oracle 分区操作
- DBA_Oracle Startup / Shutdown启动和关闭过程详解(概念)(对数据库进行各种维护操作)