Home » RDBMS Server » Performance Tuning » What is a effecting a analyzing a table for CBO.
What is a effecting a analyzing a table for CBO. [message #65543] |
Thu, 21 October 2004 03:03  |
BhavinShah
Messages: 105 Registered: February 2004
|
Senior Member |
|
|
Dear frends,
I have read in Oracle Tuning guide that CBO is using data dictionary for generating a plan.
I wanted to know that what is a effect of CBO plan before analyze a table and after analyze table.
Can anybody give me Practical example.
Diffns of Before analyze statistics and after analyze statistics.
Thax in advance..
Bhavin Shah
|
|
|
Re: What is a effecting a analyzing a table for CBO. [message #65548 is a reply to message #65543] |
Thu, 21 October 2004 05:57   |
 |
Mahesh Rajendran
Messages: 10708 Registered: March 2002 Location: oracleDocoVille
|
Senior Member Account Moderator |
|
|
Ok.
Lets do some stuff.
--
-- By analyzing the tables, you are collecting the statistics.
-- Before analyze the stats are not collected.
-- after analyze you udpate the stats (if it is already collected).
-- These stats are used by the CBO to identify and lay a shortest path
-- or 'route' to fetch the data.
-- So by course of time, the data changes in base table.(deletes,updates,inserts).
-- But the CBO still works on the stats you have collected BEFORE.
-- So if you will update the stats, the CBO will understand the changes that has happened.
-- PLEASE follow the session
--
-- Lets create a small table
--
mag@mutation_mutation > create table mytable as select * from dba_segments;
Table created.
--
-- set the tracing options to seeting plan
-- You can see 1322 rows are returned by sql
-- Plan show you nothing about rows returned...
--
mag@mutation_mutation > set autotrace on explain
mag@mutation_mutation > select count(*) from mytable;
COUNT(*)
----------
1322
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'MYTABLE'
--
-- Lets analyze the table
--
mag@mutation_mutation > analyze table mytable compute statistics;
Table analyzed.
--
-- run the same sql again
-- Now the plan shows something called COST and CARD
-- card=1322 means, CBO got these stats based on prior analyze.
-- To fetch 1322 rows the cost is 3.
mag@mutation_mutation > select count(*) from mytable;
COUNT(*)
----------
1322
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'MYTABLE' (Cost=3 Card=1322)
--
-- Now, lets truncate the table.
-- run the same query.
-- You will find something intresting.
-- even though all records are gone, the CBO still thinks there are some records in table.
-- SO the cost is generated based on that,
-- and THE plan is generated based on that.
-- THis is becuase the STATISTICS was outdated .!!!
mag@mutation_mutation > truncate table mytable;
Table truncated.
mag@mutation_mutation > select count(*) from mytable;
COUNT(*)
----------
0
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'MYTABLE' (Cost=3 Card=1322)
--
-- Now lets analyze the table and run the same query.
-- with updated statistics
-- The CARD is low and Is the COST.
-- NOTE: This example doesnt deal with real world. SO the plan does not change much.
--
mag@mutation_mutation > analyze table mytable compute statistics;
Table analyzed.
mag@mutation_mutation > select count(*) from mytable;
COUNT(*)
----------
0
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'MYTABLE' (Cost=2 Card=1)
|
|
|
|
|
Goto Forum:
Current Time: Thu Jun 05 01:49:48 CDT 2025
|