partitioning beyond basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. plan_table revisited...

49
Partitioning Beyond the Basics Arup Nanda Starwood Hotels & Resorts White Plains, NY

Upload: others

Post on 06-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

PartitioningBeyond

the BasicsArup Nanda

Starwood Hotels & ResortsWhite Plains, NY

Page 2: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

DynamicBreadArtist

Page 3: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

What’s It

• Divide and Conquer• The Best Thing Since Sliced Bread

Page 4: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Partition

• Partition Elimination• Parallel Execution• Partition Exchange• Deletion• Archiving

Page 5: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Partition Views

View Created asSELECT some fieldsFROM Table1UNION ALLSELECT same fieldsFROM Table2

Table A

Table B

View

Page 6: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Problem

While INSERTINGTable A

Table B

Row1 View

Page 7: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Real Partitions

• Came Out with Oracle 8.0• Range Partitioned Only• Partition Key Column

– VALUES LESS THAN (CONSTANT)

Partition A

Partition B

Main Table

Page 8: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Hash Partitions

• Where Range is Not Practical• Performance

Partition1

Partition2

Row1HashFunc

Page 9: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Composite Partitioning

• Partitions are subdivided• Range-Hash• Range-List Partition1

Partition2

Subpart1

Subpart2

Subpart1

Subpart2

Page 10: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

More Techie

In V$SESSION_WAIT: ‘latch wait’Latch: “cache buffer chain latch”More Accesses to a Segment = Need More

LatchesPartitioning More Segments per Object

Less Accesses per Segment Less “cache buffer chain latch” contention

Page 11: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

List Partitioning

Similar to Range but Values are DiscretePARTITION BY LIST (STATE_CODE)

(

PARTITION P1 VALUES (‘CT’,’NY’),

PARTITION P2 VALUES (‘NJ’),

PARTITION PM VALUES (DEFAULT)

)

Multi-column not supported

Page 12: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Local Index

• Partitioning Schemesof Index and Table areSame

• Easy to Administer• REBUILD part by part

Table

Index

Page 13: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Global Indexes

• Indexes That SpanAcross All Rows of AllPartitions

• Typically Used toEnforce Primary Keys

Index

Oracle 10g: Global Index can be Hash Partitioned

Page 14: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Equi-Partitioning

If a Table and another Tableare partitioned in exactlysame way with the samePartitioning Key

E.g.SALES on ORDER_DATEORDERS on ORDER_DATE

TableB

TableA

Page 15: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

SALES

Page 16: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

QTR1 QTR2 QTR3 DEFAULT

SALES

PARTITIONS

Page 17: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

DEFAULT

QTR1 QTR2 QTR3 DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

SALES

PARTITIONS

SUBPARTITIONS

Page 18: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

DEFAULT

QTR1 QTR2 QTR3 DEFAULTCUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

TAB

ANALYZE

Page 19: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

DEFAULT

QTR1 QTR2 QTR3 DEFAULTCUST3

CUST2

TAB

DEFAULT

CUST3

CUST2

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1CUST1 CUST1

Page 20: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

DEFAULT

QTR1 QTR2 QTR3 DEFAULTCUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

QTR1 QTR2 QTR3 DEFAULTCUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

DEFAULT

CUST3

CUST2

CUST1

TAB

IND

TABLE

INDEX

replace

replace

Page 21: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

DEFAULT

QTR1 QTR2 QTR3 DEFAULTCUST3

CUST2

TAB

DEFAULT

CUST3

CUST2

DEFAULT

CUST3

CUST2

DEFAULT

CUST3

CUST2

DEFAULT

QTR1 QTR2 QTR3 DEFAULTCUST3

CUST2

IND

DEFAULT

CUST3

CUST2

DEFAULT

CUST3

CUST2

DEFAULT

CUST3

CUST2

CUST1

CUST1

TABLE

INDEX

CUST1

CUST1

CUST1 CUST1

CUST1 CUST1

Page 22: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Subpartitioning

Select from a partition bySELECT … FROM TAB1 PARTITION (P1);

Select from a subpartition bySELECT … FROM TAB1 SUBPARTITION (SP1);

Works for Insert/Update/Delete, SQL*LoaderINTO TABLE TAB1 SUBPARTITION (SP1)

And Export, too TABLE=MYTAB1:SP1

Page 23: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Subpartitioning …

DBA_SEGMENTSSELECT * FROM DBA_SEGMENTS

WHERE TABLE_NAME = ‘TAB1’

AND PARTITION_NAME = ‘SP1’

/

SEGMENT_TYPEPARTITION_ID

Page 24: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

SubpartitionsSubpartition Templates

PARTITION BY RANGE (COL1)SUBPARTITION BY HASH (COL2)SUBAPARTITION TEMPLATE(

SUBPARTITION SP1 TABLESPACE T1,SUBPARTITION SP2 TABLESPACE T2

)(

PARTITION P1 VALUES LESS THAN (101),PARTITION P2 VALUES LESS THAN (201),

P1_SP1, P1_SP2, P2_SP1, P2_SP2Can’t Specify Storage (8i)Can specify Storage (9i) DBA_SUBPARTITION_TEMPLATES

Page 25: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Partition Pruning

Partition Based on Date – 1 partition per quarterSELECT … FROM SALES

WHERE ORDER_DATE = ‘1/1/2003’

Will search only the 2003 Q1 partition

ptest1 ins_ptest1; ptest2

Page 26: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Plan_Table Revisited

Relvant ColumnsPARTITION_STARTPARTITION_STOPPARTITION_ID

The step id that decided the partition start and stopFILTER_PREDICATES

The exact condition used to evaluate partitions

Page 27: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Dbms_xplan

dbms_xplan.display (

‘plan_table’,/* plan table name */NULL,/* statement id */

‘BASIC’,/* format */ ‘TYPICAL’,‘ALL’,‘SERIAL’ )

select * from

table (

)

Page 28: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Partition Wise JoinsEqui-partioned tables

SALES partitioned on SALES_DATEREVENUE partitioned on BOOKED_DATESELECT … FROM SALES S, REVENUE RWHERE S.SALES_DATE = R.BOOKED_DATE

REVENUESALES

Partition1Partition2Partition3

Partition1Partition2Partition3

•Ptest3a ptest3b

Page 29: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Partitionwise Join

• Hash Partitioned Tables• Elimination will occur in Equality only, not in

range.

Ptest3ha ptest3hb

Page 30: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Character Values in RangeCREATE TABLE EMPLOYEE (…………)

PARTITION BY RANGE (LAST_NAME)

(

PARTITION P1 VALUES LESS THAN (‘D%’),

PARTITION P2 VALUES LESS THAN (‘M%’),

PARTITION P3 VALUES LESS THAN (‘T%’),

PARTITION PM VALUES LESS THAN (MAXVALUE)

)

ptest4a, ptest4b, ins_ptest4

Page 31: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Multi-column KeysCol1 col2--- ---- ----- 50 50 rec1150 150 rec2 50 150 rec3150 50 rec4101 50 rec5101 101 rec6101 150 rec7201 50 rec8201 101 rec9201 201 rec10

p1p2p2p2p2p2

partition by range (col1,col2)

(partition p1 valuesless than (101, 101),

partition p2 values lessthan (201, 201),

partition pm values lessthan

(maxvalue, maxvalue))

ptab1

p2pmpmpm

Page 32: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Multi-Column Decision

Consider 1st Column

< Boundary

Value

= Boundary

Value

1st Partition Consider 2nd Column

< Boundary

Value

2nd Partition 3rd Partition

Y

N

Y

NY

Page 33: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Deciding Partition Key

• Performance – Elimination/Join, etc.• Backup• Other Manageability

Page 34: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Converting to Partitioning

Oracle Recommended (MetaLink Note 1070693.6)

• Create the partitoned table and Insert• Create Table As Select (CTAS)• Create Small Tables and Exchange Partitions• PROBLEM: Space Requirement and Time

Page 35: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Alternatives

• Oracle 9i Online Redefinition– Small Downtime– Space Needed– Oracle 9i

• Materialized View Method– CREATE MATERIALIZED VIEW MV1 ON

PREBUILT TABLE ….– DROP MATERIALIZED VIEW

Page 36: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Split-Split Method

• Create partitioned table exactly same as sourcetable with one partition with MAXVALUE

• Exchange source table with this partition• Split this partition at the lowest boundary• Split the maximum partition at the next boundary• Repeat till all partitions are created

Page 37: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Example

Table NOPARTCOL1 NUMBERCOL2 VARCHAR2(10)COL3 CHAR(2)

Index IN_NOPART(COL2)

Constraint CK_NOPART(COL3 IS NOT NULL)

Partitioned BY RANGE (COL1)P1 LESS THAN (101)P2 LESS THAN (201)P3 LESS THAN (301)P4 LESS THAN (401)PM … (MAXVALUE)

Table PARTTable, Index, Constraint

Name Change

Page 38: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Summary• Create table part …• Exchange partition pMAX with table NOPART• Split partition pMAX repeatedly• Drop original table nopart• Rename part to no part• Rename index to in_nopart• Rename constraint to ck_nopart

Page 39: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Pros & Cons

• Space Needs – Less• Redo Log Generation – Minimized• Time – Less• Concurrency – Higher• Time – Still High• Concurency – Still Low

Page 40: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Exchanging Partitions

Main TablePartition p1

Subpartition sp1Subpartition sp2Subpartition sp3

),…

Source Tablepartition p1partition p2partition p3

Page 41: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Subpartition Statistics

• DBMS_STATS.GATHER_TABLE_STATS– tabname => ‘MYTABLE’– partname => ‘P1’– granularity =>

• DEFAULT• GLOBAL• PARTITION• SUBPARTITION• ALL

Spart1.sql

Page 42: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Statistics Collection

YESYESYESYESALLYESYESNONOSUBPARTITIONNOYESYESYESDEFAULTNOYESYESNOPARTITIONNONONOYESGLOBAL

SubpartStats

PartitionStats

PartitionGlobal

TableGlobal

Granularity

Page 43: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Parallel Index Rebuilding

– One Query Server per Partition– Slows down processing– Can’t exploit the Parallel Processing Capabilities

q1 q2

QC

q3 q4

Page 44: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Parallel Index Rebuilding

DBMS_PCLXUTIL.BUILD_PART_INDEXjobs_per_batch NUMBER DEFAULT 1procs_per_job NUMBER DEFAULT 1tab_name VARCHAR2idx_name VARCHAR2force_opt BOOLEAN DEFAULT FALSE

Page 45: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

The Rule Based Optimizer

• Invokes CBO• Makes Up Statistics• Don’t Use Partitioning if RBO is Used

Page 46: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Coalesce –vs- Merge

• Coalesce – Hash Partitions• Merge – Range and List

coalesce

merge

Page 47: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Oracle 10g Enhancements

• Partitioned Index Organized Tables (IOT)– List Partitioning Possible– Bitmap Index Support– Global Index Maintenance

• Hash Partitioning of Indexes– On Partitioned Tables– On Index Organized Tables– On Regular Tables

Page 48: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Hash Partitioned Index

Block1 Block2 Block3 Block4Table

Block10 Block11 Block12 Block13Index

Block10 Block11 Block12 Block13IndexPart1 Part2 Part3 Part4

Page 49: Partitioning Beyond Basics · 2009. 3. 4. · ptest1 ins_ptest1; ptest2. Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided

Thank You

Questions?More Resources:

www.proligence.com