Download presentation
Presentation is loading. Please wait.
Published byKathleen Barber Modified over 9 years ago
1
prligence Empowering Intelligence Partitioning Demystified Arup Nanda Proligence, Inc. Norwalk, CT
2
prligence Empowering Intelligence What’s It Divide and Conquer The Best Thing Since Sliced Bread
3
prligence Empowering Intelligence Partition Views View Created as SELECT some fields FROM Table1 UNION ALL SELECT same fields FROM Table2 Table A Table B View
4
prligence Empowering Intelligence Problem While INSERTING Table A Table B Row1 View
5
prligence Empowering Intelligence Real Partitions Came Out with Oracle 8.0 Range Partitioned Only Partition Key Column –VALUES LESS THAN (CONSTANT) Partition A Partition B Main Table
6
prligence Empowering Intelligence Hash Partitions Where Range is Not Practical Performance Partition1 Partition2 Row1 Hash Func
7
prligence Empowering Intelligence Composite Partitioning Partitions are subdivided Range-Hash Range-List Partition1 Partition2 Subpart1 Subpart2 Subpart1 Subpart2
8
prligence Empowering Intelligence List Partitioning Similar to Range but Values are Discrete PARTITION BY LIST (STATE_CODE) ( PARTITION P1 VALUES (‘CT’,’NY’), PARTITION P2 VALUES (‘NJ’), PARTITION PM VALUES (DEFAULT) ) Multi-column not supported
9
prligence Empowering Intelligence Local Index Partitioning Schemes of Index and Table are Same Easy to Administer REBUILD part by part Table Index
10
prligence Empowering Intelligence Global Indexes Indexes That Span Across All Rows of All Partitions Typically Used to Enforce Primary Keys Index
11
prligence Empowering Intelligence Equi-Partitioning If a Table and another Table are partitioned in exactly same way with the same Partitioning Key E.g. SALES on ORDER_DATE ORDERS on ORDER_DATE TableB TableA
12
prligence Empowering Intelligence SALES
13
prligence Empowering Intelligence QTR1QTR2QTR3DEFAULT SALES PARTITIONS
14
prligence Empowering Intelligence DEFAULT QTR1QTR2QTR3DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 SALES PARTITIONS SUBPARTITIONS
15
prligence Empowering Intelligence DEFAULT QTR1QTR2QTR3DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 TAB ANALYZE
16
prligence Empowering Intelligence DEFAULT QTR1QTR2QTR3DEFAULT CUST3 CUST2 TAB DEFAULT CUST3 CUST2 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1
17
prligence Empowering Intelligence DEFAULT QTR1QTR2QTR3DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT QTR1QTR2QTR3DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 DEFAULT CUST3 CUST2 CUST1 TAB IND TABLE INDEX replace
18
prligence Empowering Intelligence DEFAULT QTR1QTR2QTR3DEFAULT CUST3 CUST2 TAB DEFAULT CUST3 CUST2 DEFAULT CUST3 CUST2 DEFAULT CUST3 CUST2 DEFAULT QTR1QTR2QTR3DEFAULT CUST3 CUST2 IND DEFAULT CUST3 CUST2 DEFAULT CUST3 CUST2 DEFAULT CUST3 CUST2 CUST1 TABLE INDEX CUST1
19
prligence Empowering Intelligence Subpartitioning Select from a partition by SELECT … FROM TAB1 PARTITION (P1); Select from a subpartition by SELECT … FROM TAB1 SUBPARTITION (SP1); Works for Insert/Update/Delete, SQL*Loader INTO TABLE TAB1 SUBPARTITION (SP1) And Export, too TABLE=MYTAB1:SP1
20
prligence Empowering Intelligence Subpartitioning … DBA_SEGMENTS SELECT * FROM DBA_SEGMENTS WHERE TABLE_NAME = ‘TAB1’ AND PARTITION_NAME = ‘SP1’ / SEGMENT_TYPE
21
prligence Empowering Intelligence Subpartitions Subpartition 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_SP2 Can’t Specify Storage (8i) Can specify Storage (9i) DBA_SUBPARTITION_TEMPLATES
22
prligence Empowering Intelligence Partition Pruning Partition Based on Date – 1 partition per quarter SELECT … FROM SALES WHERE ORDER_DATE = ‘1/1/2003’ Will search only the 2003 Q1 partion ptest1 ins_ptest1; ptest2
23
prligence Empowering Intelligence Plan_Table Revisited Relvant Columns PARTITION_START PARTITION_STOP PARTITION_ID The step id that decided the partition start and stop FILTER_PREDICATES The exact condition used to evaluate partitions
24
prligence Empowering Intelligence Dbms_xplan dbms_xplan.display( ‘plan_table’, /* plan table name */ NULL, /* statement id */ ‘BASIC’, /* format */ ‘TYPICAL’,‘ALL’,‘SERIAL’) select * from table ( )
25
prligence Empowering Intelligence Partition Wise Joins Equi-partioned tables SALES partitioned on SALES_DATE REVENUE partitioned on BOOKED_DATE SELECT … FROM SALES S, REVENUE R WHERE S.SALES_DATE = R.BOOKED_DATE REVENUESALES Partition1 Partition2 Partition3 Partition1 Partition2 Partition3 Ptest3a ptest3b
26
prligence Empowering Intelligence Partitionwise Join Hash Partitioned Tables Elimination will occur in Equality only, not in range. Ptest3ha ptest3hb
27
prligence Empowering Intelligence Character Values in Range CREATE 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
28
prligence Empowering Intelligence Multi-column Keys Col1 col2 --- ---- ----- 50 50 rec1 150 150 rec2 50 150 rec3 150 50 rec4 101 50 rec5 101 101 rec6 101 150 rec7 201 50 rec8 201 101 rec9 201 201 rec10 p1 p2 partition by range (col1, col2) (partition p1 values less than (101, 101), partition p2 values less than (201, 201), partition pm values less than (maxvalue, maxvalue)) ptab1 p2 pm
29
prligence Empowering Intelligence Multi-Column Decision Consider 1st Column Consider 1st Column < Boundary Value < Boundary Value = Boundary Value = Boundary Value 1st Partition Consider 2nd Column Consider 2nd Column < Boundary Value < Boundary Value 2nd Partition 3rd Partition Y N Y N Y
30
prligence Empowering Intelligence 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
31
prligence Empowering Intelligence Alternatives Oracle 9i Online Redefinition –Small Downtime –Space Needed –Oracle 9i
32
prligence Empowering Intelligence Split-Split Method Create partitioned table exactly same as source table 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
33
prligence Empowering Intelligence Example Table NOPART COL1 NUMBER COL2 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 PART Table, Index, Constraint Name Change
34
prligence Empowering Intelligence 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
35
prligence Empowering Intelligence Pros & Cons Space Needs – Less Redo Log Generation – Minimized Time – Less Concurrency – Higher Time – Still High Concurency – Still Low
36
prligence Empowering Intelligence Exchanging Partitions Main Table Partition p1 Subpartition sp1 Subpartition sp2 Subpartition sp3 ), … Source Table partition p1 partition p2 partition p3
37
prligence Empowering Intelligence Subpartition Statistics DBMS_STATS.GATHER_TABLE_STATS –tabname => ‘MYTABLE’ –partname => ‘P1’ – granularity => DEFAULT GLOBAL PARTITION SUBPARTITION ALL Spart1.sql
38
prligence Empowering Intelligence Statistics Collection GranularityTable Global Partition Global Partition Stats Subpart Stats GLOBALYESNO PARTITIONNOYES NO DEFAULTYES NO SUBPARTITIONNO YES ALLYES
39
prligence Empowering Intelligence Parallel Index Rebuilding –One Query Server per Partition –Slows down processing –Can’t exploit the Parallel Processing Capabilities q1q2 QC q3q4
40
prligence Empowering Intelligence Parallel Index Rebuilding DBMS_PCLXUTIL.BUILD_PART_INDEX jobs_per_batchNUMBER DEFAULT 1 procs_per_job NUMBER DEFAULT 1 tab_name VARCHAR2 idx_name VARCHAR2 force_opt BOOLEAN DEFAULT FALSE
41
prligence Empowering Intelligence The Rule Based Optimizer Invokes CBO Makes Up Statistics Don’t Use Partitioning if RBO is Used
42
prligence Empowering Intelligence Coalesce –vs- Merge Coalesce – Hash Partitions Merge – Range and List coalesce merge
43
prligence Empowering Intelligence A Real Life Case Sales Datawarehouse Several Customers Several Quarters Data Coming from Customers Irregular Frequency Data Comes Often Late
44
prligence Empowering Intelligence Datawarehouse Cust1 Cust2 Cust3 Cust4 Cust10 Cust9 Cust8 Cust7 Cust11? Cust5Cust6 DB3 DB6 DB4DB5 DB1DB2
45
prligence Empowering Intelligence Detail Table Detail Table Summary Table Summary Table Detail Table Detail Table CUST2 Problem of Irregular Data
46
prligence Empowering Intelligence CUST1 Summary tables Summary tables DETAIL TABLES CUST2 CUST1 aggregation
47
prligence Empowering Intelligence Problems Data Coming from Customers Irregularly Need to Refresh the Summary Tables when New Data Arrives Quarters are Added Continuosly Archival Requirements Vary Across Customers Quick Retrieval of Archival Needed
48
prligence Empowering Intelligence Problems contd. Summary on Summary Tables as Materialized Views Needed to be Refreshed whenever New Data Arrived Or When Data is Purged/Reinstated Customers Added and Deleted Frequently
49
prligence Empowering Intelligence Objective To Minimize Downtime for Refreshes –Incrementally Refresh –Partitioning Techniques To Add Customers Easily To Add Quarters Easily To Archive Off and Purge Easily and Atomically To Restore Archives Quickly
50
prligence Empowering Intelligence Design Varying Dimensions – –Customer –Quarter Composite Partitioning –Range (for Quarters) –List (for Customers) Local Indexes
51
prligence Empowering Intelligence Design contd… Mat Views Created As Tables First Query Rewrite and Stale Tolerated Same Partitioning as Parent Tables –Partition-Wise Joins –Partition Pruning –Partition Independence
52
prligence Empowering Intelligence cust1 Summary Table Summary Table DW View Owned by Cust Schema Temporary Table Index of Temporary Table Massaging Analyzing Filter: Where SALES_DATE is in that quarter INDEX TABLE For Customer cust1 and Quarter Q1
53
prligence Empowering Intelligence cust DW View Old Sub Partition INDEX TABLE
54
prligence Empowering Intelligence Design Each Subpartition – of Index or Table is kept in seprate tablespaces named in the format S _ _Y Q E.g. S1_CUST1_Y02Q2
55
prligence Empowering Intelligence subpartitions partitions PARENT MV1 MV2 TableSpace1TableSpace2
56
prligence Empowering Intelligence Design … MV_* Subpartitions are on the same tablespace as the parents. Subparts of MV_S1_0? are in the same TS as S1 Subparts of MV_S2_0? in S2
57
prligence Empowering Intelligence Qtr1 Qtr2Qtr3 DEF Cust1 Cust2 Cust3 DEF
58
prligence Empowering Intelligence Qtr1 Qtr2Qtr3 DEF Cust1 Cust2 Cust3 DEF
59
prligence Empowering Intelligence Qtr1 Qtr2Qtr3 DEF Cust1 Cust2 Cust3 DEF Cust4
60
prligence Empowering Intelligence Qtr1 Qtr2Qtr3 DEF Cust1 Cust2 Cust3 DEF
61
prligence Empowering Intelligence Qtr1 Qtr2Qtr3Qtr4 Cust1 Cust2 Cust3 DEF
62
prligence Empowering Intelligence Objectives Revisited To Minimize Downtime for Refreshes –Incrementally Refresh –Partitioning Techniques To Add Customers Easily To Add Quarters Easily To Archive Off and Purge Easily and Atomically To Restore Archives Quickly
63
prligence Empowering Intelligence www.proligence.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.