17
17.11.2010 Page 1 of 17 SAP Note 588668 - FAQ: Database statistics Note Language: English Version: 78 Validity: Valid Since 09.02.2010 The displayed SAP Note is not up to date in the selected language / Summary Symptom 1. What are database statistics used for? 2. When are database statistics not required? 3. What type of information is covered by database statistics? 4. What are histograms? 5. How damaging are old statistics? 6. What are the disadvantages of creating new statistics? 7. How can I restore old statistics? 8. How can database statistics be created? 9. How does BRCONNECT proceed when creating statistics? 10. What is the difference between DBMS_STATS and ANALYZE TABLE? 11. Are the statistics of DBMS_STATS and ANALYZE compatible? 12. How should statistics usually be created? 13. Can I create statistics while the system is running? 14. How can I determine when an object was last analyzed? 15. How can I determine whether Oracle DDIC tables contain statistics? 16. How can I determine, whether there are any statistics relating to fixed objects? 17. Why do some tables not contain any new statistics even though a statistical run was carried out with BRCONNECT? 18. Why is it that frequently, only the primary indexes have new statistics after a BRCONNECT run? 19. How can I force the creation of statistics with BRCONNECT for a table? 20. How can I use BRCONNECT to create new statistics for all tables? 21. With what degree of accuracy does BRCONNECT create statistics? 22. How can I determine tables whose statistics have too low a sample size? 23. What is the DBSTATC table used for?

sapnote_0000588668

Embed Size (px)

Citation preview

Page 1: sapnote_0000588668

17.11.2010 Page 1 of 17

SAP Note 588668 - FAQ: Database statistics

Note Language: English Version: 78 Validity: Valid Since 09.02.2010

The displayed SAP Note is not up to date in the selected language /

Summary

Symptom

1. What are database statistics used for?

2. When are database statistics not required?

3. What type of information is covered by database statistics?

4. What are histograms?

5. How damaging are old statistics?

6. What are the disadvantages of creating new statistics?

7. How can I restore old statistics?

8. How can database statistics be created?

9. How does BRCONNECT proceed when creating statistics?

10. What is the difference between DBMS_STATS and ANALYZE TABLE?

11. Are the statistics of DBMS_STATS and ANALYZE compatible?

12. How should statistics usually be created?

13. Can I create statistics while the system is running?

14. How can I determine when an object was last analyzed?

15. How can I determine whether Oracle DDIC tables contain statistics?

16. How can I determine, whether there are any statistics relating tofixed objects?

17. Why do some tables not contain any new statistics even though astatistical run was carried out with BRCONNECT?

18. Why is it that frequently, only the primary indexes have newstatistics after a BRCONNECT run?

19. How can I force the creation of statistics with BRCONNECT for a table?

20. How can I use BRCONNECT to create new statistics for all tables?

21. With what degree of accuracy does BRCONNECT create statistics?

22. How can I determine tables whose statistics have too low a samplesize?

23. What is the DBSTATC table used for?

Page 2: sapnote_0000588668

17.11.2010 Page 2 of 17

SAP Note 588668 - FAQ: Database statistics

24. How can exceptions to the standard procedure be defined during thecreation of statistics with BRCONNECT?

25. Which statement does BRCONNECT use internally to create statistics?

26. How can I control the use of ANALYZE and DBMS_STATS?

27. How can I accelerate the creation of statistics?

28. How I can determine whether table, index or column statistics aremissing?

29. What are system statistics?

30. What should I take into account with respect to the statistics forpartitioned objects?

31. What special features apply to statistics in the BW environment?

32. Can I manipulate statistics to trigger a preferable access path?

33. Can statistics be transported from one system to another?

34. Can the NUM_ROWS field be filled with decimal figures?

35. Are statistics lost during an Oracle or R/3 upgrade?

36. How are statistical values included in the CBO cost calculation?

37. Why does DB20 report statistics as obsolete, even if they have justbeen created?

38. Can I use Oracle tools such as DBMS_STATS instead of BRCONNECT forregular statistic creation?

39. Does BRCONNECT also support new 10g statistics features, such aslocking statistics?

40. Can entries in DBSTATC be transported?

41. How can I reduce the scope of the statistics history?

42. Where can I find more information about database statistics?

Other termsFrequently asked questions

Reason and Prerequisites

Solution

1. What are database statistics used for?

The Cost Based Optimizer (CBO) requires database statistics in orderto use the most suitable access path (for example, index access, full

Page 3: sapnote_0000588668

17.11.2010 Page 3 of 17

SAP Note 588668 - FAQ: Database statistics

table scan, join types) to access the required data for SELECT, UPDATEand DELETE statements. To do this, the system uses the statistics toselect the access path with the fewest expected I/O operations.

Database statistics can also be used as part of database monitoring(for example, to determine memory requirements).

2. When are database statistics not required?

No statistics are required if you are using the Rule Based Optimizer(RBO):

o R/3 <= 3.1I

o SAP table pools and table clusters

o Other tables with exception processing in accordance with DBSTATC(Note 122718)

o If RULE hints are explicitly specified

o Oracle DDIC objects (exception: Large BW systems, Note 558746)

o When the TP transport control program is used for an import,statistics are deleted by default on the DDXTT, DDXTF, TATAF,TRBAT, TRBATC and TRBAT2 tables so that you can use the RBO (seeNote 564161).

No statistics are required for insert statements either, since theinserts carried out are based on Freelist entries.

As of Oracle Release 10g, you generally require database statistics.

3. What type of statistics are there and where are they stored?

Statistics are saved in the Oracle Data Dictionary. Different types ofstatistics are available:

o Table statistics:

- Access using the DBA_TABLES view

- These contain information such as the number of rows(NUM_ROWS), number of blocks used (NUM_BLOCKS), accuracy(SAMPLE_SIZE) or date of last statistics creation(LAST_ANALYZED)

o Index statistics:

- Access using the DBA_INDEXES view

- Contain information such as the size of the index tree(BLEVEL), number of leaf blocks (LEAF_BLOCKS), number ofdifferent keys (DISTINCT_KEYS), key figure for assigning indexvs. table (CLUSTERING_FACTOR, see Note 832343), accuracy(SAMPLE_SIZE) or date of last statistics creation(LAST_ANALYZED).

Page 4: sapnote_0000588668

17.11.2010 Page 4 of 17

SAP Note 588668 - FAQ: Database statistics

o Column statistics:

- Access using the DBA_TAB_COLUMNS view

- Contain information such as the number of different values(NUM_DISTINCT), lowest value (LOW_VALUE), highest value(HIGH_VALUE), accuracy (SAMPLE_SIZE) or date of the laststatistics creation (LAST_ANALYZED)

o Histogram information (optional):

- Access using the DBA_TAB_HISTOGRAMS view

- Contains (75 items or less by default) bucket informationconsisting of the bucket number (ENDPOINT_NUMBER) and bucketfinal value (ENDPOINT_ACTUAL_VALUE).

o System statistics (Note 927295)

- Access using SYS.AUX_STATS$

- Contains information about the weighting of Single Block Reads,Multi Block Reads and CPU consumption.

- Only used in the SAP environment as of Oracle Release 10g.

4. What are histograms?

Histograms describe the distribution of column values between thelowest existing value (LOW_VALUE) and the highest existing value(HIGH_VALUE). For more information, see Note 797629.

5. How damaging are old statistics?

No conclusions can be made as to how good or bad the existingstatistics are, based on their age. The decisive factor affecting thequality of statistics is how well the current dataset is represented.Even "old" statistics generally still correspond to the currentdataset.

6. What are the disadvantages of creating new statistics?

Every change to the statistics can cause changed accesses to the CBOIn most cases, changed access caused by new statistics have a positiveeffect on performance. Such changes can have negative consequences ina small number of cases. In this context, note the followingrecommendations:

If you have manually modified the statistics to optimize performance,as described in Note 724545, you should avoid creating any newstatistics for the affected tables. However, if you still want tocreate new statistics, you will need to make the manual changesdescribed in Note 724545 again.

7. How can I restore old statistics?

Creating new statistics always involves the risk that individual

Page 5: sapnote_0000588668

17.11.2010 Page 5 of 17

SAP Note 588668 - FAQ: Database statistics

accesses may be compromised. In this case, it is helpful if you canretrieve the previous statistics quickly. In addition, the followingpossibilities are available:

o If you use DBMS_STATS to create the statistics, as of Oracle 10g,you can retrieve previous statistics from a table usingDBMS_STATS.RESTORE_TABLE_STATS. Using the following command, youcan restore the statistics that existed a day ago, for example:

EXEC DBMS_STATS.RESTORE_TABLE_STATS('<owner>', '<table_name>', SYSDATE - 1);

o Otherwise, you can only restore old statistics if you saved themexplicitly using DBMS_STATS.EXPORT_TABLE_STATS. You can retrievestatistics that you saved using DBMS_STATS.IMPORT_TABLE_STATS.Refer to Note 448380 for further details.

8. How can database statistics be created?

There are various ways to create database statistics:

o Oracle tools and commands:

- ANALYZE command (see Oracle documentation)

- DBMS_STATS package (see Oracle documentation and Note 448380)

o SAP tools:

- BRCONNECT 6.10 or higher (see SAP online documentation and Note403704)

- Transaction DB20

- Report RSANAORA

9. How does BRCONNECT proceed when creating statistics?

In the usual scenario, BRCONNECT functions in two phases:

a) First, it determines whether new statistics are required: Newstatistics are only required if the number of table entries sincethe last statistics creation has changed by more than one thresholdvalue (parameter stats_change_threshold, default: 50%) BRCONNECTthen creates new statistics: BRCONNECT 7.00 (36) and higherreleases contain tables in which a Data Definition Language (DDL)operation has occurred such as online reorganization, SHRINK, orADD COLUMN (see Note 1235952, point 2).

b) Creating new statistics: If the first phase resulted in the needfor new statistics, and the system has met further conditions (noalternative entry in the DBSTATC control table, no table pool ortable cluster, and so on), new statistics are created.

10. What is the difference between DBMS_STATS and ANALYZE?

DBMS_STATS is a more recent method for creating statistics that isexpected to replace ANALYZE in the long term. You can observe the

Page 6: sapnote_0000588668

17.11.2010 Page 6 of 17

SAP Note 588668 - FAQ: Database statistics

following differences when using DBMS_STATS instead of ANALYZE:

o Advantages of DBMS_STATS:

- It is possible to use histograms for global statistics ofpartitioned objects

- Table-internal parallel processing is possible (Note 408532)

- Correct statistics even for columns with identical characterstrings in the first 32 characters (Note 365480)

- You can transport statistics to other systems

- You can back up and reactivate statistics

o Disadvantages of DBMS_STATS:

- DBMS_STATS only determines statistical data that is relevant toCBO. For monitoring purposes, the system does not calculateuseful columns such as AVG_SPACE, EMPTY_BLOCKS,AVG_SPACE_FREELIST_BLOCKS or NUM_FREELIST_BLOCKS. As a result,you cannot make assertions about space utilization andfragmentation on the basis of this value with DBMS_STATSstatistics, for example.

- No statistics for cluster tables

- Oracle 8i: Histograms cannot be created when you use parallelprocessing.

11. Are the statistics of DBMS_STATS and ANALYZE compatible?

The two types of statistics are not fully compatible, which causesproblems when you create DBMS_STATS statistics for objects withANALYZE statistics and vice versa. For more information, see Note489352.

When changing the method, you should therefore first delete statisticsusing the function of the method used to date ("ANALYZE TABLE ...DELETE STATISTICS" or DBMS_STATS.DELETE_..._STATS) before newstatistics are created. Deletion of these old statistics has alreadybeen implemented in current versions of BRCONNECT and BW.

12. How should statistics usually be created?

To keep the statistics up-to-date, we recommend that you schedule thefollowing at least once weekly (Oracle 9i or lower) or at least oncedaily (Oracle 10g or higher):

brconnect ... -f stats -t all

. Irrespective of the number of table lines or (in the case ofactivated table monitoring) the contents of DBA_TAB_MODIFICATIONS,this run checks which table requires new statistics in the first step.In the second step, new statistics are created for the tables thatwere determined to need them. You can use transaction DB13 to schedulethese runs (see Note 132861).

Page 7: sapnote_0000588668

17.11.2010 Page 7 of 17

SAP Note 588668 - FAQ: Database statistics

If new columns or indexes are created (even in transports - refer toNote 657536 for more information), the table statistics must beupdated (for instance, using transaction DB20). Other functions suchas DB13, BRCONNECT without special force options, or the sole analysisof an index (whether newly created or reorganized) can causeincomplete statistics and then cause considerable performanceproblems. As of Oracle 10g, Oracle automatically creates indexstatistics when an index is created. This means that you do not needto also create the statistics manually.

In some situations, statistics are also created implicitly:

o After special BW actions such as aggregate rollup or change runs;Note 555030 describes how you can deactivate this automaticcreation if required.

o At the end of a reorganization with SAPDBA

Note 1057511 describes an alternative to generating statisticsregularly using BRCONNECT. This procedure means that experiencedadministrators do not need to use BRCONNECT as frequently, providedcertain precautions are followed.

13. Can I create statistics while the system is running?

Creating statistics does not block any database objects. In theory,therefore, you can create statistics while the system is running.However, since the creation of statistics involves an additional CPUand I/O load, it should be carried out during a period of minimalworkload, if at all possible.

14. How can I determine when an object was last analyzed?

For tables, execute the following statement at Oracle level:

SELECT TO_CHAR(LAST_ANALYZED, 'DD.MM.YYYY, HH24:MI:SS') FROM DBA_TABLES WHERE OWNER = '<table_owner>' AND TABLE_NAME = '<table_name>';

For indexes, replace DBA_TABLES with DBA_INDEXES and TABLE_NAME withINDEX_NAME in the statement above.

15. How can I determine whether Oracle DDIC tables contain statistics?

You can use the following SELECT statement to determine whether andwhich objects from the Oracle data dictionary contain statistics:

SELECT TABLE_NAMEFROM DBA_TABLESWHERE LAST_ANALYZED IS NOT NULL AND OWNER = 'SYS';

Note 138639 describes the cases in which you should create statisticsfor the Oracle DDIC.

16. How can I determine, whether there are any statistics relating tofixed objects?

Page 8: sapnote_0000588668

17.11.2010 Page 8 of 17

SAP Note 588668 - FAQ: Database statistics

As of Oracle 10g, we recommend that you use fixed object statistics(refer to Note 838725). You can check whether these statistics havebeen created or not as follows:

SELECT TABLE_NAMEFROM DBA_TAB_STATISTICSWHERE LAST_ANALYZED IS NOT NULL AND OWNER = 'SYS' ANDTABLE_NAME LIKE 'X$%';

If the query returns X$ tables, then fixed object statistics exist.

17. Why do some tables not contain any new statistics even though astatistical run was carried out with BRCONNECT?

Before BRCONNECT creates new statistics, the tool checks whether newstatistics are required. No new statistics are created if there havebeen no significant changes in the number of entries in a table.

18. Why is it that frequently, only the primary indexes have newstatistics after a BRCONNECT run?

To determine the current number of table entries in the check phase,BRCONNECT executes an ANALYZE of the primary index. This is muchfaster than accessing the (larger) table yourself. For this reason,the primary indexes always receive new statistics - even if it turnsout that the table does not require any new statistics.

The system deviates from the above rule if table monitoring isactivated (Notes 408527, 628590). In this case, there is no need toanalyze the primary index and as a result, the primary indexes do notreceive any new statistics.

19. How can I force the creation of statistics with BRCONNECT for a table?

You can do this by additionally specifying the force options

-f collect,allsel,keep

(these ensure that statistics are always created even if changes aremade to table rows, entries in DBSTATC and the table type). This typeof call is also generated when you create statistics in transactionDB20.

Note that the force options are expert settings that should only beused in exceptional circumstances.

20. How can I use BRCONNECT to create new statistics for all tables?

It may be useful in some situations to create new statistics for alltables without a necessity check. Tables that normally receive nostatistics should, of course, be left out of the statistic creation.You can do this using the following call:

brconnect -u / -c -f stats -t all -f collect

21. With what degree of accuracy does BRCONNECT create statistics?

Page 9: sapnote_0000588668

17.11.2010 Page 9 of 17

SAP Note 588668 - FAQ: Database statistics

The accuracy of new statistics depends on the size of the table:

o Fewer than 10,000 rows: Exact calculation (COMPUTE)

o Fewer than 100,000 rows: ESTIMATE with 30 % of the table

o Fewer than 1,000,000 rows: ESTIMATE with 10 % of the table

o Fewer than 10,000,000 rows: ESTIMATE with 3 % of the table

o More than 10,000,000 rows: ESTIMATE with 1% of the table

If the number of table blocks (BLOCKS) is greater than the number ofrows (NUM_ROWS), the system uses the blocks instead of the rows as thebasis for the sample size.

As of BRCONNECT 7.00 (27), we introduced other smaller sample sizesfor very large tables (Note 892296, point 9).

22. How can I determine tables whose statistics have too low a samplesize?

You can use the following statement to determine the statistics oflarger tables (more than 50,000 entries), which were created with lessthan 20% of the accuracy used by BRCONNECT by default:

SELECT TABLE_NAME, NUM_ROWS, SAMPLE_SIZE, TO_CHAR(LAST_ANALYZED, 'dd.mm.yyyy hh24:mi:ss') LAST_ANALYZEDFROM DBA_TABLESWHERE NUM_ROWS > 50000 AND SAMPLE_SIZE > 100 AND SAMPLE_SIZE < 0.2 * NUM_ROWS * DECODE(NUM_ROWS, 0, 0, DECODE(TRUNC(LOG(10,

GREATEST(NUM_ROWS, BLOCKS))), 0, 1, 1, 1, 2, 1, 3, 1, 4, 0.3, 5, 0.1, 6, 0.03, 7, 0.01, 8, 0.003, 9, 0.001, 10, 0.0003, 11, 0.0001, 12, 0.00003, 0.00001))ORDER BY 4 ASC;

Sample sizes <= 100 are percentages that were specified in earlierOracle releases instead of row numbers, and are therefore excludedfrom the check.

Check whether there is a plausible explanation for the lower accuracyof the statistics (for example, a DBSTATC entry), otherwise create newstatistics.

NUM_ROWS values on the order of approximately 1065 are created forlarge tables when you use an "ANALYZE TABLE ... ESTIMATE STATISTICS"statement without specifying a sample size (such as when you createstatistics manually without using BRCONNECT).

Page 10: sapnote_0000588668

17.11.2010 Page 10 of 17

SAP Note 588668 - FAQ: Database statistics

If the SAMPLE_SIZE value is demonstrably lower than the sample sizeyou specified for the last statistic creation, this may be caused byfragmentation effects. For more information, see Note 821687 also.

If you implement predefined statistics in accordance with Note1020260, SAMPLE_SIZE no longer fits the imported values. Therefore,you can ignore the tables mentioned in Note 1020260 here.

If you generate statistics using BRCONNECT after a restructuring ofthe the system (that is, at a point where no CBO statistics existyet), a sample size of one percent is used by default. You may have tocreate the statistics again (using the option "-f collect") to obtainlarger sample sizes.

23. What is the DBSTATC table used for?

DBSTATC contains predefined exceptions for calculating statistics withBRCONNECT. For more information, see Note 122718.

Statistics are calculated normally for tables that are not defined inDBSTATC (unless there is another exception, such as table pool/tablecluster or R/3 3.1I).

24. How can I define additional exceptions to the standard procedure increating statistics with BRCONNECT?

In some individual cases, the statistics created by BRCONNECT are notoptimal. In these cases, you may require greater accuracy in theanalysis or you may need to create statistics with additionalhistograms. To make these settings permanent, you can add an entry inthe DBSTATC table as described in Note 106047.

25. Which statement does BRCONNECT use internally to create statistics?

o Oracle 9i or lower

To create statistics, BRCONNECT calls ANALYZE TABLE with severalFOR conditions, by default. The following is an example of anestimate with 10%:

ANALYZE TABLE <table_name> ESTIMATE STATISTICS SAMPLE 10 PERCENT FOR TABLE FOR ALL INDEXES FOR ALL INDEXED COLUMNS SIZE 1;

With this statement, table statistics ("FOR TABLE"), indexstatistics for all indexes belonging to the table ("FOR ALLINDEXES") and column statistics for all indexed columns ("FOR ALLINDEXED COLUMNS") are created without histograms ("SIZE 1").

As of BRCONNECT 6.40, the system creates statistics for ALL columns("FOR ALL COLUMNS") by default.

o Oracle 10g or higher

As of Release 10g, by default, BRCONNECT uses DBMS_STATS to createstatistics. A typical DBMS_STATS call looks like:

DBMS_STATS.GATHER_TABLE_STATS

Page 11: sapnote_0000588668

17.11.2010 Page 11 of 17

SAP Note 588668 - FAQ: Database statistics

( OWNNAME => '"<owner>"', TABNAME => '"<table_name>"', ESTIMATE_PERCENT => <percentage>, METHOD_OPT => 'FOR ALL COLUMNS SIZE 1', DEGREE => NULL, CASCADE => TRUE, NO_INVALIDATE => FALSE);

This statement creates table statistics, index statistics ("CASCADE =>TRUE") and all column statistics ("FOR ALL COLUMNS") withouthistograms ("SIZE 1").

26. How can I control the use of ANALYZE and DBMS_STATS?

You can use the stats_dbms_stats parameter to specify the use ofDBMS_STATS for some or all tables or for ANALYZE (see Note 424239).

27. How can I accelerate the creation of statistics?

See Note 806554.

28. How I can determine whether table, index or column statistics aremissing?

During its statistics runs, BRCONNECT checks only the tables and indextables. This means that missing column statistics can no longer becreated over a long period of time. In addition, up until Release6.20, BRCONNECT created statistics only for indexed columns. In themeantime, however, it is advisable to create statistics for allcolumns (Note 723894).

The following SQL statements allow you to determine the missingstatistics manually:

o Indexes with missing statistics:

SELECT T.TABLE_NAME, I.INDEX_NAMEFROM DBA_TABLES T, DBA_INDEXES IWHERE I.OWNER = T.OWNER AND I.TABLE_NAME = T.TABLE_NAME ANDT.LAST_ANALYZED IS NOT NULL AND I.LAST_ANALYZED IS NULLAND INDEX_TYPE != 'LOB';

o Indexed columns with missing statistics:

SELECT SUBSTR(T.OWNER, 1, 15) OWNER,SUBSTR(T.TABLE_NAME, 1, 30) TABLE_NAME,SUBSTR(TC.COLUMN_NAME, 1, 15) COLUMN_NAME,T.NUM_ROWS NUM_ROWSFROM DBA_TABLES T, DBA_TAB_COLUMNS TC, DBA_IND_COLUMNS ICWHERE T.OWNER = IC.TABLE_OWNER AND TC.OWNER = IC.TABLE_OWNER AND T.TABLE_NAME = IC.TABLE_NAME AND TC.TABLE_NAME = IC.TABLE_NAME AND TC.COLUMN_NAME = IC.COLUMN_NAME AND T.LAST_ANALYZED IS NOT NULL AND TC.LAST_ANALYZED IS NULL

Page 12: sapnote_0000588668

17.11.2010 Page 12 of 17

SAP Note 588668 - FAQ: Database statistics

ORDER BY 4 DESC, 1 ASC, 2 ASC, 3 ASC;

o All columns with missing statistics:

SELECT SUBSTR(T.OWNER, 1, 15) OWNER,SUBSTR(T.TABLE_NAME, 1, 30) TABLE_NAME,SUBSTR(TC.COLUMN_NAME, 1, 15) COLUMN_NAME,T.NUM_ROWS NUM_ROWSFROM DBA_TABLES T, DBA_TAB_COLUMNS TCWHERE T.OWNER = TC.OWNER AND T.TABLE_NAME = TC.TABLE_NAME AND TC.DATA_TYPE NOT IN ('CLOB', 'BLOB', 'NCLOB', 'BFILE', 'LONG', 'LONG RAW') AND T.LAST_ANALYZED IS NOT NULL AND TC.LAST_ANALYZED IS NULLORDER BY 4 DESC, 1 ASC, 2 ASC, 3 ASC;

If results are returned, new statistics should be created for therelevant tables (to create statistics for all columns with BRCONNECT6.40 or higher). This also creates all index and column statistics.

As of Oracle 10g, statistics must exist for ALL SAP tables. You canuse the following statement to check whether there are still SAPtables without statistics under 10g.

SELECT T.OWNER, T.TABLE_NAME, TO_CHAR(O.CREATED, 'dd.mm.yyyy hh24:mi:ss') CREATION_TIMEFROM DBA_TABLES T, DBA_OBJECTS OWHERE T.OWNER = O.OWNER AND T.TABLE_NAME = O.OBJECT_NAME AND T.OWNER LIKE 'SAP%' AND T.LAST_ANALYZED IS NULL AND O.OBJECT_TYPE = 'TABLE';

When the system returns tables, the reason for the missing statisticsshould be identified and new statistics should be created.

29. What are system statistics?

System statistics are a new type of statistic, available as of Oracle9, which contains system-specific information about CPU and I/Obehavior. For more information, see Note 927295.

30. What should I take into account with respect to the statistics forpartitioned objects?

Statistical information for partitions is located in the Oracle viewsDBA_TAB_PARTITIONS, DBA_IND_PARTITIONS and DBA_PART_COL_STATISTICS.

Partitioned objects may have global (cross-partition) or local(partition-based) statistics. The GLOBAL_STATS field indicates whetheror not global statistics have been created.

Page 13: sapnote_0000588668

17.11.2010 Page 13 of 17

SAP Note 588668 - FAQ: Database statistics

Note 524341 contains more information about creating statistics forpartitioned objects with BRCONNECT. While we previously recommendedthat you use the ANALYZE method to create statistics, you can also useDBMS_STATS as of BRCONNECT 6.40 (Note 744483).

31. What special features apply to statistics in the BW environment?

Refer to the corresponding information in Note 1013912.

32. Can I manipulate statistics to trigger a preferable access path?

Yes, as of Oracle 8.1, you can change statistical data usingDBMS_STATS packages. For more information on this topic, see Note724545.

If you change statistics manually, the USER_STATS entry belonging tothe statistics is converted from NO to YES. You can therefore use thiscolumn value to find out whether statistics were manipulated.

33. Can statistics be transported from one system to another?

Yes, this is also possible as of Oracle 8.1 using DBMS_STATS packages.For example, you can do this to simulate production systemrelationships with a large volume of data on a small test system.

34. Can the NUM_ROWS field be filled with decimal figures?

In certain cases, Oracle may fill the NUM_ROWS field (which recordsthe number of rows in the object) with decimal figures instead ofintegers. This behavior is normal and does not present a problem.

35. Are statistics lost during an Oracle or R/3 upgrade?

Statistics are retained during an Oracle and R/3 upgrade and do nothave to be recreated.

36. How are statistical values included in the CBO cost calculation?

Note 750631 describes rules of thumb for the cost calculation oftypical database accesses based on parameters and statistics.

37. Why does DB20 report statistics as obsolete, even if they have justbeen created?

DB20 compares the current number of rows in the table with the numberof the rows the last time the statistics were created. If thedifference between these numbers exceeds a defined threshold value(default value is 50%), the statistics are regarded as obsolete.

To estimate the current number of table entries, an analysis of theprimary index is performed with the default statistics accuracy. Ifthe accuracy is low or the index is heavily fragmented, the estimatedresult deviates significantly from reality and DB20 reports obsoletestatistics, even though the statistics are current.

In most cases, reconstructing the index (see Note 332677) or creatingthe statistics with greater accuracy helps in this case.

Page 14: sapnote_0000588668

17.11.2010 Page 14 of 17

SAP Note 588668 - FAQ: Database statistics

38. Can I use Oracle tools such as DBMS_STATS instead of BRCONNECT forregular statistic creation?

The Oracle package DBMS_STATS provides numerous options forautomatically updating obsolete statistics (for example, GATHER STALE,GATHER AUTO), that can be executed periodically based on the Oraclejob system. SAP does not support periodic creation of statistics forR/3 using these Oracle mechanisms (refer to Note 105047). Instead, youshould always use BRCONNECT.

39. Does BRCONNECT also support new 10g statistics features, such aslocking statistics?

Note 892296 describes new functions in BRCONNECT 7.00, which aremainly aimed at supporting the new Oracle 10g functions.

40. Can entries in DBSTATC be transported?

The table DBSTATC is not connected to the SAP transport system. If youwant to transport the DBSTATC table, you can do so with an explicittransport using the Workbench Organizer. (Refer to Note 211105).

41. How can I reduce the scope of the statistics history?

As of Oracle 10g, Oracle keeps old statistics for 31 days by defaultto maintain the option of being able to activate such statistics againusing DBMS_STATS.RESTORE_TABLE_STATS. In particular cases, the historystatistics can lead to a massive memory requirement in the SYSAUXtablespace. Segments with statistical data and a potentially largememory requirement are, for example:

WRI$_OPTSTAT_IND_HISTORYI_WRI$_OPTSTAT_HH_STI_WRI$_OPTSTAT_HH_OBJ_ICOL_STWRI$_OPTSTAT_HISTHEAD_HISTORYI_WRI$_OPTSTAT_H_STWRI$_OPTSTAT_HISTGRM_HISTORYI_WRI$_OPTSTAT_H_OBJ#_ICOL#_ST

The history statistics data can become particularly intense if histogram statistics are created on a large scale, as in the BWenvironment, for example. To reduce the scope of the authorizedhistory data, you can set the retention period to a decreased numberof days (decreased by two or more) as follows:

EXEC DBMS_STATS.ALTER_STATS_HISTORY_RETENTION (<days>);

Alternatively, you can deactivate the complete statistics history asfollows:

EXEC DBMS_STATS.ALTER_STATS_HISTORY_RETENTION (0);

To delete all statistics history data up to a certain date, you canexecute the following command:

EXEC DBMS_STATS.PURGE_STATS(<date>);

Page 15: sapnote_0000588668

17.11.2010 Page 15 of 17

SAP Note 588668 - FAQ: Database statistics

To delete all data up to two days ago, you can use the followingcommand:

EXEC DBMS_STATS.PURGE_STATS(SYSDATE - 2);

42. Where can I find more information about database statistics?

o Statistics creation with BRCONNECT

- SAP library 6.x-> mySAP Technology Components -> Database Interface, Database Platforms (BC-DB) -> SAP Database Guide: Oracle (BC-DB-ORA-DBA) -> Tools for Oracle DBA -> BRBACKUP, BRARCHIVE, BRRESTORE and BRCONNECT -> BRCONNECT -> Update Statistics with BRCONNECT

- http://service.sap.com/dbaora-> Media Library -> Performance -> Update Statistics for the Oracle Cost-based optimizer

o Creating statistics with Oracle tools:

- Oracle 9I documentation:Performance Tuning Guide and Reference -> Chapter 3: Gathering Optimizer StatisticsSupplied PL/SQL packages and Types Reference -> 70. DBMS_STATS

- Oracle Metalink documents:122009.1: How to retrieve Statistics generated by ANALYZE SQLStatement175258.1: How to compute Statistics on Partitioned Tables andIndexes with DBMS_STATS1031826.6: Histograms: An Overview97207.1: ANALYZE TABLE does not replace Statistics

Header Data

Release Status: Released for CustomerReleased on: 09.11.2010 09:14:06Master Language: GermanPriority: Recommendations/additional infoCategory: FAQPrimary Component: BC-DB-ORA Oracle

Secondary Components:BC-DB-ORA-DBA Database Administration withOracle

Page 16: sapnote_0000588668

17.11.2010 Page 16 of 17

SAP Note 588668 - FAQ: Database statistics

The Note is release-independent

Related Notes

Number Short Text

1232776 Long runtimes for accesses to D010INC or D010TAB

1095171 Exporting index statistics via DBMS_STATS fails

1057511 Collecting statistis - An alternative approach

1013912 FAQ: Oracle BW performance

927295 FAQ: Oracle system statistics

892296 Enhancements in update statistics in BRCONNECT 7.00/7.10

848708 Oracle Database Configuration for NWDI server

838725 Oracle dictionary statistics and system statistics

832343 FAQ: Clustering factor

826814 SMSY: Expanding 'Systems' takes a long time

825653 Oracle: Common misconceptions

821687 FAQ: Space utilization and fragmentation in Oracle

806554 FAQ: I/O-intensive database operations

797629 FAQ: Oracle histograms

766349 FAQ: Oracle SQL optimization

750631 Approximations for cost calculation of the CBO

744483 Changes in collection of statistics in BRCONNECT 6.40

724545 Adjusting the CBO statistics manually using DBMS_STATS

690702 Histograms cause long runtimes on Oracle 9

657536 Transports and DB Statistic Calculation

651812 FAQ: BR*TOOLS and SAPDBA

628590 Activating table monitoring using "-f monit" option

618868 FAQ: Oracle performance

590370 Too many uncompressed request (f table partitions)

564161 Transport profile parameter 'dropstatistics'

558746 Better Oracle Data Dictionary BW Performance

555030 Deactivating BW-initiated DB statistics

524341 Updating the statistics for individual partitions

448380 Information: Oracle Package DBMS_STATS

428212 Using BRCONNECT to update InfoCube statistics

424239 New BRCONNECT parameter: stats_dbms_stats

408532 Using the DBMS_STATS package for collecting statistics

408527 Checking the statistics using DBA_TAB_MODIFICATIONS

403713 BRCONNECT: Parallel updating of statistics

403704 BRCONNECT - Enhanced functions for Oracle DBA

365480 CBO: Field filled with leading "0" aligned to left

211105 DB21: You cannot create transport requests

Page 17: sapnote_0000588668

17.11.2010 Page 17 of 17

SAP Note 588668 - FAQ: Database statistics

Number Short Text

132861 CBO: Statistics creation with SAPDBA or BRCONNECT

129252 Oracle DB Statistics for BW Tables

122718 CBO: Tables with special treatment

106047 DB21: Customizing the DBSTATC

105047 Support for Oracle functions in the SAP environment