Reputation: 11
What is the best to do among the following commands ?
exec dbms_stats.gather_table_stats
dbms_stats.gather_schema_stats
which one improves the database performances?
Upvotes: 1
Views: 156
Reputation: 15144
Oracle does stats gathering anyway regularly since 10g. Have you noticed the standard gathering is too rare or not detailed enough in your case? The default of estimate_percent < 100 can lead to bad plans in 10g.
The statistics gathering might one of the optimizations you will apply but we cannot know in advance. Before you augment Oracle's default statistics gathering you would look for sub-optimal query plans that would not be chosen with manually gathered statistics.
This excellent paper by Cary Millsap might help you: http://method-r.com/downloads/doc_details/44-thinking-clearly-about-performance
Upvotes: 2
Reputation: 4055
both. neither. depends.
What do you mean by "the database performances"? Gathering stats on existing tables and indexes MAY help if the stats are out of date. But they aren't a magic bullet that will replace adding helpful indexes for use by problem queries.
updating stats on one table may be all that you need for your problem. Updating stats on ALL indexed columns might be in order. Or these may not be the issues that you are dealing with from a performance perspective. Good indexes won't help baddly written queries.
You need to figure out WHAT SPECIFICALLY is slow before you can figure out how to fix it. For sure there is not one accelerator pedal for the entire database - no matter how we all might wish there was.
Upvotes: 3
Reputation: 132680
They both improve database performance (or rather, they both gather statistics that will be used by the oprtimiser and may improve performance). GATHER_SCHEMA_STATS gathers statistics for all objects in a schema. GATHER_TABLE_STATS does it for just one table. You can read all about them in the documentation.
Upvotes: 5