Link to home
Create AccountLog in
Avatar of _TAD_
_TAD_

asked on

Analyze Table made performance worse! -- help!

I ave a relatively large database that had some minor performance issues.  I had been going through and Analyzing tables and computing statistics.  This improved overall efficiency and the number of buffer gets went down dramatically.


That is, until I analyzed a table that was really out of wack.  The table stats claimed to have 400,000 rows, but a select count(*) showed about a million.  So I analyzed the table and computed statistics.  

When I did that, a query that was only using about 30 buffer gets per transaction now uses over 1,000 buffer gets for the same transaction.

The explain plan shows that the index is no longer being used.  Instead it is doing a full table scan.

What's up with that?  How do I fix it?
Avatar of Sean Stuber
Sean Stuber

how did you analyze?
analyze or dbms_stats?

did you analyze the indexes with the table?
Did you gather histograms?  (should you have? usually no, but sometimes yes you must)
is the table partitioned?  did you gather partition level statistics?


what is the query?
and what are the original and new plans?
Avatar of _TAD_

ASKER

I ran the following SQL:

Analyze Table <TableName> Compute Statistics;

The last analyzed data time stamp on the idexes match the date-time stamp of the table

no histograms were gathered

The table is not partitioned.

Further, overall query performance against this table has improved tremendously when using other indexes.  The problem is that this one particular index is performing much, much worse -- and the query is run several hundred times a day.

As sdstuber said, you need to analyze the indexes also.

Avatar of _TAD_

ASKER

indexes analyzed.  No change
do not use analyse, it is being deprecated.

what i use is : dbms_stats.gather_table_stats( 'owner', 'table_name', block_sample => true, cascade => true, estimate_percent => 10, method_opt => 'FOR ALL COLUMNS SIZE AUTO' );

try that and see what happens.
Avatar of _TAD_

ASKER

While I understand that Analyze is, in some circumstances, not as efficient as dbms_stats.  I have not heard that it is being depricated.  It is my understanding that some statistics like high water mark cannot be gotten through dbms_stats, but instead must use analyze.

That being said, I did a full compute, not an estimation.  the dms_stats must be a really awesome tool to produce more accurate statistics with a 10% estimation than a full analysis of 100% of the data.
ASKER CERTIFIED SOLUTION
Avatar of rbrooker
rbrooker
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi,
  fastest solution to try - delete statistics:
analyze table TABLE_NAME delete statistics;

painful, but right solution (in 9i only):
  think about changing the SQL SELECTs, use some indexing hints etc.

you can also try change index cost for session (1-1000 and more :-) like thist (100 - default):
alter session set optimizer_index_cost_adj=100;
Try some lower values and look how the cost in explain plan changes.

Vorbis
Avatar of _TAD_

ASKER



I wound up rewriting the daemon procedures instead.

The original process....

Count the number of records that... <condition>
If count > 0 Then run process.
   Process... load temp table & cursor use prev. count to itterate through processes one at a time.


New Process....

Select 1 where exists... <condition>

Count the number of records that... <condition>
If count > 0 Then run process.
   Process... load temp table & cursor use prev. count to itterate through processes one at a time.



The original code USED to only use 21 buffer gets right up until the processing.   After the compute of statistics it started to use over 1,000.  Not a big deal normally, but the process runs a few hundred times a day (running the count SQL each and every time).

Now the process does the "where exists" and that uses 11 additional Buffer Gets over the old process (which currently uses 1,000+) -- but only where there is something there to process.  

In a nutshell, I am still taking a big performance hit, but instead of having the highest number of buffer gets in a single day, the new code is somewhere in the middle -- and I can live with that.
can you post your before and after code with the before and after execution plans?

we'll all help, but we need something to work from.