Understanding Oracle Execution Plans is the first step in optimization, let's start with the example below.
The following supplementary content
1. Create Test table
[SQL] view plain copy sql> create table t as Select 1 id,object_name from Dba_objects; Table created sql> update t set id=99 where rownum=1; 1 row updated sql> commit; Commit Complete sql> CREATE index t_ind on t (ID); Index created
Oracle Optimizer: Rbo and CBO two kinds, from the oracle10g start optimizer has abandoned the Rbo, the following illustration shows how the CBO is probably
[SQL] View Plain copy sql> select /*+dynamic_sampling (t 0) */* from t where id=1; 50819 rows selected. execution plan ---------------------------------------------------------- plan hash value: 1376202287 -------------------------------------------- ----------------------------------------- | id | operation | name | Rows | Bytes | Cost (%CPU) | time | ------------------------------------------------------------------------------------- | 0 | select statement | | 195 | 15405 | 51 (0) | 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| T | 195 | 15405 | 51 (0) | 00:00:01 | |* 2 | index range scan | T_IND | 78 | | 50 (0) | 00:00:01 | ---------------- --------------------------------------------------------------------- predicate information (identified by operation id): ------------------------------------- --------------&NBsp; 2 - access ("ID" =1)
The
T table has not been analyzed, suggesting that/*+dynamic_sampling (T 0) */* is designed to allow the CBO to get the actual data in the table through dynamic sampling, At this point the CBO can only guess the data in the table based on the very limited information in the T table (such as the number of extents in the table, the number of data blocks). As you can see from the results, the CBO guessed that there are 195 id=1 in the table, which is a very small value for the total number of tables, so the CBO chooses the index rather than the full table scan.
The actual situation looks like this:
[SQL] View plain copy sql> Select * from t where