## What are partitions stats?

Partition Stats in oracle is the stats of a particular partition for a table. We need to maintained the table global stats and partition stats for used by optimizer to provide the better execution plan. I am taking example of RETAIL schema having SALES table which is partition table in database.

**How often we should gather stats in Oracle?**

Since Oracle 11g statistics are gathered automatically by default. Two Scheduler windows are predefined upon installation of Oracle Database: WEEKNIGHT_WINDOW starts at 10 p.m. and ends at 6 a.m. every Monday through Friday. WEEKEND_WINDOW covers whole days Saturday and Sunday.

**How do you collect table statistics?**

begin DBMS_STATS. GATHER_TABLE_STATS(‘owner’, ‘table_name’, estimate_percent=>50, block_sample=>TRUE, degree=>4) ; end ; These statements collect statistics on all the objects associated with table_name, including the table columns and any indexes (b-tree, bitmap, or Text domain) associated with the table.

### How do you gather stats for a partitioned table?

STEPS TO MAINTAIN STATISTICS ON LARGE PARTITION TABLES

- STEP 1: Gather stats for any one partition say P185. EXEC dbms_stats.
- STEP 2: Generate script for rest of the remaining partition like shown below.
- STEP 3: After gather statistics you can lock the stats.

**How do you gather stats for a partition?**

Gather Partition Statistics Frequently exec dbms_stats. gather_table_stats(OWNNAME=>user,TABNAME=>’MYTAB’, PARTNAME=>’SYS_P10030′, CASCADE=> TRUE);

**How gather stats improve performance?**

A parallel statistics collection requires an SMP server with multiple CPUs. The dbms_stats utility is a great way to improve SQL execution speed. By using dbms_stats to collect top-quality statistics, the CBO will usually make an intelligent decision about the fastest way to execute any SQL query.

#### What does gather stats do in Oracle?

You must gather statistics on a regular basis to provide the optimizer with information about schema objects. New statistics should be gathered after a schema object’s data or structure are modified in ways that make the previous statistics inaccurate.

**What is global stats in Oracle?**

Global statistics are generated by aggregating the synopses from each partition, thus eliminating the need for the full table scan (see Figure below). When a new partition is added to the table you only need to gather statistics for the new partition.

**What statistics are generated when a table is partitioned in Oracle?**

For other partitioned tables, only the global and partition level statistics are generated. When the GLOBAL AND PARTITION option is specified, Oracle gathers the global and partition level statistics. No sub-partition level statistics are gathered even it is composite partitioned object.

## Can I gather Optimizer statistics on a partitioned table?

Gathering optimizer statistics on a partitioned table is not a trivial task with some caveats. Particularly on a daily partitioned schema it could be not the best solution to gather partitions statistics once per day.

**What Statistics does DBMS_StatsCan gather for partitioned tables and indexes?**

For partitioned tables and indexes, DBMS_STATScan gather separate statistics for each partition as well as global statistics for the entire table or index. Similarly, for composite partitioning DBMS_STATScan gather separate statistics for subpartitions, partitions, and the entire table or index.

**Is it OK to gather partitions statistics once per day?**

Particularly on a daily partitioned schema it could be not the best solution to gather partitions statistics once per day. To demonstrate it, let assume we have not daily schema but yearly partitions of transaction data. The question is, would it be OK to gather statistics say on 1. January (or 1. June or 31. December)?