Title: Get the best out of Oracle Partitioning
1(No Transcript)
2Get the best out of Oracle Partitioning
- Hermann Bär
- Director Product Management, Data Warehousing
3Agenda
- Partitioning in a nutshell
- Getting optimal pruning
- Partition exchange loading
- Partitioning and unusable indexes
- Efficient statistics management
- QA
4The Concept of PartitioningSimple Yet Powerful
ORDERS
USA
ORDERS
ORDERS
EUROPE
FEB
FEB
JAN
JAN
Large Table Difficult to Manage
Partition Divide and Conquer Easier to
Manage Improve Performance
Composite Partition Better Performance More
flexibility to match business needs
Transparent to applications
5What is Oracle Partitioning?
- It is
- Powerful functionality to logically partition
objects into smaller pieces - Only driven by business requirements
- Partitioning for Performance, Manageability, and
Availability
- It is not
- Just a way to physically divide or clump - any
large data set into smaller buckets - Enabling pre-requirement to support a specific
hardware/software design - Hash mandatory for shared nothing systems
6Physical versus Logical PartitioningShared
Nothing Architecture
- Physical Partitioning
- Fundamental system setup requirement
- Node owns piece of DB
- Enables parallelism
- Number of partitions is equivalent to min.
parallelism - Always needs HASH distribution
- Equally sized partitions per node required for
proper load balancing
DB
DB
DB
7Physical versus Logical PartitioningShared
Everything Architecture - Oracle
- Logical Partitioning
- Does not underlie any constraints
- SMP, MPP, Cluster, Grid does not matter
- Purely based on the business requirement
- Availability, Manageability, Performance
- Beneficial for every environment
- Provides the most comprehensive functionality
DB
8Agenda
- Partitioning in a nutshell
- Getting optimal pruning
- Partition exchange loading
- Partitioning and unusable indexes
- Efficient statistics management
- QA
9Partition Pruning
Q What was the total sales for the weekend of
May 20 - 22 2008?
Select sum(sales_amount) From SALES Where
sales_date between to_date(05/20/2008,MM/DD/YYY
Y) And to_date(05/23/2008,MM/DD/YYYY)
10Partition Pruning
- Works for simple and complex SQL statements
- Support for every data access
- Transparent to any application
- No extra coding required
- Two flavors of pruning
- Static pruning at compile time
- Dynamic pruning at runtime
- Complementary to Exadata Storage Server
- Partitioning prunes logically through partition
elimination - Exadata prunes physically through storage indexes
- Further data reduction through filtering and
projection
11Sun Oracle Database MachineOptimized for large
scans
1 TB with compression
10 TB of user data Requires 10 TB of IO
100 GB with partition pruning
Subseconds On Database Machine
20 GB with Storage Indexes
5 GB with Smart Scans
2000X less data needs to be processed
11
12Static Partition Pruning
- Relevant Partitions are known at compile time
- Look for actual values in PSTART/PSTOP columns in
the plan - Optimizer has most accurate information for the
SQL statement
SELECT sum(amount_sold) FROM salesWHERE times_id
BETWEEN 01-MAR-2004 and 31-MAY-2004
04-Apr
04-Feb
04-Jan
04-Mar
04-May
13Static Pruning
14Static Pruning
15Dynamic Partition Pruning
- Advanced Pruning mechanism for complex queries
- Recursive statement evaluates the relevant
partitions at runtime - Look for the word KEY in PSTART/PSTOP columns
in the Plan
SELECT sum(amount_sold)FROM sales s, times
tWHERE t.time_id s.time_id AND
t.calendar_month_desc IN (MAR-2004,
APR-2004, MAY-2004)
Time
Sales
16Dynamic Partition PruningNested Loop
Sample explain plan output
17Dynamic Partition PruningNested Loop
Sample explain plan output
18Dynamic Partition PruningSubquery pruning
19Dynamic Partition PruningBloom filter pruning
20Enhanced Pruning CapabilitiesOracle Database 11g
Release 2
- Extended modeling capabilities for better data
placement and pruning - Support for virtual columns as primary and
foreign key for Reference Partitioning - Enhanced optimizer support for Partitioning
- AND pruning
- Intelligent multi-branch execution plan with
unusable index partitions
20
21AND Pruning
- All predicates on partition key will used for
pruning - Dynamic and static predicates will now be used
combined - A.k.a. multi-predicate pruning
- Example
- Star transformation with pruning predicate on
both the FACT table and a dimensionFROM sales s,
times t WHERE s.time_id t.time_id ..AND
t.fiscal_year in (2000,1999)AND s.time_id
between TO_DATE('01-JAN-1999','DD-MON-YYYY') and
TO_DATE('01-JAN-2000','DD-MON-YYYY')
Dynamic pruning
Static pruning
21
22AND Pruning
23Ensuring Partition Pruning
- Dont use functions on partition key filter
predicates
24Ensuring Partition Pruning
- Dont use functions on partition key filter
predicates
25Agenda
- Partitioning in a nutshell
- Getting optimal pruning
- Partition exchange loading
- Partitioning and unusable indexes
- Efficient statistics management
- QA
26Partition Exchange loading
27Agenda
- Partitioning in a nutshell
- Getting optimal pruning
- Partition exchange loading
- Partitioning and unusable indexes
- Efficient statistics management
- QA
28Segment Creation On-DemandA.k.a. deferred
segment creation
- Segment creation for nonpartitioned tables (and
indexes) is delayed until first data inserted - No support for partitioned objects (yet)
- Specifically beneficial for pre-packaged
applications - Common deployments consist of thousands of
tables, many of them being empty - Reduced storage foot print
- Faster initial deployment
- Leverage this functionality after database
migration - API to drop segments for existing empty objects
28
29Segment Creation On-DemandTechnical details
- Enabled by DEFAULT with compatible11.2
- Init.ora deferred_segment_creation TRUE
FALSE - Session and system level attribute
- Object level SEGMENT CREATION IMMEDIATE
DEFERRED - Indexes inherit the attribute from the table
- No support for partitioned indexes, bitmap join
indexes, domain indexes - Same infrastructure is leveraged for unusable
indexes - Both non-partitioned and partitioned indexes
- Unusable index segments can never be re-used
29
30Unusable Indexes
- Unusable index partitions are commonly used in
environments with fast load requirements - Safe the time for index maintenance at data
insertion - Unusable index segments do not consume any space
(11.2) - Unusable indexes are ignored by the optimizer
- SKIP_UNUSABLE_INDEXES TRUE FALSE
- Partitioned indexes can be used by the optimizer
even if some partitions are unusable - Prior to 11.2, static pruning and only access of
usable index partitions mandatory - With 11.2, intelligent rewrite of queries using
UNION ALL
31Intelligent Multi-Branch Execution
- Intelligent UNION ALL expansion in the presence
of partially unusable indexes - Transparent internal rewrite
- Usable index partitions will be used
- Full partition access for unusable index
partitions
32Multi-Branch Execution
33Agenda
- Partitioning in a nutshell
- Getting optimal pruning
- Partition exchange loading
- Partitioning and unusable indexes
- Efficient statistics management
- QA
34Statistics Gathering
- You must gather optimizer statistics
- Using dynamic sampling is not an adequate
solution - Statistics on global and partition level
recommended - Run all queries against empty tables to populate
column usage - This helps identify which columns automatically
get histograms created on them - Optimizer statistics should be gathered after the
data has been loaded but before any indexes are
created - Oracle will automatically gather statistics for
indexes as they are being created
35Statistics Gathering
- By default DBMS_STATS gathers following stats for
each table - global (table level)
- partition level
- Sub-partition
- Optimizer uses global stats if query touches two
or more partitions - Optimizer uses partition stats if queries do
partition elimination and only one partition is
necessary to answer the query - If queries touch two or more partitions the
optimizer will use a combination of global and
partition level statistics - Optimizer uses sub-partition level statistics
only if your queries do partition elimination and
one sub-partition is necessary to answer query
36Efficient Statistics Management
- Use AUTO_SAMPLE_SIZE
- The only setting that enables new efficient
statistics collection - Hash based algorithm, scanning the whole table
- Speed of sampling, accuracy of compute
- Enable incremental global statistics collection
- Avoids scan of all partitions after changing
single partitions - Prior to 11.1, scan of all partitions necessary
for global stats - Managed on per table level
- Static setting
37Incremental Global Statistics
Sysaux Tablespace
38Incremental Global Statistics Contd
3. A new partition is added to the table Data
is Loaded
Sales Table
May 18th 2008
May 19th 2008
May 20th 2008
May 21st 2008
May 22nd 2008
May 23rd 2008
May 24th 2008
May 24th 2008
Sysaux Tablespace
39Step necessary to gather accurate statistics
- Turn on incremental feature for the table
- EXEC DBMS_STATS.SET_TABLE_PREFS('SH,'SALES','INCR
EMENTAL','TRUE') - After load gather table statistics using
GATHER_TABLE_STATS - No need to specify parameters
- EXEC DBMS_STATS.GATHER_TABLE_STATS('SH','SALES')
- The command will collect statistics for
partitions and update the global statistics based
on the partition level statistics and synopsis - Possible to set incremental to true for all
tables - Only works for already existing tables
- EXEC DBMS_STATS.SET_GLOBAL_PREFS('INCREMENTAL','TR
UE')
40Summary
- Partitioning in a nutshell
- Getting optimal pruning
- Partition exchange loading
- Partitioning and unusable indexes
- Efficient statistics management
41Q A
42For More Information
search.oracle.com
Oracle Partitioning
or oracle.com
43(No Transcript)