oracle partitioning : basis & new features in 12cr2 · infrastructure at your service. oracle...

50
Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2

Upload: lexuyen

Post on 09-Apr-2018

242 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Infrastructure at your Service.

Oracle partitioning :basis & new features in 12cR2

Page 2: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Infrastructure at your Service.

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 2

About me

Joël Cattin

Consultant

+41 79 961 29 65

[email protected]

Page 3: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Experts At Your Service

> Over 50 specialists in IT infrastructure

> Certified, experienced, passionate

Based In Switzerland

> 100% self-financed Swiss company

> Over CHF 8.4 mio. turnover

Leading In Infrastructure Services

> More than 150 customers in CH, D, & F

> Over 50 SLAs dbi FlexService contracted

30.05.2017

dbi servicesWho we are

Page 3

Oracle partitioning : basis & new features in 12cR2

Best Workplace in Switzerland 2017Small Companies 20-49 employeesRank 7

dbi services is hiring ([email protected])

Page 4: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

1. Introduction

2. Partitioning strategies

3. Partitioning features

4. What’s new in 12cR2 ?

5. Conclusion

Agenda

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 4

Page 5: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Few words about partitioningIntroduction

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 5

> Overview

> History

Page 6: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

What is partitioning ?

> Functionality introduced in Oracle 8.0 (1997)

> Logical subdivision of tables (or indexes) into smaller pieces called “partitions”

> Each partition has its own name and its own storage characteristics

> Partition Key : composed of one or more column and used to determine the partition where each row will be stored

> Different strategies : list, range, hash, composite (subpartitions)

Overview

30.05.2017

Introduction

Page 6

Oracle partitioning : basis & new features in 12cR2

Page 7: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Why to use it ?

> Manageability

> Data management at partition level rather than on the entire table

> More flexibility from the DBA side

> Performance

> Faster access to the data (reduce unecessary I/O)

> Availability

> One partition is unavailable ? Others remain available

> Totally transparent for the application side

When to use it ?

> Big tables (> 2GB)

> Tables containing historical data

> Data need to be stored on different storage

Overview

30.05.2017

Introduction

Page 7

Oracle partitioning : basis & new features in 12cR2

Page 8: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

History

30.05.2017

Introduction

Page 8

Oracle partitioning : basis & new features in 12cR2

Oracle version Partitioning features

8.0 Range partitioning

8iHash partitioningComposite Range-Hash partitioning

9iList partitioningComposite Range-List partitioning

10g Index partitioning – Range, Hash and List

11g

Interval partitioningReference partitioningSystem partitioningVirtual column-based partitioningPartition Advisor

12cR1

CASCADE option for exchange and truncate partition operationsMultiple partitions maintenanceONLINE move partition

12cR2 Be patient…

Page 9: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

What can we do ?Partitioning strategies

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 9

> Range partitioning

> List partitioning

> Hash partitioning

> Composite partitioning

Page 10: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Characteristics

> Most popular method

> Often used with the partition key on a date column (historical data)

> Each partition has a VALUES LESS THAN clause (non-inclusive)

> Partition key column can be :

> Time based (date)

> Numerical

> String

Range partitioning

30.05.2017

Partitioning strategies

Page 10

Oracle partitioning : basis & new features in 12cR2

Page 11: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Simple business case

> “I want to store all the sales of the last years on a specific disk”

Range partitioning

30.05.2017

Partitioning strategies

Page 11

Oracle partitioning : basis & new features in 12cR2

SQL> CREATE TABLE sales_range_partition (

product_id NUMBER(6),

customer_id NUMBER,

sale_date DATE

)

PARTITION BY RANGE (sale_date)

(

PARTITION sales_2014 VALUES LESS THAN (TO_DATE('01-JAN-2015','dd-MON-yyyy'))

TABLESPACE tbs_2014,

PARTITION sales_2015 VALUES LESS THAN (TO_DATE('01-JAN-2016','dd-MON-yyyy'))

TABLESPACE tbs_2015,

PARTITION sales_2016 VALUES LESS THAN (TO_DATE('01-JAN-2017','dd-MON-yyyy'))

TABLESPACE tbs_2016);

Page 12: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Check partitions

Partitions must be defined before the data insertion

Or…

Range partitioning

30.05.2017

Partitioning strategies

Page 12

Oracle partitioning : basis & new features in 12cR2

SQL> SELECT TABLE_NAME, PARTITION_NAME, PARTITION_POSITION FROM

DBA_TAB_PARTITIONS WHERE TABLE_NAME ='SALES_RANGE_PARTITION';

TABLE_NAME PARTITION_NAME PARTITION_POSITION

------------------------------ ------------------------------ ------------------

SALES_RANGE_PARTITION SALES_2014 1

SALES_RANGE_PARTITION SALES_2015 2

SALES_RANGE_PARTITION SALES_2016 3

SQL> INSERT INTO SALES_RANGE_PARTITION VALUES(1,1,'08-FEB-2017');

INSERT INTO SALES_RANGE_PARTITION VALUES(1,1,'08-FEB-2017')

*

ERROR at line 1:

ORA-14400: inserted partition key does not map to any partition

Page 13: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

> Create a “MAXVALUE” partition

Catch-all for values that exceed all specified ranges.

> Configure interval partitioning

Range partitioning

30.05.2017

Partitioning strategies

Page 13

Oracle partitioning : basis & new features in 12cR2

SQL> ALTER TABLE SALES_RANGE_PARTITION ADD PARTITION sales_other VALUES LESS THAN

(MAXVALUE);

SQL> CREATE TABLE sales_range_partition (

product_id NUMBER(6),

customer_id NUMBER,

sale_date DATE

)

PARTITION BY RANGE (sale_date) INTERVAL(NUMTOYMINTERVAL(1, 'YEAR'))

(

PARTITION sales_2014 VALUES LESS THAN (TO_DATE('01-JAN-2015','dd-MON-yyyy'))

TABLESPACE tbs_2014,

PARTITION sales_2015 VALUES LESS THAN (TO_DATE('01-JAN-2016','dd-MON-yyyy'))

TABLESPACE tbs_2015,

PARTITION sales_2016 VALUES LESS THAN (TO_DATE('01-JAN-2017','dd-MON-yyyy'))

TABLESPACE tbs_2016);

Page 14: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Characteristics

> Use a list of values as partition key

> Can group and organize unordered and unrelated data

> DEFAULT partition for data that don’t correspond to any partition

List partitioning

30.05.2017

Partitioning strategies

Page 14

Oracle partitioning : basis & new features in 12cR2

Page 15: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Simple business case

> “I want to group and store the sales by country”

List partitioning

30.05.2017

Partitioning strategies

Page 15

Oracle partitioning : basis & new features in 12cR2

SQL> CREATE TABLE sales_list_partition (

product_id NUMBER(6),

quantity_sold INTEGER,

sales_city VARCHAR(100)

)

PARTITION BY LIST (sales_city)

(

PARTITION sales_CH VALUES ('DELEMONT','BASEL','ZURICH','NYON'),

PARTITION sales_DE VALUES ('BERLIN','MUNICH','NUREMBERG'),

PARTITION sales_FR VALUES ('PARIS','MULHOUSE','BORDEAUX'),

PARTITION sales_DEFAULT VALUES (DEFAULT));

Page 16: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Check partitions

Data insertion

List partitioning

30.05.2017

Partitioning strategies

Page 16

Oracle partitioning : basis & new features in 12cR2

SQL> SELECT TABLE_NAME, PARTITION_NAME, PARTITION_POSITION FROM

DBA_TAB_PARTITIONS WHERE TABLE_NAME ='SALES_LIST_PARTITION';

TABLE_NAME PARTITION_NAME PARTITION_POSITION

------------------------------ -------------------- ------------------

SALES_LIST_PARTITION SALES_CH 1

SALES_LIST_PARTITION SALES_DE 2

SALES_LIST_PARTITION SALES_FR 3

SALES_LIST_PARTITION SALES_DEFAULT 4

SQL> INSERT INTO SALES_LIST_PARTITION VALUES (1, 5, 'BASEL');

SQL> SELECT * FROM SALES_LIST_PARTITION PARTITION (SALES_CH);

PRODUCT_ID QUANTITY_SOLD SALES_CITY

---------- ------------- -----------

1 5 BASEL

SQL> INSERT INTO SALES_LIST_PARTITION VALUES (1, 5, 'MILAN');

SQL> SELECT * FROM SALES_LIST_PARTITION PARTITION (SALES_DEFAULT);

PRODUCT_ID QUANTITY_SOLD SALES_CITY

---------- ------------- -----------

1 5 MILAN

Page 17: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Characteristics

> Useful when other partitioning strategies are not appropriate

> Data distribution doesn’t need to respect a business constraint

> Hash function is applied to the partition key column

> Data distribution is balanced between all partitions (no control)

Hash partitioning

30.05.2017

Partitioning strategies

Page 17

Oracle partitioning : basis & new features in 12cR2

Page 18: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Simple business case

> “The product table is too big. I want to partition it and I don't care about where the data goes.”

Hash partitioning

30.05.2017

Partitioning strategies

Page 18

Oracle partitioning : basis & new features in 12cR2

SQL> CREATE TABLE product(

product_id NUMBER(6),

product_name VARCHAR2(50)

)

PARTITION BY HASH (product_id)

(PARTITION p1 TABLESPACE tbs1,

PARTITION p2 TABLESPACE tbs2,

PARTITION p3 TABLESPACE tbs3,

PARTITION p4 TABLESPACE tbs4);

SQL> CREATE TABLE product_hash_partition2(

product_id NUMBER(6),

product_name VARCHAR2(50))

PARTITION BY HASH (product_id) PARTITIONS 2;

SQL> SELECT partition_name, tablespace_name FROM dba_tab_partitions WHERE table_name

=('PRODUCT_HASH_PARTITION2');

PARTITION_NAME TABLESPACE_NAME

---------------------------------------- ------------------------------

SYS_P4547 SYSTEM

SYS_P4548 SYSTEM

Page 19: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

What is it ?

> Combination of two partitioning methods (two levels)

> Each sub-partition is a separate segment

Existing strategies

> Range-Range

> Range-Hash

> Range-List

> List-Range

> List-Hash

> List-List

> Hash-Range

> Hash-Hash

> Hash-List

Composite partitioning

30.05.2017

Partitioning strategies

Page 19

Oracle partitioning : basis & new features in 12cR2

Page 20: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Example

Composite partitioning

30.05.2017

Partitioning strategies

Page 20

Oracle partitioning : basis & new features in 12cR2

CREATE TABLE sales_composite (

product_id NUMBER(6),

customer_id NUMBER,

sale_date DATE,

sale_city VARCHAR2(50))

PARTITION BY RANGE (sale_date)

SUBPARTITION BY LIST (sale_city)

(PARTITION sales_2014 VALUES LESS THAN (TO_DATE('01-JAN-2015','dd-MON-yyyy'))

(SUBPARTITION sales_2014_CH VALUES ('DELEMONT','BASEL','ZURICH','NYON'),

SUBPARTITION sales_2014_DE VALUES ('BERLIN','MUNICH','NUREMBERG'),

SUBPARTITION sales_2014_FR VALUES ('PARIS','MULHOUSE','BORDEAUX')),

PARTITION sales_2015 VALUES LESS THAN (TO_DATE('01-JAN-2016','dd-MON-yyyy'))

(SUBPARTITION sales_2015_CH VALUES ('DELEMONT','BASEL','ZURICH','NYON'),

SUBPARTITION sales_2015_DE VALUES ('BERLIN','MUNICH','NUREMBERG'),

SUBPARTITION sales_2015_FR VALUES ('PARIS','MULHOUSE','BORDEAUX')),

PARTITION sales_2016 VALUES LESS THAN (TO_DATE('01-JAN-2017','dd-MON-yyyy'))

(SUBPARTITION sales_2016_CH VALUES ('DELEMONT','BASEL','ZURICH','NYON'),

SUBPARTITION sales_2016_DE VALUES ('BERLIN','MUNICH','NUREMBERG'),

SUBPARTITION sales_2016_FR VALUES ('PARIS','MULHOUSE','BORDEAUX'))

);

Page 21: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Enhance partitioning strategiesPartitioning features

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 21

> Partition pruning

> Virtual column partitioning

Page 22: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

What is it ?

> Simplest means to improve performances using partitioning

> Oracle performs operations only on partitions that are relevant to the statement

> Eliminate unneeded partitions

> Also available for composite partitioned tables

Partition pruning

30.05.2017

Partitioning features

Page 22

Oracle partitioning : basis & new features in 12cR2

P_SALES_2014

P_SALES_2015

P_SALES_2016

SELECT * FROM sales WHERE

sale_date = '02-MAY-2015';

SALES table

Page 23: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

How does it work ?

> The optimizer analyzes FROM and WHERE clauses in SQL statements

> The optimizer use predicates for pruning

Limitations

> For Range and List partitioning

> Equality (WHERE… =, <[=], >[=] …)

> Range (WHERE…BETWEEN…AND…)

> IN-list (WHERE…IN…)

> LIKE (WHERE…LIKE…)

> For Hash partitioning

> Equality (WHERE… =, <[=], >[=] …)

> IN-list (WHERE…IN…)

Partition pruning

30.05.2017

Partitioning features

Page 23

Oracle partitioning : basis & new features in 12cR2

Page 24: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Example without pruning

> Usage of a function on the partition key filter predicate

Partition pruning

30.05.2017

Partitioning features

Page 24

Oracle partitioning : basis & new features in 12cR2

SQL> select plan_table_output from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT

-------------------------------------

SQL_ID 572pnngc9xjbw, child number 1

-------------------------------------

SELECT customer_id FROM sales_range_partition WHERE to_char(sale_date,'yyyy')='2015'

Plan hash value: 2968405107

-------------------------------------------------------------------------------------------------------------

| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |

-------------------------------------------------------------------------------------------------------------

| 0 | SELECT STATEMENT | | | | 854 (100)| | | |

PLAN_TABLE_OUTPUT

-------------------------------------------------------------------------------------------------------------

| 1 | PARTITION RANGE ALL| | 333K| 3581K| 854 (5)| 00:00:01 | 1 | 4 |

|* 2 | TABLE ACCESS FULL | SALES_RANGE_PARTITION | 333K| 3581K| 854 (5)| 00:00:01 | 1 | 4 |

-------------------------------------------------------------------------------------------------------------

Page 25: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Example with pruning

> Usage of BETWEEN…AND predicate

Partition pruning

30.05.2017

Partitioning features

Page 25

Oracle partitioning : basis & new features in 12cR2

SQL> select plan_table_output from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT

-------------------------------------

SQL_ID 3um6bnzk9r21q, child number 0

-------------------------------------

SELECT customer_id FROM sales_range_partition WHERE sale_date BETWEEN '01-JAN-2015' AND '31-DEC-2015'

Plan hash value: 2536827120

----------------------------------------------------------------------------------------------------------------

| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |

----------------------------------------------------------------------------------------------------------------

| 0 | SELECT STATEMENT | | | | 279 (100)| | | |

PLAN_TABLE_OUTPUT

----------------------------------------------------------------------------------------------------------------

| 1 | PARTITION RANGE SINGLE| | 333K| 3581K| 279 (2)| 00:00:01 | 2 | 2 |

|* 2 | TABLE ACCESS FULL | SALES_RANGE_PARTITION | 333K| 3581K| 279 (2)| 00:00:01 | 2 | 2 |

----------------------------------------------------------------------------------------------------------------

Page 26: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Virtual column

> Expression based on one (or more) existing columns in a table

> Stored as metadata -> don’t use physical space

> Can be used as a Partition Key

> Useful where existing columns are not relevant Partition Key

Example

Virtual column partitioning

30.05.2017

Partitioning features

Page 26

Oracle partitioning : basis & new features in 12cR2

SQL> desc shop;

Name Null? Type

------------------ -------- ---------------------

SHOP_REF VARCHAR2(50)

SHOP_NAME VARCHAR2(50)

SQL> SELECT * FROM shop;

SHOP_REF SHOP_NAME

-------------------- --------------------

CH-123456 Sport shop

DE-654321 Shoes shop

FR-024680 IT shop

Page 27: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Business requirement

> “I want to partition this table by country”

Virtual column partitioning

30.05.2017

Partitioning features

Page 27

Oracle partitioning : basis & new features in 12cR2

CREATE TABLE shop_part (

shop_ref VARCHAR2(50),

shop_name VARCHAR2(50),

country AS (case

when substr(shop_ref,1,2) = 'CH' then 'Switzerland'

when substr(shop_ref,1,2) = 'DE' then 'Deutschland'

when substr(shop_ref,1,2) = 'FR' then 'France'

end))

partition by list (country) (

partition p_CH values ('Switzerland'),

partition p_DE values ('Deutschland'),

partition p_FR values ('France'));

Page 28: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Check partitions

Check data

Virtual column partitioning

30.05.2017

Partitioning features

Page 28

Oracle partitioning : basis & new features in 12cR2

SQL> SELECT * FROM shop_part PARTITION (P_CH);

SHOP_REF SHOP_NAME COUNTRY

-------------------- -------------------- -----------

CH-123456 Sport shop Switzerland

SQL> SELECT * FROM shop_part;

SHOP_REF SHOP_NAME COUNTRY

-------------------- -------------------- -----------

CH-123456 Sport shop Switzerland

DE-654321 Shoes shop Deutschland

FR-024680 IT shop France

SQL> SELECT TABLE_NAME, PARTITION_NAME, PARTITION_POSITION, HIGH_VALUE FROM

DBA_TAB_PARTITIONS WHERE TABLE_NAME ='SHOP_PART';

TABLE_NAME PARTITION_NAME PARTITION_POSITION HIGH_VALUE

-------------------- -------------------- ------------------ --------------------

SHOP_PART P_CH 1 'Switzerland'

SHOP_PART P_DE 2 'Deutschland'

SHOP_PART P_FR 3 'France'

Page 29: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Some new functionalitiesWhat’s new in 12cR2 ?

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 29

> Multi-column list partitioning

> Auto-list partitioning

> Read-only partitions

> Filtered partition maintenance operations

> Online operations

Page 30: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Until today

> Only available with RANGE partitioning

Characteristics

> Data is organized in lists of multiple values (up to 16 columns)

> Partition key contains more than 1 value

> Individual partitions can contain sets of multiple values

> Supported by partitions and subpartitions

> Each set of partitioning keys must be unique

Multi-column list partitioning

30.05.2017

What’s new in 12cR2 ?

Page 30

Oracle partitioning : basis & new features in 12cR2

Page 31: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Syntax

Check partitions

Multi-column list partitioning

30.05.2017

What’s new in 12cR2 ?

Page 31

Oracle partitioning : basis & new features in 12cR2

CREATE TABLE cars(

car_make VARCHAR2(30),

car_model VARCHAR2(30)

)

PARTITION BY LIST (car_make, car_model)

(PARTITION P1 VALUES ('Ford','Focus'),

PARTITION P_DEFAULT VALUES (DEFAULT));

SQL> SELECT partitioning_type, partition_count, partitioning_key_count FROM

dba_part_tables WHERE table_name = 'CARS';

PARTITION PARTITION_COUNT PARTITIONING_KEY_COUNT

--------- --------------- ----------------------

LIST 2 2

SQL> SELECT partition_name, high_value FROM dba_tab_partitions WHERE table_name = 'CARS';

PARTITION_NAME HIGH_VALUE

-------------------- ------------------------------

P1 ( 'Ford', 'Focus' )

P_DEFAULT DEFAULT

Page 32: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Auto-list ?

> Extension of LIST partitioning

> Automatic creation of partitions for new values

> Maintenance is simplified

> No notion of DEFAULT partition

> Also available with subpartitions (since 12.2.0.2)

> Using multiple partition keys is also possible

Auto-list partitioning

30.05.2017

What’s new in 12cR2 ?

Page 32

Oracle partitioning : basis & new features in 12cR2

Page 33: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Syntax

Check partitions

Auto-list partitioning

30.05.2017

What’s new in 12cR2 ?

Page 33

Oracle partitioning : basis & new features in 12cR2

SQL> CREATE TABLE city(

city_zip NUMBER(5),

city_name VARCHAR2(30)

)

PARTITION BY LIST (city_name) AUTOMATIC

(PARTITION p_delemont VALUES ('Delemont'));

SQL> SELECT partition_name, high_value, partition_position FROM

dba_tab_partitions WHERE table_name = 'CITY';

PARTITION_NAME HIGH_VALUE PARTITION_POSITION

-------------------- ------------------------------ ------------------

P_DELEMONT 'Delemont' 1

New keyword

Page 34: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Data insertion

Check partitions

Auto-list partitioning

30.05.2017

What’s new in 12cR2 ?

Page 34

Oracle partitioning : basis & new features in 12cR2

SQL> INSERT INTO city VALUES (2800, 'Delemont');

SQL> INSERT INTO city VALUES (4001, 'Basel');

SQL> INSERT INTO city VALUES (8001, 'Zurich');

SQL> INSERT INTO city VALUES (1000, null);

SQL> SELECT partition_name, high_value, partition_position FROM

dba_tab_partitions WHERE table_name = 'CITY';

PARTITION_NAME HIGH_VALUE PARTITION_POSITION

-------------------- -------------------- ------------------

P_DELEMONT 'Delemont' 1

SYS_P5004 'Basel' 2

SYS_P5005 'Zurich' 3

SYS_P5006 '' 4

SQL> SELECT partitioning_type, autolist, partition_count FROM dba_part_tables

WHERE table_name = 'CITY';

PARTITIONING_TYPE AUT PARTITION_COUNT

------------------------------ --- ---------------

LIST YES 4

Page 35: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Evolving to auto-list

Requirement

> No DEFAULT partition

Auto-list partitioning

30.05.2017

What’s new in 12cR2 ?

Page 35

Oracle partitioning : basis & new features in 12cR2

SQL> ALTER TABLE cars SET AUTOMATIC;

ALTER TABLE cars SET AUTOMATIC

*

ERROR at line 1:

ORA-14852: SET [SUB]PARTITIONING AUTOMATIC is not legal on this table.

SQL> ALTER TABLE cars DROP PARTITION (P_DEFAULT);

Table altered.

SQL> ALTER TABLE cars SET AUTOMATIC;

Table altered.

Page 36: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Until today

> Only available on tablespace and table level

Characteristics

> Expand read-only functionality from table level to partitions level

> Partitions and subpartitons can be set to read-only or read-write

> Structural DDL for a table still permitted

Read-only partitions

30.05.2017

What’s new in 12cR2 ?

Page 36

Oracle partitioning : basis & new features in 12cR2

Page 37: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Syntax

Data insertion

Read-only partitions

30.05.2017

What’s new in 12cR2 ?

Page 37

Oracle partitioning : basis & new features in 12cR2

CREATE TABLE sales(

sales_product VARCHAR2(30),

sales_date DATE

) READ WRITE

PARTITION BY RANGE (sales_date)

(

PARTITION P_2013 VALUES LESS THAN (TO_DATE('01-JAN-2014','dd-MON-yyyy')) READ ONLY,

PARTITION P_2014 VALUES LESS THAN (TO_DATE('01-JAN-2015','dd-MON-yyyy')) READ ONLY,

PARTITION P_2015 VALUES LESS THAN (TO_DATE('01-JAN-2016','dd-MON-yyyy')) READ ONLY,

PARTITION P_2016 VALUES LESS THAN (TO_DATE('01-JAN-2017','dd-MON-yyyy'))

);

SQL> INSERT INTO sales VALUES ('SHIRT', '02-MAY-2013');

INSERT INTO sales VALUES ('SHIRT', '02-MAY-2013')

*

ERROR at line 1:

ORA-14466: Data in a read-only partition or subpartition cannot be modified.

SQL> INSERT INTO sales VALUES ('SHOES', '29-MAR-2016');

1 row created.

Page 38: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Partition maintenance -> always to the whole partition

> Move a partition

> Split a partition

> …

For what ?

> Combine data maintenance and partition maintenance

Filtered partition maintenance operations

30.05.2017

What’s new in 12cR2 ?

Page 38

Oracle partitioning : basis & new features in 12cR2

Page 39: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Check partitions

Simple business case

> “I want to delete all orders dated of 2013, but keep the one that are still open and store them in an other tablespace”

Filtered partition maintenance operations

30.05.2017

What’s new in 12cR2 ?

Page 39

Oracle partitioning : basis & new features in 12cR2

SQL> SELECT PARTITION_NAME, HIGH_VALUE, TABLESPACE_NAME FROM DBA_TAB_PARTITIONS WHERE

TABLE_NAME = 'ORDERS';

PARTITION_NAME HIGH_VALUE TABLESPACE_NAME

-------------------- ------------------------------ ------------------------

P_2013 2013 USERS

P_2014 2014 USERS

P_2015 2015 USERS

P_2016 2016 USERS

ALTER TABLE orders MOVE PARTITION p_2013 TABLESPACE archive INCLUDING ROWS WHERE

order_status = 'OPEN' ONLINE;

SQL> SELECT * FROM orders;

ORDER_ID ORDER_PRODUCT ORDER_STATUS ORDER_YEAR

---------- ------------------------------ ------------------------------ ----------

1 SHOES CLOSE 2013

4 SHOES OPEN 2013

2 SOCKS CLOSE 2015

3 TSHIRT OPEN 2016

Page 40: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

What happened ?

> Partition p_2013 before the move

> Partition p_2013 after the move

The data excluded of the filter are deleted !

Filtered partition maintenance operations

30.05.2017

What’s new in 12cR2 ?

Page 40

Oracle partitioning : basis & new features in 12cR2

SQL> SELECT * FROM orders PARTITION (p_2013);

ORDER_ID ORDER_PRODUCT ORDER_STATUS ORDER_YEAR

---------- ----------------- ------------- ----------

1 SHOES CLOSE 2013

4 SHOES OPEN 2013

SQL> SELECT * FROM orders PARTITION (p_2013);

ORDER_ID ORDER_PRODUCT ORDER_STATUS ORDER_YEAR

---------- ----------------- ------------- ----------

4 SHOES OPEN 2013

Page 41: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Limitations

> Maintenance operations

> MOVE

> SPLIT

> MERGE

> Filter conditions

> Limited to the partitioned table itself

> Any reference to other tables (JOIN) is not allowed

Filtered partition maintenance operations

30.05.2017

What’s new in 12cR2 ?

Page 41

Oracle partitioning : basis & new features in 12cR2

Page 42: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Online partitioning DDL operations

> 12cR1

> Move partition

> 12cR2

> Split partition

> Convert non-partitioned table to partitioned table

Online operations

30.05.2017

What’s new in 12cR2 ?

Page 42

Oracle partitioning : basis & new features in 12cR2

Page 43: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Split partition

Online operationsWhat’s new in 12cR2 ?

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 43

Page 44: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Conversion of a non-partitioned table to a partitioned table

“Old” way -> DBMS_REDEFINITION (since 9i)

1. Verify that the table is a candidate for redefinition> DBMS_REDEFINITION.CAN_REDEF_TABLE

2. Create an interim partitioned table

3. Start the redefinition> DBMS_REDEFINITION.START_REDEF_TABLE

4. Copy dependent objects to the new table (grants, constraints, …)> DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS

5. Synchronize the interim table (optional)> DBMS_REDEFINITION.SYNC_INTERIM_TABLE

6. Complete the redefinition> DBMS_REDEFINITION.FINISH_REDEF_TABLE

Online operations

30.05.2017

What’s new in 12cR2 ?

Page 44

Oracle partitioning : basis & new features in 12cR2

Page 45: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Conversion of a non-partitioned table to a partitioned table

> One shot

> In-place conversion

> No business interruption

Online operations

30.05.2017

What’s new in 12cR2 ?

Page 45

Oracle partitioning : basis & new features in 12cR2

Page 46: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Conversion of a non-partitioned table to a partitioned table

Online operationsWhat’s new in 12cR2 ?

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 46

Page 47: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Conversion of a non-partitioned table to a partitioned table

> What about indexes ?

> By default> Prefixed* indexes local partitioned indexes

> Non-prefixed indexes global non-partitioned indexes

> With the UPDATE INDEX clause> You can change the partition state of an index (partitioned or not)

> You can change the storage properties (move it to another tablespace)

> You can NOT change the columns of an index

> You can NOT change the uniqueness of an index

* Prefixed means that the partition key column is in the index definition :

Ex. : Table partitioned on column1 -> prefixed-index contains [column1, columnX, …]

Online operations

30.05.2017

What’s new in 12cR2 ?

Page 47

Oracle partitioning : basis & new features in 12cR2

Page 48: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Conclusion

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 48

Page 49: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Partitioning can improve

> Manageability

> Performance

> Availability

Partitioning still evolving

> More and more business requirements are met

Partitioning is an option

> Available in Enterprise Edition

Conclusion

30.05.2017Oracle partitioning : basis & new features in 12cR2Page 49

per Named User Plus per Processor

1 year $ 46.00 $ 2’300.00

Perpetual $ 230.00 $ 11’500.00

Page 50: Oracle partitioning : basis & new features in 12cR2 · Infrastructure at your Service. Oracle partitioning : basis & new features in 12cR2 30.05.2017 Page 2 About me Joël Cattin

Infrastructure at your Service.

30.05.2017

We look forward to working with you!

Page 50

Oracle partitioning : basis & new features in 12cR2

Joël CattinConsultant

+41 79 961 29 65

[email protected]

Any questions? Please do ask