How does the plan change in both cases?
Hope eveything else remains the same and the tests are done on the same object.
Main Topics
Browse All TopicsI am running a medium sized databse (75 Gig) on a Unix server with Oracle 9i
What is the difference between Analyze Table and DBMS_STATS ?
I understand that Analyze table is a depricated feature and *everyone* claims that DBMS_STATS is better and should be used. However....
when I run the following:
ANALYZE TABLE PS_SCRTY_QUERY ESTIMATE STATISTICS SAMPLE 40 PERCENT
and then execute a query against that table the buffer gets is around 17.
When I execute
exec DBMS_STATS.GATHER_TABLE_ST
and then run a query against the PS_SCRTY_QUERY table, the buffer gets is at 410
Even if buffer gets are not the definitive metric for determining performance, but this struck me as not good.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
First : My apologies about the mis-stated code above. Both queries *did* estimate the table at 40%. I changed the DBMS to 100% in an effort to figure out why the buffer gets were so large. I then copied the wrong query when I posted the question.
Second: The explain plan remains constant. Regardless of how the table statistics get generated.
Had I not been maintaining an exact history of all 3,000 queries that are executed on a daily basis and their footprints, I would not have caught this discrepency. Keeping in mind that many of the queries resulted in a very similar footprint between analyze and DBMS.
I have confirmed that when I use:
exec DBMS_STATS.GATHER_TABLE_ST
the performance is *MUCH* worse than when I use:
ANALYZE TABLE PS_SCRTY_QUERY ESTIMATE STATISTICS SAMPLE 40 PERCENT
Buffer gets, CPU, and Disk Reads go through the roof when I use the new "preferred" method of analyzing tables.
>>If the execution plan is the same, why should performance differ?
That is kind of the root of my question. When I run an explain plan on a query, the explain plan is identical between the analyze table and the dbms_gatether stats. However, all of our monitoring software indicates a much higher usage of CPU, Bugger gets and IO.
So... Back to my original question:
What is the difference between Analyze Table and DBMS_STATS ?
Are your measurements of gets, reads, cpu, etc repeatable or do they occur only on the first attempt after you gather?
analyzing both, run the queries multiple times (make sure it's parsed and cached as well as it's going to be) and then turn on tracing and run each. you can trace the collection itself too and capture the queries executed by each if you want to see the exact differences between them
confirm the plans that are really being used are in fact identical.
if you are getting different results then the execution must be different.
of course, you can always query the stats themselves and see what's different.
query the views below where TABLE_NAME = 'PS_SCRTY_QUERY'
DBA_ALL_TABLES
DBA_OBJECT_TABLES
DBA_TABLES
DBA_TAB_PARTITIONS
DBA_TAB_SUBPARTITIONS
DBA_INDEXES
DBA_IND_PARTITIONS
DBA_IND_SUBPARTITIONS
DBA_TAB_COLUMNS
DBA_TAB_COL_STATISTICS
DBA_PART_COL_STATISTICS
DBA_SUBPART_COL_STATISTICS
and compare the results after each stat collection method
Business Accounts
Answer for Membership
by: QlemoPosted on 2009-01-25 at 15:59:17ID: 23463298
In DBMS_STATS you created full scan statistics, while in analyze table only estimated. I guess the same result would be achieved when you use a analyze with full sample.
Additionally, cascade in DBMS_STATS scans dependend objects, and (re)creates those statistics. This could lead to the conclusion that more buffer (!) reads could be better than several real physical I/O.