[Reproduced] Oracle performance tuning - statistical data collection

There are two categories of optimization methods of the ORACLE optimizer, namely rule-based optimization (Rule-Based Optimization, referred to as RBO) and cost-based optimization (Cost-Based Optimization, referred to as CBO).

A. RBO method: When the optimizer analyzes the SQL statement, it follows some rules predetermined by Oracle according to the definition information of tables and indexes in the database. For example, we are common: when a column in a where clause has an index, go to the index instead of the full table scan.
B. CBO method: According to the meaning of the word, it is the cost (Cost) of the sentence. For cost-based queries, the database comprehensively decides to select an execution plan that the database thinks is optimal (actually not necessarily optimal) based on the statistics of the collected table and index data (statistics are collected through the analyze command or using the dbms_stats package). . Statistics give information about the size of the table, how many rows it has, the length of each row, etc.
Note: These statistics are not in the library at first, they are collected periodically according to the analyze command or the dbms_stats package, so many times outdated statistics will cause the optimizer to make a wrong execution plan, because some We shall promptly update this information. In order to use the cost-based optimizer (CBO), you must frequently run the analyze or dbms_stats command to increase the accuracy of object statistics in the database.
In Oracle8 and later versions, Oracle strongly recommends the CBO method.

1. How to view object statistics (object statistics)

For CBO mode, object statistics are very important. How can I view object statistics?
The statistical information about tables in Oracle is in the data dictionary, which can be queried by SQL, eg:
SELECT table_name,num_rows, blocks, empty_blocks AS empty, avg_space, chain_cnt, avg_row_len
FROM dba_tables
WHERE owner = 'ONT'
AND table_name = 'OE_ORDER_LINES_ALL';
TABLE_NAME NUM_ROWS BLOCKS EMPTY AVG_SPACE CHAIN_CNT AVG_ROW_LEN
OE_ORDER_LINES_ALL 0 544 505
data dictionary can be seen The table has 5344 records in the statistics, let's verify it with SQL:
select count(*) from apps.OE_ORDER_LINES_ALL;
found that the return is 16518 records, it can be seen that the statistics of this table are relatively old, the real data and statistics to data are quite different. In this case, if a View uses this Table and the system uses CBO, it may cause Oracle's optimizer to give an inefficient execution plan.

At this point, you can use ANALYZE to re-statistics the OE_ORDER_LINES_ALL table, you can run SQL:
ANALYZE TABLE ONT.OE_ORDER_LINES_ALL COMPUTE STATISTICS;
Query the data dictionary again:
TABLE_NAME NUM_ROWS BLOCKS EMPTY AVG_SPACE CHAIN_CNT AVG_ROW_LEN
OE_ORDER_LINES_ALL 16518 1530 1035 865 257 643

found that the information at this time is the latest. With more correct statistics, the optimizer can give an efficient execution plan.

2. Concurrent requests: Statistics Collection Mode (FNDGSCST) / Gather Schema Statistics

There are several Gather-related standard Requests in Oracle ERP:
Gather All Column Statistics –FND_STATS.GATHER_ALL_COLUMN_STATS()
Gather Column Statistics –FND_STATS.GATHER_COLUMN_STATS()
Gather Schema Statistics -FND_STATS.GATHER_SCHEMA_STATS()
Gather Table Statistics -FND_STATS.GATHER_TABLE_STATS()
Check the way FND_STATS Package is written, in fact, it is calling some Functions in Standard's Package dbms_stats in Oracle DB.
The commonly used Gathers in Oracle DB are as follows. DBAs can also run these Functions directly at the Database level regularly, so that Oracle can count the latest database status:
dbms_stats.gather_database_stats();
dbms_stats.gather_schema_stats();
dbms_stats.gather_table_stats();
dbms_stats.gather_index_stats();

Oracle CBO requires the system to regularly analyze statistical tables/indexes. Only in this way can CBO use the correct SQL access path to improve query efficiency. Therefore, it is very important to run ANALYZE or dbms_stats regularly at the Instance Level with optimizer_mode = choose, especially after the data volume has changed greatly since the last statistics.
Note: Statistical operations are very resource-intensive actions and should be performed when the system Loading is small.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326664501&siteId=291194637