analyze table compute statistics for table for all indexes for all indexed columns : analyze « SQL PLUS Session Environment « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> create table myTable as
  2  select decode( mod(rownum,100), 0, 'N', 'Y' ) processed, a.*
  3    from all_objects a;

Table created.

SQL>
SQL> create index processed_idx on myTable(processed);

Index created.

SQL>
SQL> select * from myTable where status = 'N';

no rows selected

SQL>
SQL>
SQL> analyze table myTable compute statistics
  2  for table
  3  for all indexes
  4  for all indexed columns
  5  /

Table analyzed.

SQL>
SQL> variable processed varchar2(1);
SQL> exec :processed := 'N'

PL/SQL procedure successfully completed.

SQL>
SQL> set autotrace traceonly explain
SQL>
SQL> select *
  2    from myTable
  3   where processed = 'N';

Execution Plan
----------------------------------------------------------
Plan hash value: 362789735

--------------------------------------------------------------------------------
-------------

| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU
)| Time     |

--------------------------------------------------------------------------------
-------------

|   0 | SELECT STATEMENT            |               |   126 | 11466 |     4   (0
)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| MYTABLE       |   126 | 11466 |     4   (0
)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | PROCESSED_IDX |   126 |       |     1   (0
)| 00:00:01 |

--------------------------------------------------------------------------------
-------------


Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("PROCESSED"='N')

SQL>
SQL>
SQL> select *
  2    from myTable
  3   where processed = :processed;

Execution Plan
----------------------------------------------------------
Plan hash value: 1015944200

-----------------------------------------------------------------------------
| Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |         |  6328 |   562K|    47   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| MYTABLE |  6328 |   562K|    47   (3)| 00:00:01 |
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("PROCESSED"=:PROCESSED)

SQL>
SQL> drop table myTable;

Table dropped.

SQL>
SQL> set autotrace off
SQL>
SQL>








29.33.analyze
29.33.1.analyze table compute statistics
29.33.2.analyze compute statistics on table with index
29.33.3.Analyze table with user defined column type
29.33.4.analyze table compute statistics for table for all indexes for all indexed columns
29.33.5.analyze and autotrace full outer join and union
29.33.6.analyze and autotrace single column key and multi-column key
29.33.7.analyze and autotrace table with primary key
29.33.8.analyze index t_idx validate structure
29.33.9.analyze table TABLENAME compute statistics;
29.33.10.analyze table after creating index
29.33.11.analyze table estimate statistics
29.33.12.analyze table students compute statistics
29.33.13.analyze table t compute statistics for table for columns id;
29.33.14.analyze table t compute statistics for table, for all indexes, for all indexed columns