Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1722
  • Last Modified:

How to use DBMS_STATS

We are planning to use dbms_stats package instead of ANALYZE statement .

We are collecting statistics by using the follwing statements with ANALYZE ;

1) ANALYZE TABLE table_name ESTIMATE STATISTICS ;

2) ANALYZE TABLE table_name ESTIMATE STATISTICS
  FOR TABLE
  FOR ALL INDEXES
  FOR ALL INDEXED COLUMN SIZE 100 ;

3) ANALYZE TABLE table_name PARTITION (partition_name) ESTIMATE STATISTICS ;

My question is if I use DBMS_STATS.GATHER_TABLE_STATS package and pass ownname tabname and estimate_percent
then will it be same as "ANALYZE TABLE table_name ESTIMATE STATISTICS " or
" ANALYZE TABLE table_name ESTIMATE STATISTICS
FOR TABLE
FOR ALL INDEXES
FOR ALL INDEXED COLUMN SIZE 1 "

How can I use the above statement to execute 1 & 2 .
I think if I set cascade to TRUE will run the 2nd statement and if I don't pass will take default value
which is FALSE will run the 1st statement . Please clarify .
0
bperumandla
Asked:
bperumandla
1 Solution
 
soraCommented:
dbms_stats.gather_table_stats gets the table, index and column statistics for the specified table and partition. Parition is optional. If not specified it gathers stats for all partitions into which this table is divided.

So, to answer your question, DBMS_STATS.GATHER_TABLE_STATS is similar to

" ANALYZE TABLE table_name ESTIMATE STATISTICS
FOR TABLE
FOR ALL INDEXES
FOR ALL INDEXED COLUMN SIZE 1 "

But note that with DBMS_STATS, you can EXTIMATE only by a % (percentage) and not a specific number of rows - whereas with ANALYZE you can estimate for a specific number of rows as well.


For more on DBMS_STATS package, see this URL:

http://technet.oracle.com/docs/products/oracle8i/doc_library/817_doc/appdev.817/a76936/dbms_sta.htm#999107

You need a technet account, but it is free.


sora
0
 
waynezhuCommented:
The dbms_stats package can not accomplish the 2) to gather the column statistics, the histograms. Although its parallel implementation can speedup the statistics
gathering (if implemented correctly), in reality,
ANALYZE is still indispensible  
0
 
p_yaroslavCommented:
Hi!

Sora is not completely right (see p.2)!
_____________________________________________________
1. For statement "ANALYZE TABLE table_name ESTIMATE STATISTICS;"
------------------------
If you specify ANALYZE TABLE ESTIMATE
STATISTICS without a sample size, Oracle will only gather statistics based on 1064 rows.  This is important to note because depending on how large the table is, you may get inadequate statistics for the object being analyzed.
------------

In dbms_stats package you may set estimate_percent parameter by analogy with "ANALYZE TABLE ESTIMATE STATISTICS SAMPLE SIZE 20 PERCENT".

dbms_stats.gather_schema_stats('OWNER','TABLE_NAME',estimate_percent=>20).
________________________________________________________

2. For statement "ANALYZE TABLE table_name ESTIMATE STATISTICS
 FOR TABLE
 FOR ALL INDEXES
 FOR ALL INDEXED COLUMN SIZE 100 ;"

dbms_stats.gather_schema_stats('OWNER','TABLE_NAME',estimate_percent=>20,cascade='TRUE',method_opt=>'FOR ALL INDEXED COLUMNS SIZE 100').

cascade: default value is FALSE!
method_opt: default value is 'FOR ALL COLUMNS SIZE 1'

 method_opt - method options of the following format (the phrase 'SIZE 1' is required to ensure gathering statistics in parallel and for use with the phrase hidden): FOR ALL [INDEXED | HIDDEN] COLUMNS [SIZE integer] FOR COLUMNS [SIZE integer] column|attribute [,column|attribute ...]



Best regards!
Yaroslav


0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
soraCommented:
Yaroslav - Thanks for the correction.

Yes, I missed to mention about the DEFAULT=FALSE part

Cheers!

sora
0
 
soraCommented:
bperumandla - just out of curiosity, may I know why you want to switch from ANALYZE to DBMS_STATS

sora
0
 
MindphaserCommented:
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,

** Mindphaser - Community Support Moderator **
0
 
anand_2000vCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
points spto be given to Sora
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

anand_2000v
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now