Professional Documents
Culture Documents
General Information
Library Note Are you prepared for the release of Oracle Database 18c ... the first autonomous database? We are here at the Library. It is time fo
stop fighting robots with their fingers and losing ... time to start using our intelligence and winning.
Purpose Partitioning and subpartitioning of tables and indexes is a technique for creating a single logical entity, a table or index, mapping multiple
segments allowing the optimizer to access a smaller number of blocks to respond to a SQL statement.
Oracle supports partitioning only for tables, indexes on tables, materialized views, and indexes on materialized views. Oracle does not s
partitioning of clustered tables or indexes on clustered tables.
Partition Types Partition Type Composite Type
Hash List - Hash
Interval List - List
List List - Range
Range Exadata
Reference Range - Hash
System Range - List
Virtual Column Range - Range
Dependencies ALL_IND_PARTITIONS CDB_PART_KEY_COLUMNS INDPART$
ALL_IND_SUBPARTITIONS CDB_PART_LOBS INDPART_PARAM$
ALL_LOB_PARTITIONS CDB_PART_TABLES INDSUBPART$
ALL_LOB_SUBPARTITIONS CDB_SUBPARTITION_TEMPLATES INSERT_TSN_LIST
ALL_MVIEW_DETAIL_PARTITION CDB_SUBPART_COL_STATISTICS PARTLOB$
ALL_MVIEW_DETAIL_SUBPARTITION CDB_SUBPART_HISTOGRAMS PARTOBJ$
ALL_PART_COL_STATISTICS CDB_SUBPART_KEY_COLUMNS SUBPARTCOL$
ALL_PART_HISTOGRAMS CDB_TAB_PARTITIONS TABPART$
ALL_PART_INDEXES CDB_TAB_SUBPARTITIONS TABSUBPART$
ALL_PART_KEY_COLUMNS DBA_IND_PARTITIONS USER_IND_PARTITIO
ALL_PART_LOBS DBA_IND_SUBPARTITIONS USER_IND_SUBPARTIT
ALL_PART_TABLES DBA_LOB_PARTITIONS USER_LOB_PARTITIO
ALL_SUBPARTITION_TEMPLATES DBA_LOB_SUBPARTITIONS USER_LOB_SUBPARTIT
ALL_SUBPART_COL_STATISTICS DBA_MVIEW_DETAIL_PARTITION USER_MVIEW_DETAIL_PA
ALL_SUBPART_HISTOGRAMS DBA_MVIEW_DETAIL_SUBPARTITION USER_MVIEW_DETAIL_SUB
ALL_SUBPART_KEY_COLUMNS DBA_PART_COL_STATISTICS USER_PART_COL_STAT
ALL_TAB_PARTITIONS DBA_PART_HISTOGRAMS USER_PART_HISTOGR
ALL_TAB_SUBPARTITIONS DBA_PART_INDEXES USER_PART_INDEX
CDB_IND_PARTITIONS DBA_PART_KEY_COLUMNS USER_PART_KEY_COL
CDB_IND_SUBPARTITIONS DBA_PART_LOBS USER_PART_LOBS
CDB_LOB_PARTITIONS DBA_PART_TABLES USER_PART_TABLE
CDB_LOB_SUBPARTITIONS DBA_SUBPARTITION_TEMPLATES USER_SUBPARTITION_TEM
CDB_MVIEW_DETAIL_PARTITION DBA_SUBPART_COL_STATISTICS USER_SUBPART_COL_STA
CDB_MVIEW_DETAIL_SUBPARTITION DBA_SUBPART_HISTOGRAMS USER_SUBPART_HISTOG
CDB_PART_COL_STATISTICS DBA_SUBPART_KEY_COLUMNS USER_SUBPART_KEY_CO
CDB_PART_HISTOGRAMS DBA_TAB_PARTITIONS USER_TAB_PARTITIO
CDB_PART_INDEXES DBA_TAB_SUBPARTITIONS USER_TAB_SUBPARTIT
Definitions
Composite Partitioning Composite partitioning is a combination of other partitioning methods. Oracle currently supports range-hash and range-list composite pa
Explain Plan PSTART/PSTOP Values KEY(I) IN subquery
KEY(SQ) Recursive subquery
Global Index A single index covering all partitions.
Hash Partitioning Enables partitioning of data that does not lend itself to range or list partitioning.
-- to view the value Oracle is using within a specific session for hashing
ADD (HASH)
COALESCE (HASH)
DROP
EXCHANGE
MERGE
MOVE
SPLIT
TRUNCATE
List Partitioning Explicitly controls how rows map to partitions. You do this by specifying a list of discrete values for the partitioning key in the description
partition.
Local Index Separate indexes for each partition. A local index can be unique. However, in order for a local index to be unique, the partitioning key of
https://www.morganslibrary.org/reference/partitions.html#pbsy 1/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
be part of the index's key columns. Unique local indexes are useful for OLTP environments. You cannot explicitly add a partition to a loc
Instead, new partitions are added to local indexes only when you add a partition to the underlying table.
Partition Decompose a table or index into smaller, more manageable pieces, called partitions. Each partition of a table or index must have the sa
attributes, such as column names, datatypes, and constraints, but each partition can have separate physical attributes such as pctfree,
tablespaces.
Partition Key Each row in a partitioned table is unambiguously assigned to a single partition. The partition key is a set of from 1 to 16 columns that de
partition for each row.
Partitioning Pruning Oracle optimizes SQL statements to mark the partitions or subpartitions that need to be accessed and eliminates (prunes) unnecessary
subpartitions from access. Partition pruning is the skipping of unnecessary index and data partitions or subpartitions by a query.
Range Partitioning Maps data to partitions based on ranges of partition key values that you establish for each partition.
Referential Partitioning Data is mapped to partitions based on values defined in a referential constraint (foreign key)
Subpartition Partitions created within partitions. They are just partitions themselves and there is nothing special about them.
Tablespaces
Create demo tablespaces conn sys@pdbdev as sysdba
Table Partitions
Hash Partitioned Table CREATE TABLE hash_part (
prof_history_id NUMBER(10),
person_id NUMBER(10) NOT NULL,
organization_id NUMBER(10) NOT NULL,
record_date DATE NOT NULL,
prof_hist_comments VARCHAR2(2000))
PARTITION BY HASH (prof_history_id)
PARTITIONS 3
STORE IN (part1, part2, part3);
desc hash_part
desc user_tab_partitions
https://www.morganslibrary.org/reference/partitions.html#pbsy 2/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
SELECT partition_name, tablespace_name
FROM user_tab_partitions;
Interval-Numeric Range Partitioned Table CREATE TABLE interval_part (
Also possible are Interval-Hash and Interval-List
person_id NUMBER(5) NOT NULL,
first_name VARCHAR2(30),
last_name VARCHAR2(30))
PARTITION BY RANGE (person_id)
INTERVAL (100) STORE IN (part1) (
PARTITION p1 VALUES LESS THAN (101))
TABLESPACE uwdata;
desc interval_part
https://www.morganslibrary.org/reference/partitions.html#pbsy 3/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
(4, 'Catz', SYSDATE-60);
COMMIT;
COMMIT;
https://www.morganslibrary.org/reference/partitions.html#pbsy 4/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
FROM user_tab_partitions
WHERE table_name = 'HOURLY_INTERVAL';
List Partitioned Table CREATE TABLE list_part(
deptno NUMBER(10),
deptname VARCHAR2(20),
quarterly_sales NUMBER(10,2),
state VARCHAR2(2))
PARTITION BY LIST (state) (
PARTITION q1_northwest VALUES ('OR', 'WA') TABLESPACE part1,
PARTITION q1_southwest VALUES ('AZ', 'CA', 'NM') TABLESPACE part2,
PARTITION q1_northeast VALUES ('NY', 'VT', 'NJ') TABLESPACE part3,
PARTITION q1_southeast VALUES ('FL', 'GA') TABLESPACE part4,
PARTITION q1_northcent VALUES ('MN', 'WI') TABLESPACE part1,
PARTITION q1_southcent VALUES ('OK', 'TX') TABLESPACE part2);
https://www.morganslibrary.org/reference/partitions.html#pbsy 5/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
ALTER SESSION SET SQL_TRACE=FALSE;
Trace file
C:\APP\ORACLE\diag\rdbms\orabase2\orabase2\trace\orabase2_ora_19240_range_part.trc
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing optio
Windows NT Version V6.1 Service Pack 1
CPU : 4 - type 8664, 2 Physical Cores
Process Affinity : 0x0x0000000000000000
Memory (Avail/Total): Ph:2889M/8075M, Ph+PgF:10763M/16148M
Instance name: orabase2
Redo thread mounted by this instance: 1
Oracle process number: 45
Windows thread id: 19240, image: ORACLE.EXE (SHAD)
https://www.morganslibrary.org/reference/partitions.html#pbsy 6/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
PARTITION BY RANGE(num_rows) (
PARTITION num_rows1 VALUES LESS THAN (100) TABLESPACE part1,
PARTITION num_rows2 VALUES LESS THAN (1000) TABLESPACE part2,
PARTITION num_rows3 VALUES LESS THAN (10000) TABLESPACE part3,
PARTITION num_rows4 VALUES LESS THAN (MAXVALUE) TABLESPACE part4);
desc ref_parent
desc json_orders
desc user_tab_cols
https://www.morganslibrary.org/reference/partitions.html#pbsy 7/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
SELECT column_name, virtual_column, data_default
FROM user_tab_cols
WHERE table_name = 'JSON_ORDERS';
COMMIT;
desc vcol_part
desc user_tab_cols
COMMIT;
https://www.morganslibrary.org/reference/partitions.html#pbsy 8/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
EXPLAIN PLAN FOR
SELECT *
FROM vcol_part;
desc orders
desc orders
https://www.morganslibrary.org/reference/partitions.html#pbsy 9/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
ORDER BY 1;
DECLARE
x XMLTYPE;
BEGIN
x := XMLTYPE('<?xml version="1.0" encoding="utf-8"?>
<Order orderId="1" orderRevision="1" orderTimeStamp="01-JAN-2012">
<OrderHeader>
<AlternateIds>
<AlternateId altIdType="SiteId">2</AlternateId>
<AlternateId altIdType="MerchantOrderNumber">Merch</AlternateId>
<AlternateId altIdType="MarketplaceOrderNumber">Place</AlternateId>
<AlternateId altIdType="CustomerReferenceId">Ref</AlternateId>
<AlternateId altIdType="CartId">Cart</AlternateId>
<AlternateId altIdType="SessionId">1</AlternateId>
</AlternateIds>
</OrderHeader>
</Order>');
INSERT INTO orders VALUES (x);
SYS_NC_ROWINFO$
----------------------------------------------------------------------------
<?xml version="1.0" encoding="WINDOWS-1252"?>
<Order orderId="1" orderRevision="1" orderTimeStamp="01-JAN-2012">
<OrderHeader>
<AlternateIds>
<AlternateId altIdType="SiteOrderNumber">123</AlternateId>
<AlternateId altIdType="MerchantOrderNumber">Merch</AlternateId>
<AlternateId altIdType="MarketplaceOrderNumber">Place</AlternateId>
<AlternateId altIdType="CustomerReferenceId">Ref</AlternateId>
<AlternateId altIdType="CartId">Cart</AlternateId>
<AlternateId altIdType="SessionId">123</AlternateId>
</AlternateIds>
</OrderHeader>
</Order>
Partitioning on Exadata Hybrid Columnar ALTER TABLE <table_name>
Compression
MODIFY PARTITION <partition_name>
COMPRESS FOR <compression_level>
STORAGE (cell_flash_cache <KEEP | NONE>);
ALTER TABLE t
MODIFY PARTITION q12012
COMPRESS FOR QUERY HIGH
STORAGE (cell_flash_cache KEEP);
Composite Partitions
Composite Partitioned Table - By Range And conn uwclass/uwclass@pdbdev
Hash
CREATE TABLE composite_rng_hash (
cust_id NUMBER(10),
cust_name VARCHAR2(25),
https://www.morganslibrary.org/reference/partitions.html#pbsy 10/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
amount_sold NUMBER(10,2),
time_id DATE)
PARTITION BY RANGE(time_id)
SUBPARTITION BY HASH(cust_id)
SUBPARTITION TEMPLATE(
SUBPARTITION sp1 TABLESPACE part1,
SUBPARTITION sp2 TABLESPACE part2,
SUBPARTITION sp3 TABLESPACE part3,
SUBPARTITION sp4 TABLESPACE part4) (
PARTITION sales_pre11
VALUES LESS THAN (TO_DATE('01/01/2011','DD/MM/YYYY')),
PARTITION sales_2011
VALUES LESS THAN(TO_DATE('01/01/2012','DD/MM/YYYY')),
PARTITION sales_2012
VALUES LESS THAN(TO_DATE('01/01/2013','DD/MM/YYYY')),
PARTITION sales_2013
VALUES LESS THAN(TO_DATE('01/01/2014','DD/MM/YYYY')),
PARTITION sales_2014
VALUES LESS THAN(TO_DATE('01/01/2015','DD/MM/YYYY')),
PARTITION sales_future
VALUES LESS THAN(MAXVALUE));
desc user_tab_partitions
desc user_tab_subpartitions
desc user_subpartition_templates
https://www.morganslibrary.org/reference/partitions.html#pbsy 11/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
SELECT table_name, partition_name, subpartition_name, num_rows
FROM user_tab_subpartitions;
desc composite_rng_list
desc composite_rng_rng
https://www.morganslibrary.org/reference/partitions.html#pbsy 12/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
SUBPARTITION TEMPLATE(
SUBPARTITION beg VALUES (1,3,5) TABLESPACE part1,
SUBPARTITION mid VALUES (2,4,6) TABLESPACE part2,
SUBPARTITION end VALUES (7,8,9,0) TABLESPACE part3) (
PARTITION west VALUES ('OR', 'WA'),
PARTITION east VALUES ('NY', 'CT'),
PARTITION cent VALUES ('IL', 'MN'));
Composite Partitioned Table - By List And Range CREATE TABLE composite_list_rng (
cust_id NUMBER(10),
cust_name VARCHAR2(25),
cust_state VARCHAR2(2),
time_id DATE)
PARTITION BY LIST(cust_state)
SUBPARTITION BY RANGE (cust_id)
SUBPARTITION TEMPLATE(
SUBPARTITION original VALUES LESS THAN (1001) TABLESPACE part1,
SUBPARTITION acquired VALUES LESS THAN (8001) TABLESPACE part2,
SUBPARTITION recent VALUES LESS THAN (MAXVALUE) TABLESPACE part3) (
PARTITION west VALUES ('OR', 'WA'),
PARTITION east VALUES ('NY', 'CT'),
PARTITION cent VALUES ('IL', 'MN'));
Composite Interval Partition CREATE TABLE t(
sequence_id NUMBER,
reservation_date DATE,
location_code VARCHAR2(5))
PARTITION BY RANGE (reservation_date)
INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
SUBPARTITION BY LIST(location_code)
SUBPARTITION TEMPLATE (
SUBPARTITION spart01 VALUES ('USA'),
SUBPARTITION spart02 VALUES ('IND'),
SUBPARTITION spart03 VALUES ('GER')) (
PARTITION root VALUES LESS THAN (TO_DATE('01-JAN-2015','DD-MON-YYYY')));
Compressed Partitions
Partition Level Compression CREATE TABLE <table_name> (
<column_definitions>) COMPRESS
<partitioning_clauses> [NOCOMPRESS];
CREATE TABLE sales (
saleskey NUMBER,
quarter NUMBER,
product NUMBER,
salesperson NUMBER,
amount NUMBER(12,2),
region VARCHAR2(10)) COMPRESS
PARTITION BY LIST (region) (
PARTITION northwest VALUES ('NORTHWEST'),
PARTITION southwest VALUES ('SOUTHWEST'),
PARTITION northeast VALUES ('NORTHEAST') NOCOMPRESS,
PARTITION southeast VALUES ('SOUTHEAST'),
PARTITION western VALUES ('WESTERN'));
https://www.morganslibrary.org/reference/partitions.html#pbsy 14/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
FROM user_tab_subpartitions
WHERE table_name = 'RANGE_LIST';
https://www.morganslibrary.org/reference/partitions.html#pbsy 15/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
ALTER TABLE hourly_interval SET STORE IN (UWDATA, EXAMPLE, USERS);
https://www.morganslibrary.org/reference/partitions.html#pbsy 16/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
SELECT 3000 + TRUNC((rownum-1)/500,6), TO_CHAR(rownum), RPAD('x',100)
FROM sys.source$ s1, sys.source$ s2
WHERE rownum <= 100000;
COMMIT;
set timing on
set timing on
set timing on
-- repeat again but this time do the following before the exchange
ALTER TABLE range_part MODIFY PRIMARY KEY NOVALIDATE;
ALTER TABLE new_part MODIFY PRIMARY KEY NOVALIDATE;
set timing on
Table created.
SQL> INSERT INTO interval_date (per_id, lname, dob) VALUES (0, 'Hurd', TO_DATE('31-DEC-2013
1 row created.
Table created.
1 row created.
1 row created.
1 row created.
PNAME HIGH_VALUE
---------- --------------------------------------------------------------------------------
P1 TO_DATE(' 2016-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
-- force creation of a partition with the correct high_value for the exchange
SQL> INSERT INTO interval_date VALUES (1, 'DUMMY', SYSDATE);
PNAME HIGH_VALUE
---------- --------------------------------------------------------------------------------
P1 TO_DATE(' 2017-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
SYS_P2614 TO_DATE(' 2017-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
SQL> SELECT *
2 FROM interval_date;
https://www.morganslibrary.org/reference/partitions.html#pbsy 18/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
INTO (PARTITION <first_partition>, PARTITION <second_partition>)
UPDATE GLOBAL INDEXES;
SELECT table_name, partition_name, high_value
FROM user_tab_partitions
WHERE table_name = 'RANGE_PART';
https://www.morganslibrary.org/reference/partitions.html#pbsy 19/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
ADD PARTITION <new_partition_name> VALUES LESS THAN (MAXVALUE)
LOB (<column_name>) STORE AS (TABLESPACE <tablespace_name);
ALTER TABLE print_media_part
ADD PARTITION p3 VALUES LESS THAN (MAXVALUE)
LOB (ad_photo, ad_composite) STORE AS (TABLESPACE part3)
LOB (ad_sourcetext, ad_finaltext) STORE AS (TABLESPACE part4);
Index Partitions
Global Index Creation CREATE INDEX <index_name>
ON <table_name> <column_name_list>;
SELECT i.index_name, i.composite, i.partition_name, i.high_value
FROM user_ind_partitions i, user_tab_partitions t
WHERE i.partition_name = t.partition_name
AND t.table_name = 'RANGE_PART';
SELECT partition_name
FROM user_tab_partitions
WHERE table_name = 'RANGE_PART';
UPDATE range_part
SET organization_id = ROWNUM;
https://www.morganslibrary.org/reference/partitions.html#pbsy 21/24
9/23/2018 Oracle 12c Partitioned and Subpartitioned Tables
Drop Partition
Drop partition from a partitioned table ALTER TABLE DROP PARTITION <partition_name> [UPDATE GLOBAL INDEXES];
SELECT table_name, partition_name
FROM user_tab_partitions;
Demos
Partition Elimination conn scott/tiger@pdbdev
conn scott/tiger@pdbdev
RETURN tspstat;
END part_status;
/
SELECT segment_name
FROM user_segments
WHERE segment_type LIKE '%PARTITION';
SELECT segment_name
FROM user_segments
WHERE segment_type LIKE '%PARTITION';
SELECT index_name
FROM user_part_indexes;
SELECT segment_name
FROM user_segments
WHERE segment_type LIKE '%PARTITION';
SELECT segment_name
FROM user_segments
WHERE segment_type LIKE '%PARTITION';
SELECT segment_name
FROM user_segments
WHERE segment_type LIKE '%PARTITION';
Related Topics
Clusters Range Partitioned
DATAOBJ_TO_PARTITION
DBMS_PCLXUTIL
DBMS_STATS
Hybrid Columnar Compression
Indexes
Secure Files
TBL$OR$IDX$PART$NUM
Tables
Truncate Partition
Update Statements
Built-in Functions
Built-in Packages
This site is maintained by Dan Morgan. Last Updated: 09/23/2018 22:42:21 This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2017 Daniel A. Morgan All Rights Reserved
https://www.morganslibrary.org/reference/partitions.html#pbsy 24/24