Skip to content

Sub-Partitioned Table Statistics Analysis (dstattabsub.sql)

This script analyzes statistics for sub-partitioned tables in composite partitioning schemes, providing detailed information about row counts, storage utilization, and statistics quality across all subpartitions. It’s essential for monitoring data distribution, statistics health, and performance optimization in complex partitioning environments where tables are partitioned by one key and sub-partitioned by another.

rem dstattabpartsub.sql
rem
ttitle 'Sub-Partitioned Table Statistics'
rem
rem set linesize 145
set linesize 500
rem
col owner format a8 heading 'OWNER'
col table_name format a22 heading 'TABLE NAME'
col subpartition_position format 999 head 'POS'
col partition_name format a13 heading 'PARTITION'
col subpartition_name format a22 heading 'SUBPARTITION'
col global_stats format a3 heading 'GBL'
col num_rows format 999,999,990 heading 'ROWS'
col chain_cnt format 9,990 heading 'CHAIN|COUNT'
col avg_row_len format 9,990 heading 'AVG|ROW|SIZE'
col blocks format 999,990 heading 'USED|BLOCKS'
col empty_blocks format 999,990 heading 'EMPTY|BLOCKS'
col avg_space format 9,990 heading 'AVG|FREE|SPACE'
col LAST_ANALYZED format a17 heading 'LAST|ANALYZED'
col SAMPLE_SIZE format 999,999 heading 'SAMPLE|SIZE'
col samp_pct format 999 heading 'SAMP|PCT'
rem
break on owner skip 1 on table_name
compute sum of num_rows blocks empty_blocks on owner table_name
rem
select table_owner owner,
table_name,
partition_name,
subpartition_position,
subpartition_name,
global_stats,
num_rows,
-- chain_cnt,
avg_row_len,
blocks,
-- empty_blocks,
-- avg_space,
to_char(LAST_ANALYZED, 'MM/DD/YY HH24:MI:SS') last_analyzed,
(SAMPLE_SIZE / decode(num_rows, 0, 1, num_rows))*100 samp_pct
from sys.dba_tab_subpartitions
where table_owner like nvl(upper('&owner'), '%')
and table_name like nvl(upper('&table'), '%')
and partition_name like nvl(upper('&partition'), '%')
and subpartition_name like nvl(upper('&subpartition'), '%')
order by table_owner, table_name, partition_name, subpartition_position;
  • Comprehensive Sub-Partition Analysis: Shows statistics for all table subpartitions
  • Multiple Filtering Options: Filter by owner, table, partition, and subpartition
  • Statistics Quality Assessment: Displays sample sizes, freshness, and global statistics status
  • Storage Metrics: Shows row counts, block usage, and space utilization
  • Hierarchical Display: Organized by owner, table, partition, and subpartition
  • Data Distribution Analysis: Reveals partition balance and skew patterns
  • Performance Indicators: Key metrics for query optimization and capacity planning
@dstattabsub.sql

Input Parameters:

  • owner: Schema owner name or pattern (press Enter for all)
  • table: Table name or pattern (press Enter for all)
  • partition: Partition name or pattern (press Enter for all)
  • subpartition: Subpartition name or pattern (press Enter for all)
SELECT on SYS.DBA_TAB_SUBPARTITIONS
Sub-Partitioned Table Statistics
OWNER TABLE NAME PARTITION POS SUBPARTITION GBL ROWS AVG USED LAST SAMPLE SAMP
ROW BLOCKS ANALYZED SIZE PCT
SIZE
-------- ---------------------- ------------- --- ---------------------- --- ----------- --- ------ ----------------- ------ ----
SALES ORDER_HISTORY P_2023_Q1 1 SP_REGION_WEST YES 1,234,567 85 2,468 01/15/24 08:30:00 12,345 1
2 SP_REGION_CENTRAL YES 1,156,789 87 2,314 01/15/24 08:30:00 11,567 1
3 SP_REGION_EAST YES 1,345,234 83 2,690 01/15/24 08:30:00 13,452 1
P_2023_Q2 4 SP_REGION_WEST YES 1,567,890 84 3,136 04/15/24 08:30:00 15,678 1
5 SP_REGION_CENTRAL YES 1,434,567 86 2,869 04/15/24 08:30:00 14,345 1
6 SP_REGION_EAST YES 1,678,901 82 3,358 04/15/24 08:30:00 16,789 1
sum 8,417,948 17,835
HR EMPLOYEE_AUDIT P_2024_Q1 1 SP_DEPT_SALES YES 456,789 92 913 11/01/24 09:15:00 4,567 1
2 SP_DEPT_MARKETING YES 234,567 95 469 11/01/24 09:15:00 2,345 1
3 SP_DEPT_ENGINEERING YES 678,901 88 1,358 11/01/24 09:15:00 6,789 1
4 SP_DEPT_SUPPORT YES 123,456 98 247 11/01/24 09:15:00 1,234 1
sum 1,493,713 2,987
  • OWNER: Schema owner of the sub-partitioned table
  • TABLE NAME: Name of the composite partitioned table
  • PARTITION: Parent partition name
  • POS: Subpartition position within the partition
  • SUBPARTITION: Subpartition name
  • GBL: Global statistics available (YES/NO)
  • ROWS: Number of rows in the subpartition
  • AVG ROW SIZE: Average row length in bytes
  • USED BLOCKS: Number of blocks containing data
  • LAST ANALYZED: Date and time of last statistics gathering
  • SAMPLE SIZE: Number of rows sampled for statistics
  • SAMP PCT: Percentage of rows sampled

Understanding Sub-Partitioned Table Statistics

Section titled “Understanding Sub-Partitioned Table Statistics”
-- Example: Sales data by date range, sub-partitioned by hash
-- Partition: P_2024_Q1 (date range: Jan-Mar 2024)
-- Subpartitions: SP_REGION_1, SP_REGION_2, SP_REGION_3 (hash)
-- Benefits: Time-based maintenance + parallel processing
-- Example: Orders by date range, sub-partitioned by status
-- Partition: P_2024_JAN (date range: January 2024)
-- Subpartitions: SP_PENDING, SP_SHIPPED, SP_DELIVERED (list)
-- Benefits: Time-based maintenance + status-based access
-- Example: Customer data by region, sub-partitioned by hash
-- Partition: P_WEST (region list: CA, OR, WA)
-- Subpartitions: SP_CUST_1, SP_CUST_2, SP_CUST_3 (hash)
-- Benefits: Region-based access + load distribution
-- Statistics freshness criteria:
-- Recent LAST_ANALYZED (< 7 days): Good
-- Moderate age (7-30 days): Monitor
-- Old statistics (> 30 days): Refresh needed
-- NULL LAST_ANALYZED: Never analyzed
-- Sample size evaluation:
-- SAMP_PCT >= 10%: Excellent quality
-- SAMP_PCT 5-10%: Good quality
-- SAMP_PCT 1-5%: Adequate quality
-- SAMP_PCT < 1%: May be insufficient
-- Global statistics (GBL column):
-- YES: Partition-level aggregated statistics available
-- NO: Only subpartition-level statistics
-- Critical for cross-partition queries
-- Affects optimizer cost calculations
  1. Data Distribution Analysis

    • Monitor subpartition size balance
    • Identify data skew patterns
    • Assess partitioning effectiveness
    • Plan partition maintenance
  2. Statistics Health Monitoring

    • Track statistics freshness across subpartitions
    • Identify subpartitions needing refresh
    • Monitor sample quality
    • Plan automated statistics gathering
  3. Performance Optimization

    • Analyze query performance by subpartition
    • Identify partitions causing plan instability
    • Support partition pruning optimization
    • Plan index strategies
  4. Capacity Planning

    • Monitor subpartition growth trends
    • Assess storage requirements
    • Plan partition splits or merges
    • Support infrastructure planning
-- Good distribution indicators:
-- Similar row counts across subpartitions
-- Consistent average row sizes
-- Uniform block usage
-- Effective partition pruning
-- Skew indicators:
-- Large variance in row counts
-- Some subpartitions much larger
-- Uneven resource utilization
-- Performance bottlenecks
-- Growth analysis:
-- Compare subpartition sizes over time
-- Identify fastest-growing subpartitions
-- Plan capacity accordingly
-- Monitor partition boundaries
-- Storage efficiency metrics:
-- Rows per block ratios
-- Average row size trends
-- Block packing efficiency
-- Space utilization patterns
-- Compression effectiveness:
-- Compare compressed vs. uncompressed sizes
-- Analyze compression ratios by subpartition
-- Monitor compression performance impact
-- Plan compression strategies
-- Pruning inefficiency signs:
-- Missing or stale statistics
-- Poor predicate selectivity
-- Cross-partition data access
-- Suboptimal execution plans
-- Performance problem indicators:
-- Uneven subpartition access patterns
-- Large subpartitions causing bottlenecks
-- Statistics staleness impact
-- Plan instability across partitions
-- Maintenance challenges:
-- Large subpartitions taking too long
-- Unbalanced maintenance windows
-- Statistics gathering overhead
-- Partition operations complexity
-- Loading issues:
-- Uneven data distribution during loads
-- Partition key selection problems
-- Constraint validation overhead
-- Index maintenance impact
-- Analyze specific table:
Enter value for owner: SALES
Enter value for table: ORDER_HISTORY
Enter value for partition: %
Enter value for subpartition: %
-- Review specific partition:
Enter value for owner: %
Enter value for table: %
Enter value for partition: P_2024_Q1
Enter value for subpartition: %
-- Search subpartition patterns:
Enter value for owner: %
Enter value for table: %
Enter value for partition: %
Enter value for subpartition: SP_REGION_%
-- Analyze entire schema:
Enter value for owner: HR
Enter value for table: %
Enter value for partition: %
Enter value for subpartition: %
-- Implement incremental statistics:
-- Enable for large composite partitioned tables
-- Monitor synopsis table maintenance
-- Handle partition operations properly
-- Plan global statistics refresh
-- Schedule statistics gathering:
-- Daily for active partitions
-- Weekly for historical partitions
-- After major data loads
-- During maintenance windows
-- Manual statistics procedures:
-- Gather for specific subpartitions
-- Use appropriate sample sizes
-- Include histogram collection
-- Validate gathering results
-- Monitor gathering impact:
-- Resource utilization during gathering
-- Time requirements by subpartition size
-- Impact on concurrent operations
-- Plan optimal gathering schedules
-- Integrate with performance tools:
-- Monitor query performance by subpartition
-- Track execution plan stability
-- Assess partition pruning effectiveness
-- Report optimization opportunities
-- Monitor capacity trends:
-- Track subpartition growth rates
-- Monitor storage utilization
-- Plan partition maintenance
-- Support capacity planning
-- Automated alerting:
-- Alert on stale statistics
-- Monitor statistics gathering failures
-- Report significant growth changes
-- Track performance degradation
-- Optimize queries for subpartitions:
-- Use partition-wise joins
-- Implement partition pruning
-- Consider parallel processing
-- Optimize predicate selection
-- Optimize partitioning strategy:
-- Evaluate partition key effectiveness
-- Consider sub-partitioning alternatives
-- Plan partition boundary adjustments
-- Assess maintenance requirements
-- Index optimization:
-- Local vs. global index trade-offs
-- Partition-wise index maintenance
-- Consider prefixed vs. non-prefixed
-- Plan index rebuild strategies
-- Follow statistics best practices:
-- Use appropriate sample sizes
-- Maintain global statistics
-- Schedule regular gathering
-- Monitor statistics quality
-- Design considerations:
-- Choose effective partition keys
-- Balance partition sizes
-- Plan for growth patterns
-- Consider access patterns
-- Plan maintenance activities:
-- Coordinate with application teams
-- Schedule during low-usage periods
-- Monitor maintenance impact
-- Validate results

This script is essential for:

  1. Data Distribution Analysis - Understanding data balance across subpartitions
  2. Statistics Health Monitoring - Tracking statistics quality and freshness
  3. Performance Optimization - Supporting query and partition optimization
  4. Capacity Planning - Monitoring growth and storage requirements
  5. Maintenance Planning - Supporting automated and manual maintenance activities