Professional Documents
Culture Documents
September 2013
Disclaimer
The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development, release,
and timing of any features or functionality described for Oracles products remains at the sole discretion
of Oracle.
Best Practices for Gathering Statistics with Oracle E-Business Suite
Executive Overview......................................................................................... 1
Introduction ..................................................................................................... 1
FND_STATS Features .................................................................................... 2
History Mode ................................................................................................... 2
Gather Options ................................................................................................ 2
Histograms ...................................................................................................... 3
The AUTO Sampling Option ........................................................................... 4
Custom Scripts ................................................................................................ 4
When to Gather Statistics ............................................................................... 5
Cursor Invalidation .......................................................................................... 6
Locking Statistics ............................................................................................ 6
Database 11g Extended Statistics .................................................................. 7
Gathering Dictionary and Fixed Object Statistics ........................................... 8
Dictionary Statistics .................................................................................... 8
Fixed Statistics............................................................................................ 8
Global Temporary Tables................................................................................ 9
Temporary Tables ......................................................................................... 10
Incremental Statistics for Partitioned Tables................................................. 10
Improving the Collection Time ...................................................................... 11
Verifying Statistics ......................................................................................... 11
Standalone Patches ...................................................................................... 12
Performance Test Cases & Examples .......................................................... 13
1. Oracle 11g Extended Optimizer Statistics ........................................ 13
2. Incremental Statistics Gathering ....................................................... 17
3. Concurrent Statistics Gathering ........................................................ 20
Appendix A: Related Documentation ............................................................ 21
Whitepapers.............................................................................................. 21
My Oracle Support Knowledge Documents ............................................. 21
Blogs ......................................................................................................... 21
Appendix B: Package Specifications ............................................................ 23
Gather Table Statistics ............................................................................. 23
Gather Schema Statistics ......................................................................... 25
Best Practices for Gathering Statistics with Oracle E-Business Suite
Executive Overview
This paper documents the best practices for gathering statistics. It focuses on new features
implemented in the FND_STATS package that can be applied to Oracle E-Business Suite 11i (11.5.10
and later) and Release 12.
Introduction
The Best Practices for Gathering Optimizer Statistics white paper provides an extensive overview of
the Oracle database statistics gathering process and is a useful precursor to this paper. It describes
several methods for collecting or setting statistics, however, the only supported methods with Oracle
E-Business Suite are either the Gather Statistics concurrent program or the FND_STATS package
(which is called by the Gather Statistics concurrent program). FND_STATS is a wrapper around the
DBMS_STATS package and provides several PL/SQL procedures for gathering statistics at the table,
schema, or database level. The FND_STATS package also supports histograms, table exclusions and
the new database 11G features such as extended stats, incremental stats gathering for partitioned tables
and concurrent stats gathering. Neither the DBMS_STATS package nor the now obsolete ANALYZE
command recognize those features and may result in suboptimal execution plans.
1
Best Practices for Gathering Statistics with Oracle E-Business Suite
FND_STATS Features
This section provides a high-level view of how the FND_STATS package interacts with DBMS_STATS. While either the
Oracle E-Business Suite or DBMS_STATS will gather statistics for objects with stale or empty (missing) statistics, the
FND_STATS package implements the following features in Oracle E-Business Suite:
Supports collection of statistics for individual schemas, or for the entire Oracle E-Business Suite. To process all E-
Business schemas, pass the schema name as 'ALL'. DBMS_STATS does not have this functionality.
Histograms on columns designated in FND_HISTOGRAM_COLS. This contains a list of histogram columns that
Oracle Development have identified as essential.
The new GATHER_AUTO option combines the collection of statistics for tables with either stale or missing (empty)
statistics.
FND_STATS supports rerun-ability feature. If the Gather Schema Statistics concurrent program is used, FND_STATS
maintains the history of each submission. If a run stopped or interrupted, the next submission will resume from the point
of failure or termination. Starting with the 10g version of the database, DBMS_STATS 'GATHER AUTO' option with
Table Monitoring feature can be used to serve the purpose of rerun-ability.
FND_STATS_HIST stores historical information about the amount of time it takes the statistics gathering package
FND_STATS to gather statistics.
History Mode
The Gather Table Statistics program can optionally backup the existing statistics prior to gathering new statistics. If the value
of backup flag parameter is BACKUP, FND_STATS exports the old statistics using
DBMS_STATS.EXPORT_TABLE_STATS prior to gathering new statistics and stores them in FND_STATTAB.
The history mode parameter controls the amount of history records that are created:
Last Run - History records are maintained only for the last gather statistics run. Each subsequent run will overwrite
the previous history record for the object. This is the default behavior.
Full - This mode does not overwrite previous historical information. History records are created for each new run and
are identified by the Request ID, which is generated automatically if one is not provided. If this mode is used, the
Purge FND_STATS History Records concurrent program should be run periodically to purge the FND_STATS_HIST
table.
None - This mode does not generate any history information and the run cannot be restarted.
If problems ensue post gathering statistics, you can use the RESTORE_SCHEMA_STATS or
RESTORE_TABLE_STATS procedure to restore statistics that were previously backed up in the FND_STATTAB table,
into the dictionary; statid can be provided to distinguish between different sets of statistics.
Gather Options
Use GATHER_AUTO option to gather stats incrementally. GATHER_AUTO relies on the Oracle Table Monitoring
feature to gather information about new or changed objects statistics.
2
Best Practices for Gathering Statistics with Oracle E-Business Suite
In Oracle 9i, it was possible to specify individual tables, but this approach was deprecated in later releases and is now
automatically enabled for the entire schemas by default in Oracle 10g and Oracle 11g. To mimic this behavior in Oracle 9i,
use the following procedure:
When Gather Options parameter is set to "GATHER AUTO", fnd_stats will only gather statistics for tables that have
changed by more than the modification threshold % since the table was last analyzed (statistics gathered). The
modifications threshold can be adjusted by the user by passing a value for modpercent, which by default is equal to 10. So
the GATHER_AUTO will only gather stats on tables that show up in DBA_TAB_MODIFICATIONS with > 10%
changes.
Histograms
A histogram is a special type of column statistic that provides additional information about the frequency and distribution
of values within a column. This information is used by the Optimizer when, for example, deciding to use an index or
perform a full-table scan, or deciding the join order. Without histograms the Optimizer assumes a uniform distribution of
rows across the distinct values in the column. These are created in Oracle E-Business Suite when a value in a column that is
referenced in a where clause has a disproportionate number of values that would usually make a full-table scan cheaper than
using the index - in other words when a column has non-unique repeating keys and only a few distinct values. This is
referred to as data skew. Histograms may also be used for some join predicates, which is beneficial with cardinality
estimates. Oracle 11g uses adaptive cursor sharing to ensure that the correct plan is used with bind peeking.
Collecting statistics for histograms adds time to the overall process. Histograms can be problematic and in Oracle 10g there
were concerns with bind peeking and how it affects cardinality estimates. The Optimizer would peek at the value of the
bind variables on the first hard parse of the SQL statement and then always use that plan for all future executions. The only
real solution for Oracle E-Business Suite was to disable bind peeking; dropping the histograms was not an option.
This has been improved in Oracle 11g with the introduction of Adaptive Cursor Sharing. Avoiding histograms will ensure
that SQL execution plans will not change depending on the bind value.
Those with custom development can use FND_STATS.CHECK_HISTOGRAM_COLS to determine the viability of
proposed histograms. This procedure checks if the leading columns in non-unique indexes have a single value occupancy
>=1/75th or more of the sample. The recommendation is that there is a minimum of 3000 rows. The following example
shows how to run the procedure:
Set Serveroutput on
EXEC FND_STATS.CHECK_HISTOGRAM_COLS( tablelist => 'owner.table_name1 , owner.table_name2, .... )
Once you have checked the design and performance use the LOAD_HISTOGRAM_COLS procedure to seed information
in the FND_HISTOGRAM_COLS table, which will ensure that they are updated when Gathering Statistics using the
following syntax:
begin
FND_STATS.LOAD_HISTOGRAM_COLS
(action=>'INSERT', appl_id=>&custom_application_id, tabname=>&table_name, colname=>&column_name);
FND_STATS.GATHER_TABLE_STATS( ownname=>&owner_name, tabname=>&table_name);
end;
3
Best Practices for Gathering Statistics with Oracle E-Business Suite
Note: When invoking the Gather Statistics concurrent program, leave the estimate percentage parameter blank.
The program will automatically choose the default value for estimate_percent parameter (depends on the
database version). If a value is provided then statistics will be gathered at the specified percentage. If the
database version is 11g or higher, the default value for this parameter will be dbms_stats.auto_sample_size,
whereas it will be set to 10% for previous releases.
Note: AUTO Sampling Statistics Gathering Feature of Oracle Database 11g is implemented with the latest code
of FND_STATS. Refer to Standalone Patches section, the standalone patches for Oracle 11g are shown in
Table 1.
Custom Scripts
As an alternative to using the Gather Statistics concurrent program, custom scripts may be developed that call the
FND_STATS package directly. The syntax is as follows:
For schema stats: Exec FND_STATS.gather_schema_statistics('schema_name');
For example:
4
Best Practices for Gathering Statistics with Oracle E-Business Suite
EXEC FND_STATS.gather_schema_statistics('ALL');
EXEC FND_STATS.gather_schema_statistics('XLA');
For table stats: Exec FND_STATS.gather_table_stats(owner,table_name);
For example:
EXEC FND_STATS.gather_table_stats('AR','RA_CUSTOMER_TRX_ALL');
5
Best Practices for Gathering Statistics with Oracle E-Business Suite
Cursor Invalidation
When an objects statistics are refreshed, all references to that object in the shared pool or library cache are invalidated and
all dependent cursors referencing that object are also invalidated, each will require a new hard parse. Oracle distributes
invalidation timestamps for dependent objects needing invalidation, thereby reducing the potentially large number of
simultaneous hard parses, but this can still result in an increase in library cache waits especially when collecting statistics
across a large number of objects.
Note: When using the Gather Statistics concurrent program, the Invalidate Dependent Cursors parameter is set
to Yes by default, which is the standard best practice. New execution plans will be generated whenever cursor
has been flushed out and reloaded.
While this approach suits most Oracle E-Business Suite installations, this parameter allows you to specify that cursors
should not be invalidated. Although this may reduce the CPU utilization, this means that existing plans, which may be sub-
optimal, will continue to be used until the dependent cursors are aged out.
Deciding between these two invalidation options is determined by the collection frequency. If you keep your statistics fairly
current, you will probably not need to invalidate cursors as the plans from the newly collected statistic are unlikely to be
significantly different. In other words, performance should remain consistent and stable and over time. However, if you
dont collect statistics frequently enough, or if you start to experience performance degradation due to stale statistics, then
setting this to the default to invalidate the cursors that are dependent on the targeted objects as soon as possible will ensure
that the plans are refreshed sooner.
Note: Gather statistics only when there is little system activity or during a defined batch period.
Locking Statistics
Locking prevents object statistics from being overwritten when the collection processes is run. This may be useful when
tables are empty when the collection process is run, or when you want to exclude exceptionally large tables while gathering
statistics for the remainder of the schema.
Very large static tables that have representative statistics already in place and are rarely updated.
Volatile tables where data changes dramatically over time. Good examples include intermediate tables used during
batch processing and some interface tables, which are deployed extensively across Oracle E-business Suite. Example
application tables include AP_SELECTED_INVOICES and WSH_PR_WORKERS.
Temporary or interim tables that only contain data at runtime but are typically empty when the collection process
runs. In this specific case, not locking statistics results in having zero or un-representative statistics. Note that these do
not include Global Temporary tables, which are excluded from FND_STATS Gather Schema Statistics anyway.
Note : If a table has zero statistics (num_rows = 0) then the CBO uses these statistics to determine the
execution plan and if the table has a lot of rows at time of execution then this execution plan could be very
inefficient. If tables have empty statistics (null) then dynamic sampling will be used, which is preferable to
using the CBO with incorrect or zero statistics.
There are two distinct methods for protecting table statistics from modification.
1. You can physically lock the statistics using DBMS_STATS.LOCK_TABLE_STATS, which prevents any calls to
FND_STATS or DBMS_STATS from modifying the statistics.
6
Best Practices for Gathering Statistics with Oracle E-Business Suite
2. You can also add the table to a list of excluded tables by using FND_STATS.LOAD_XCLUD_TAB. This prevents the table
from having its statistics modified when using Gather Schema Statistics, but the Gather Table Statistics does not honor
the FND exclusion, only the DBMS lock. This is by design; there may be instances when you want to manually collect
statitistics.
Oracle E-Business Suite development teams use LOAD_XCLUD_TAB to seed exceptions into the
FND_EXCLUDE_TABLE_STATS table (which is a metadata container). Many of the EBS volatile and temporary tables
are seeded in this table for reference only. They will not be excluded from FND_STATS Gather Schema Statistics, as they
have been seeded with negative application_ids. You should consider these tables as candidates for locking.
Note: It is recommended that you use seed tables into FND_EXCLUDE_TABLE_STATS, or use
DBMS_STATS.LOCK_TABLE_STATS if certain that you never want the statistics modified.
For each volatile or temporary table that you have locked you should initially have empty (null) statistics and rely
on dynamic sampling. Delete the statistics if they already contain values. Only if you have performance issues
should you consider gathering statistics when the table has a representative load or populating using
FND_STATS. SET_TABLE_STATS.
Once the statistics are locked using DBMS_STATS.LOCK_TABLE_STATS, the Gather Schema Statistics Concurrent
Program will display a message in the request log file explicitly stating that statistics are locked on that table.
Use the following to delete the table entry from the fnd_exclude_table_stats:
FND_STATS.LOAD_XCLUD_TAB(action=>'DELETE', appl_id=>&application_id, tabname=>&table_name)
Example
FND_STATS.LOAD_XCLUD_TAB(action=>'DELETE',
appl_id=>222, tabname=>'RA_CUSTOMER_TRX_ALL')
7
Best Practices for Gathering Statistics with Oracle E-Business Suite
begin
FND_STATS.LOAD_EXTNSTATS_COLS
(action =>'INSERT', appl_id=>&custom_application_id, tabname => &table_name, owner=>&owner, colname1
=>&column_name1, colname2 =>&column_name2, colname3.....);
FND_STATS.GATHER_TABLE_STATS( ownname=>&owner_name, tabname=>&table_name);
end;
/
Note: You need to gather statistics after defining the group of columns.
Dictionary Statistics
Dictionary statistics only need to be gathered when there have been significant structural changes to the database.
e.g.
After any associated platform or DB upgrade that is part of the overall EBS upgrade.
After the R12 upgrade.
After move to OATM
The question is when, and how often do they need to be collected. Typical examples include upgrades, new modules, or the
application of large patches where several objects might be created or rebuilt using Data Definition Language (DDL)
operations.
Statistics will need to be collected when SQL on the data dictionary objects appears as a high load (usually high elapsed
time) in AWR reports or other monitoring tools, or when times in trace/tkprof files are very high for recursive SQL on the
data dictionary objects. The following command can be used to gather statistics for all system schemas:
EXECUTE DBMS_STATS.GATHER_DICTIONARY_STATS( estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE options
=> 'GATHER AUTO' ); -- In 10G and above.
8
Best Practices for Gathering Statistics with Oracle E-Business Suite
Use DBMS_STATS.GATHER_FIXED_OBJECT_STATS (available in Oracle 10g and later) to gather fixed object
statistics. For optimal performance, and due to the transient nature of the x$ tables, it is important to gather statistics when
there is a representative workload on the system. The collection process tends to be resource intensive and if there is
insufficient capacity during peak load, choose a time after the database has been running for some time and the v$ views
have a significant amount of data. However, gathering fixed objects statistics under heavy load can result in contention
issues thereby leading to performance degradation or hangs. Refer to MyOracle Knowledge Document Fixed Objects
Statistics (GATHER_FIXED_OBJECTS_STATS) Considerations (Doc ID 798257.1) for further information.
The following command can be used to gather fixed object statistics:
EXECUTE DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;
Planning Collection
Fixed object statistics should be gathered when there are significant changes to the database configuration or when
accessing the v$ views is of concern. Oracle E-Business Suite examples include the following:
Major database or application upgrades*
Platform upgrades (especially Exadata)
New application modules are deployed
Performance issues when querying V$ views
Significant changes in the workload or number of sessions
After significant database structure changes (e.g. SGA/PGA)
For example, all the x$ tables that contain information about the buffer cache and shared pool, such as x$ tables used in
v$buffer_pool or v$shared_pool_advice, may change significantly when the SGA is increased.
Note: In Oracle E-Business Suite it is imperative that you disable the Database 11g automatic DBMS job to
gather statistics, but ensure that dictionary statistics are still gathered.
* When upgrading Oracle E-Business Suite, the $APPL_TOP/admin/adstats.sql script disables the Oracle DBMS job that
automatically gathers statistics. It then gathers dictionary and fixed object statistics. However, the Database is run in
restricted mode during the upgrade. Therefore, it is highly recommended to rerun
DBMS_STATS.GATHER_FIXED_OBJECT_STATS post upgrade, when there is a representative load on the system.
9
Best Practices for Gathering Statistics with Oracle E-Business Suite
Note that FND_STATS Gather Schema Statistics excludes Global Temporary Tables anyway, so they do not need to
be excluded or locked.
Temporary Tables
Temporary tables in Oracle E-Business Suite are regular tables that should not be confused with GTTs. They tend to be
highly volatile and are typically empty for some of the processing cycle and then re-populated. Examples include interface
tables, intermediate transient tables, transactions that have been selected by a specific process such as payments or records
to be purged.
For these tables you should initially have empty (null) statistics and rely on dynamic sampling. Delete the statistics if they
already contain values.
Only if you have performance issues should you consider gathering statistics when the table has a representative load or
populating using FND_STATS. SET_TABLE_STATS.
In all cases the statistics should be locked (so that they are not gathered).
Incremental statistics can be applied to any large partitioned tables. Once the table preference has been set, Oracle E-
Business Suite Gather Statistics (table or schema) can be used to automatically gather the statistics and create the synopsis.
Incremental Preference
Use the following command to check if the incremental preference is set for the XLA_AE_LINES table (which is part of
the Oracle E-Business Suite12 Subledger Accounting):
select dbms_stats.get_prefs('INCREMENTAL', 'XLA','XLA_AE_LINES')
from dual;
10
Best Practices for Gathering Statistics with Oracle E-Business Suite
exec dbms_stats.set_table_prefs('XLA','XLA_AE_LINES','INCREMENTAL','TRUE');
During testing, it may be useful to know that the preference can be turned off using:
exec dbms_stats.set_table_prefs('XLA', 'XLA_AE_LINES, 'INCREMENTAL', 'FALSE');
Granularity Parameter
exec fnd_stats.gather_table_stats
('OWNER', TABLE_NAME', granularity =>'ALL');
Degree Of Parallelism
FND_STATSs DEGREE (Degree of parallelism) helps speed up statistics gathering for large objects. If a degree is not
provided, FND_STATS automatically determines the Degree of Parallelism, it defaults to the minimum of
parallel_max_servers and cpu_count. This approach has been defined as intra object parallelism.
Concurrent statistics gathering is a new DBMS_STATS feature in Oracle 11gR2 that provides inter-object parallelism.
When CONCURRENT is set to TRUE (FALSE by default) and Estimate Percent is set to
DBMS_STATS.AUTO_SAMPLE_SIZE, Oracle uses the Oracle Job Scheduler ( job_queue_processes should be set to more
than 4) and Advanced Queuing to concurrently run multiple gather statistics jobs across multiple objects.
The preference can be set using the following command:
exec DBMS_STATS.SET_GLOBAL_PREFS('CONCURRENT','TRUE');
11
Best Practices for Gathering Statistics with Oracle E-Business Suite
DBMS_STATS.gather_table_stats and not gather_schema_statistics. So this feature can only be used to gather statistics for
different partitions of the same table at the same time. So it is only beneficial on partitioned tables, where data is reasonably
well distributed across the partitions.
Verifying Statistics
The FND_STATS.VERIFY_STATS procedure can be used to check that statistics are up-to-date. It produces a report and
can be run using the following syntax:
set serveroutput on
set long 10000
exec apps.fnd_stats.verify_stats (OWNER, TABLE_NAME);
For example:
exec apps.fnd_stats.verify_stats ('ONT', 'ONT.OE_ORDER_HOLDS_ALL');
Alternatively, you can verify statistics using the scripts from My Oracle Support Knowledge Document 163208.1.
bde_last_analyzed.sql - Verifies CBO Statistics.
Standalone Patches
The standalone patches for Oracle 11g are shown in Table 1: Oracle E-Business Suite Standalone Patches for the following
new features implemented in FND_STATS code.
1. Database 11g AUTO Sampling Statistics Gathering Option
Those unable to apply the Auto sampling standalone patch should review the automated script provided in My Oracle
Knowledge Document 156968.1: coe_stats.sql - Automates CBO Stats Gathering using FND_STATS and Table sizes.
This interim solution provides recommendations based on the range, sample size, and collection frequency.
2. Database 11g Extended Statistics Gathering Feature
12.1.x 16410424:R12.FND.B
12.0.x 16410424:R12.FND.A
11.5.10 14707975
12
Best Practices for Gathering Statistics with Oracle E-Business Suite
The FND_LOOKUP_VALUES table provides the basis for this example as it is suitably small, easy to understand, and
may be familiar as is used across several modules.
It stores Oracle Application Object Library QuickCode values. Essentially each row contains the QuickCode lookup type,
the QuickCode itself, its meaning, and additional description (also other columns not directly pertinent to this example).
These values are used by List of Values across several of the Oracle E-Business Suite forms.
Several of the values are only used by specific modules and therefore they are typically both referenced when querying data,
which is one of the primary conditions for using extended statistics. As such, this implies that there is a correlation between
the columns, and in fact the LOOKUP_TYPE is dependent upon the VIEW_APPLICATION_ID.
desc FND_LOOKUP_VALUES
COUNT(1)
----------
532559
exec fnd_stats.gather_table_stats('APPLSYS','FND_LOOKUP_VALUES');
TABLE_NAME NUM_ROWS
------------------------------ ----------
FND_LOOKUP_VALUES 532559
13
Best Practices for Gathering Statistics with Oracle E-Business Suite
- The following histograms are already present in the FND data dictionary:
TABLE_NAME COLUMN_NAME
------------------------------ ------------------------------
FND_LOOKUP_VALUES LANGUAGE
FND_LOOKUP_VALUES VIEW_APPLICATION_ID
select table_name, column_name, num_distinct, density, num_buckets, histogram from user_tab_col_statistics where
table_name = 'FND_LOOKUP_VALUES';
- Check explain plan of the select for the different values of view_application_id and lookup_type
explain plan for select * from FND_LOOKUP_VALUES where VIEW_APPLICATION_ID=201 and lookup_type=:b2;
Explained.
PLAN_TABLE_OUTPUT
14
Best Practices for Gathering Statistics with Oracle E-Business Suite
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 152 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| FND_LOOKUP_VALUES | 1 | 152 | 4 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U1 | 1 | | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
explain plan for select * from FND_LOOKUP_VALUES where VIEW_APPLICATION_ID=3 and lookup_type='NO_POSTAL_CODE';
Explained.
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 12 | 1680 | 13 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| FND_LOOKUP_VALUES | 12 | 1680 | 13 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U2 | 12 | | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
explain plan for select * from FND_LOOKUP_VALUES where VIEW_APPLICATION_ID=3 and lookup_type='AE_ARIA_CODE';
Explained.
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 12 | 1680 | 13 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| FND_LOOKUP_VALUES | 12 | 1680 | 13 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U2 | 12 | | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
The extended statistics approach will create a column statistics entry for the column group in the Data Dictionary. In
this example they are gathered manually so that the result can be seen immediately.
- Query fnd_extnstats_cols table to confirm that extended statistics do not exist. fnd_exnstats_cols is FND table
which holds the columns on which extension stats will be created.
no rows selected
Table analyzed.
set serveroutput on
- check if virtual column is created for the multi-columns involved for the extended statistics.
select owner,table_name,column_name,histogram from dba_tab_cols where table_name like 'FND_LOOKUP_VALUES' and owner
='APPLSYS';
15
Best Practices for Gathering Statistics with Oracle E-Business Suite
- Gather statistics on 'FND_LOOKUP_VALUES' to check if histogram is getting created on the virtual column
exec fnd_stats.gather_table_stats('APPLSYS','FND_LOOKUP_VALUES');
select owner,table_name,column_name,histogram from dba_tab_cols where table_name like 'FND_LOOKUP_VALUES' and owner
='APPLSYS';
- Above output shows that the height balanced histogram is created on the virtual column
- Now check the changes in the explain plan of the select for the different values of view_application_id and
lookup_type
explain plan for select * from FND_LOOKUP_VALUES where VIEW_APPLICATION_ID=201 and lookup_type=:b2;
Explained.
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 30 | 4560 | 27 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| FND_LOOKUP_VALUES | 30 | 4560 | 27 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U2 | 30 | | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
explain plan for select * from FND_LOOKUP_VALUES where VIEW_APPLICATION_ID=3 and lookup_type='NO_POSTAL_CODE'
Explained.
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 12580 | 1867K| 2729 (2)| 00:00:33 |
|* 1 | TABLE ACCESS FULL| FND_LOOKUP_VALUES | 12580 | 1867K| 2729 (2)| 00:00:33 |
---------------------------------------------------------------------------------------
explain plan for select * from FND_LOOKUP_VALUES where VIEW_APPLICATION_ID=3 and lookup_type='AE_ARIA_CODE';
Explained.
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 24 | 3648 | 22 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| FND_LOOKUP_VALUES | 24 | 3648 | 22 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U2 | 24 | | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
16
Best Practices for Gathering Statistics with Oracle E-Business Suite
---------------------------------------------------
2 - access("LOOKUP_TYPE"='AE_ARIA_CODE' AND "VIEW_APPLICATION_ID"=3)
Result: Above results shows the cardinality estimation changes after creating multi column extended stats.
Incremental statistics gathering is a new feature of 11G Database. Incremental stats will work only for partitioned tables
where global statistics are updated incrementally by scanning only the partitions that have changed from the last run. This
simple example demonstrates how you might deploy the Oracle 11g incremental Statistics Gathering feature in Oracle E-
Business Suite.
- Create a table xla_ae_lines_bkp as a partition table to perform this test case
- Insert data from xla_ae_lines table
exec fnd_stats.gather_table_stats('XLA','XLA_AE_LINES_BKP');
Elapsed: 00:00:29.06
- It took 29.06 sec to gather stats for the first time after data insertion.
- Check the statistics and global and partition level
TABLE_NAME last_analyzed
------------------------------ ------------------------
XLA_AE_LINES_BKP 23-SEP-12 07:04:34
PARTITION_NAME last_analyzed
------------------------------ ------------------------
AP 23-SEP-12 07:04:15
AR 23-SEP-12 07:04:16
CE 23-SEP-12 07:04:16
CST 23-SEP-12 07:04:23
DPP 23-SEP-12 07:04:23
FUN 23-SEP-12 07:04:23
FV 23-SEP-12 07:04:23
GMF 23-SEP-12 07:04:23
IGC 23-SEP-12 07:04:23
IGI 23-SEP-12 07:04:23
LNS 23-SEP-12 07:04:23
OFA 23-SEP-12 07:04:23
OKL 23-SEP-12 07:04:23
OZF 23-SEP-12 07:04:23
PA 23-SEP-12 07:04:24
PAY 23-SEP-12 07:04:24
PN 23-SEP-12 07:04:24
PO 23-SEP-12 07:04:24
PSB 23-SEP-12 07:04:24
- Delete the data from one of the partition to check how statistics are getting calculated
exec fnd_stats.gather_table_stats('XLA','XLA_AE_LINES_BKP');
Elapsed: 00:00:14.06
- After deleting the data ran gather stats without setting the preference. It took 14.06 sec
17
Best Practices for Gathering Statistics with Oracle E-Business Suite
TABLE_NAME last_analyzed
------------------------------ ------------------------
XLA_AE_LINES_BKP 23-SEP-12 07:10:26
PARTITION_NAME last_analyzed
------------------------------ ------------------------
AP 23-SEP-12 07:10:14
AR 23-SEP-12 07:10:14
CE 23-SEP-12 07:10:14
CST 23-SEP-12 07:10:15
DPP 23-SEP-12 07:10:15
FUN 23-SEP-12 07:10:15
FV 23-SEP-12 07:10:15
GMF 23-SEP-12 07:10:15
IGC 23-SEP-12 07:10:15
IGI 23-SEP-12 07:10:15
LNS 23-SEP-12 07:10:16
OFA 23-SEP-12 07:10:16
OKL 23-SEP-12 07:10:16
OZF 23-SEP-12 07:10:16
PA 23-SEP-12 07:10:17
PAY 23-SEP-12 07:10:17
PN 23-SEP-12 07:10:17
PO 23-SEP-12 07:10:17
PSB 23-SEP-12 07:10:17
19 rows selected.
NOTE : statistics are gathered on all the partitions even though only AR parition data is deleted, last_analyzed is
updated for all the partitions.
- Perform the same test case after setting the preference to true. Following command will set the incremental
preference at the table level so next time when gather statistics is run, it will gather stats incremental on this
table
- Drop and Recreate the table xla_ae_lines_bkp as a partition table to perform this test case
- Insert data from xla_ae_lines table
exec dbms_stats.set_table_prefs('XLA','XLA_AE_LINES_BKP','INCREMENTAL','TRUE');
DBMS_STATS.GET_PREFS('INCREMENTAL','XLA','XLA_AE_LINES_BKP')
------------------------------------------------------------
TRUE
exec fnd_stats.gather_table_stats('XLA','XLA_AE_LINES_BKP');
Elapsed: 00:00:22.91
- After setting the preference it took 22.91 sec to gather statistics for the first time after data insertion
- checking stats timing information
TABLE_NAME last_analyzed
------------------------------ ------------------------
XLA_AE_LINES_BKP 23-SEP-12 07:17:32
18
Best Practices for Gathering Statistics with Oracle E-Business Suite
PARTITION_NAME last_analyzed
------------------------------ ------------------------
AP 23-SEP-12 07:17:30
AR 23-SEP-12 07:17:12
CE 23-SEP-12 07:17:10
CST 23-SEP-12 07:17:21
DPP 23-SEP-12 07:17:21
FUN 23-SEP-12 07:17:12
FV 23-SEP-12 07:17:10
GMF 23-SEP-12 07:17:10
IGC 23-SEP-12 07:17:10
IGI 23-SEP-12 07:17:12
LNS 23-SEP-12 07:17:10
OFA 23-SEP-12 07:17:10
OKL 23-SEP-12 07:17:12
OZF 23-SEP-12 07:17:30
PA 23-SEP-12 07:17:12
PAY 23-SEP-12 07:17:12
PN 23-SEP-12 07:17:12
PO 23-SEP-12 07:17:10
PSB 23-SEP-12 07:17:30
19 rows selected.
- Deleting the data from one partition to see how incremental statistics gathering will help next time when stats are
gathered.
exec fnd_stats.gather_table_stats('XLA','XLA_AE_LINES_BKP');
Elapsed: 00:00:04.11
- After deleting the data for one partition incremental gathering statistics took 4.11 sec
- Check global and partition statistics
TABLE_NAME last_analyzed
------------------------------ ------------------------
XLA_AE_LINES_BKP 23-SEP-12 07:26:20
PARTITION_NAME last_analyzed
------------------------------ ------------------------
AP 23-SEP-12 07:17:30
AR 23-SEP-12 07:26:18
CE 23-SEP-12 07:17:10
CST 23-SEP-12 07:17:21
DPP 23-SEP-12 07:17:21
FUN 23-SEP-12 07:17:12
FV 23-SEP-12 07:17:10
GMF 23-SEP-12 07:17:10
IGC 23-SEP-12 07:17:10
IGI 23-SEP-12 07:17:12
LNS 23-SEP-12 07:17:10
OFA 23-SEP-12 07:17:10
OKL 23-SEP-12 07:17:12
OZF 23-SEP-12 07:17:30
PA 23-SEP-12 07:17:12
PAY 23-SEP-12 07:17:12
PN 23-SEP-12 07:17:12
PO 23-SEP-12 07:17:10
PSB 23-SEP-12 07:17:30
19 rows selected.
Elapsed: 00:00:00.01
Note : statistics are gathered, last_analyzed date is changed for only AR partition and timing has also reduced.
19
Best Practices for Gathering Statistics with Oracle E-Business Suite
- With the above test case we can see improvement in timings when incremental preference is set.
- Timing information:
exec DBMS_STATS.SET_GLOBAL_PREFS('CONCURRENT','TRUE');
system altered.
exec DBMS_STATS.SET_GLOBAL_PREFS('CONCURRENT','FALSE');
exec dbms_stats.delete_table_stats('XLA','XLA_AE_HEADERS');
exec fnd_stats.gather_table_stats('XLA','XLA_AE_HEADERS');
Elapsed: 00:29:30.97
exec DBMS_STATS.SET_GLOBAL_PREFS('CONCURRENT','TRUE');
exec dbms_stats.delete_table_stats('XLA','XLA_AE_HEADERS');
- Gathering Statistics
exec fnd_stats.gather_table_stats('XLA','XLA_AE_HEADERS');
Elapsed: 00:26:59.54
From the above test cases, we see fnd_stats (with parallel option, as fnd_stats runs by default with parallel option)
with setting global preference to FALSE took 29 mins and 30 secs. fnd_stats ran with setting global preference to TRUE,
took 26 mins and 59 secs. We see a net gain of 2 mins 5 secs in the gather statistics timing. And even this small gain
could be explained by blocks already being in cache.
20
Best Practices for Gathering Statistics with Oracle E-Business Suite
Whitepapers
These papers are generic and do not specifically focus on Oracle E-Business Suite.
Best Practices for Gathering Optimizer Statistics
This paper provides an extensive overview of the Oracle Database statistics gathering process and is a useful precursor
to this paper. It should be considered as the source for many of the generic statements in this document. This is
available on the Oracle Optimizer blog: https://blogs.oracle.com/optimizer/ and Oracle Technet:
http://www.oracle.com/technetwork/database/bi-datawarehousing/dbbi-tech-info-optmztn-092214.html
Understanding Optimizer Statistics
This document provides more foundation information about Optimizer statistics and related topics. For example, it
includes a clear explanation of the different types of histograms and where they are applicable. This could be
considered a precursor to the Best Practices for Gathering Optimizer Statistics paper. This is available on Oracle Technet:
http://www.oracle.com/technetwork/database/focus-areas/bi-datawarehousing/twp-optimizer-stats-concepts-110711-1354477.pdf
Upgrading from Oracle Database 10g to 11g: What to expect from the Optimizer
This paper introduces the new Oracle 11g Optimizer features and outlines essential steps before and after the upgrade
in order to avoid performance regressions related to plan changes that are likely to occur. This is available on Oracle
Technet: http://www.oracle.com/technetwork/database/focus-areas/bi-datawarehousing/twp-upgrading-10g-to-11g-what-to-ex-
133707.pdf
Blogs
21
Best Practices for Gathering Statistics with Oracle E-Business Suite
The Oracle Optimizer blog ( https://blogs.oracle.com/optimizer ) contains excellent generic information on a number of topics
from the author of the Best Practices for Gathering Optimizer Statistics paper.
Topics include the following
Extended Statistics
Concurrent Statistics Gathering
Maintaining statistics on large partitioned tables
Fixed Objects Statistics and why they are important
In addition there are articles on other tuning related issues such as cardinality feedback.
22
Best Practices for Gathering Statistics with Oracle E-Business Suite
Figure 1 :
Oracle E-Business Suite - Gather Table Statistics Concurrent Request Submission window
Figure 1 shows an example of submitting Gather Table Statistics. Note that Estimate Percent is blank; a description of the
parameters follows.
PARAMETER DESCRIPTION
Estimate Percent The sampling percentage. If left blank, for 11g defaults to dbms_stats.auto_sample_size and for
23
Best Practices for Gathering Statistics with Oracle E-Business Suite
10g and prior it the default value of 10 is used. The valid range is from 0 to 100.
Degree The degree of parallelism to be used when gathering statistics. If a Degree is not provided, it
defaults to the minimum of parallel_max_servers and cpu_count.
Granularity The granularity of statistics to collect (only relevant for partitioned tables). Valid values are:
DEFAULT - Gather global and partitionlevel statistics.
SUBPARTITION - Gather subpartitionlevel statistics.
PARTITION - Gather partitionlevel statistics.
GLOBAL - Gather global statistics.
ALL - Gather all (subpartition, partition, and global) statistics.
History Mode This parameter controls the number of history records. The options, which are discussed in the
History Mode section, include LASTRUN, FULL and NONE. The default is LASTRUN.
Invalidate Dependent Cursors This indicates whether dependent cursors should be invalidated. This parameter is ignored prior
to Oracle 9iR2
24
Best Practices for Gathering Statistics with Oracle E-Business Suite
The Gather Schema Statistics program gathers table, column and index statistics for every object in the schema. This
program calls the FND_STATS.GATHER_SCHEMA_STATS package; the parameters are shown in Table B2. This is the
recommended process to run in order to update Oracle E-Business Suite statistics. Various considerations are explained
throughout the main part of this paper. When the collection time exceeds the available time slot, it may be useful to exclude
very large tables and schedule these at different times.
If this procedure fails at any time during operation, supplying the request ID, for the request that failed, can restart it. The
request ID, which can be queried from the FND_STATS_HIST table, is captured when the program is started from
concurrent manager or will be automatically created if the FND_STATS.GATHER_SCHEMA_STATS is used directly or
in a custom script.
Figure 2 :
Oracle E-Business Suite - Gather Schema Statistics Concurrent Request Submission window
Figure 2 shows an example of submitting Gather Schema Statistics. Note that Estimate Percent is blank; a description of
the parameters follows.
PARAMETER DESCRIPTION
Schema Name ALL will collect statistics for every registered Oracle E-Business Suite schema listed in
FND_PRODUCT_INSTALLATIONS table.
Estimate percent The sampling percentage. If left blank, for 11g defaults to dbms_stats.auto_sample_size and for
10g and prior it the default value of 10 is used. The valid range is from 0 to 100.
25
Best Practices for Gathering Statistics with Oracle E-Business Suite
Degree The degree of parallelism for gathering statistics. Default value is MIN (DB init parameters:
parallel_max_servers, cpu_count).
Restart Request ID If the Gather Schema Statistics run failed or was stopped, it can be re-submitted with this
parameter and it will pick up where the failed run left off.
History Mode This parameter controls the number of history records. The options, which are discussed in the
History Mode section, include LASTRUN, FULL and NONE. The default is LASTRUN.
Gather Options This parameter specifies how objects are selected for statistics gathering.
GATHER (Default) - All schema tables and indexes are selected for statistics gathering.
GATHER_AUTO - Tables of the schema schemaname for which the percentage of modifications
has exceeded modpercent are selected for statistics gathering. Table monitoring needs to be
enabled before using this option.
GATHER_EMPTY - Statistics are gathered only for tables and indexes that are missing
statistics.
LIST_AUTO - It only provides a list of objects for gather statistics if GATHER_AUTO is used.
LIST_EMPTY - It only provides a list of objects for gather statistics if GATHER_EMPTY is used.
Modification Threshold This option is applicable only to GATHER AUTO and LIST AUTO options. This parameter
specifies the percentage of modifications that have to take place on a table before it can be
picked up for AUTO statistics gathering.
Invalidate Dependent Cursors This indicates whether dependent cursors should be invalidated. The default is 'Y'.
26
Best Practices for Gathering Statistics with Copyright 2013, Oracle and/or its affiliates. All rights reserved.
Oracle E-Business Suite
Aug 2013 This document is provided for information purposes only, and the contents hereof are subject to change without notice. This
document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied in
Authors: Deepak Bhatnagar, Mohammed
law, including implied warranties and conditions of merchantability or fitness for a particular purpose. We specifically disclaim any
Saleem, Andy Tremayne
liability with respect to this document, and no contractual obligations are formed either directly or indirectly by this document. This
Editor: Robert Farrington document may not be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without our
prior written permission.
Oracle E-Business Suite Performance Group Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Oracle Corporation
Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and
World Headquarters
are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron, the AMD logo, and the AMD Opteron logo are
500 Oracle Parkway
trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group. 0113
Redwood Shores, CA 94065
U.S.A.
Worldwide Inquiries:
Phone: +1.650.506.7000
Fax: +1.650.506.7200
oracle.com