Skip to Main Content
  • Questions
  • GATHER_STATS_JOB how AUTO parameters decided and hwo to find individual object start and end stats gather time

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, abhishek.

Asked: February 11, 2016 - 9:24 am UTC

Last updated: February 12, 2016 - 11:07 am UTC

Version: 10g

Viewed 1000+ times

You Asked

hi Team,

greetings!!

hope all of your doing good :) . really appreciate your efforts in helping the entire oracle community :).

the scenarios I have is as follows:

In our database the stats gather process is taken care by GATHER_STATS_JOB job which automatically starts and ends based on the maintenance window timings.

below are my questions:

1.) how can I figure out the start time and end time of stats gather for a particular object (so far I can only figure out the start and end time of the stats gather job). do we need to enable debugging or perform similar activity.

2.) in the database the "degree" parameter of parallelism is set as AUTO. so how much parallel will oracle allow. is it decided based on the load on the server at that point and some other factors?

3.) the parameter AUTOSTATS_TARGET is set as AUTO
I got the below information from the oracle documentation:

The GATHER_STATS_JOB job gathers optimizer statistics by calling the DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC procedure. The GATHER_DATABASE_STATS_JOB_PROC procedure collects statistics on database objects when the object has no previously gathered statistics or the existing statistics are stale because the underlying object has been modified significantly (more than 10% of the rows).

but in our database we have some tables for which the modification is more than 10% but still stats are not being gathered. can you please help me understand the cause behind this ?

4.) how is the priority decided? what factors decide the priority is it ?is it someting like when underlying object has been modified significantly (more than 10% of the rows).

I got the below information from oracle documentation.

DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC is an internal procedure,
but its operates in a very similar fashion to the DBMS_STATS.GATHER_DATABASE_STATS procedure using the GATHER A
UTO option. The primary difference is that the DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC procedure prioritizes
the database objects that require statistics, so that those objects which most need updated statistics are
processed first. This ensures that the most-needed statistics are gathered before the maintenance window closes.


Thanks
Abhishek

and Chris said...

1. There isn't a direct way. You can compare the difference in last_analyzed times from dba_tables:

select table_name, last_analyzed ,
       (last_analyzed - lag(last_analyzed) over (order by last_analyzed)) * 86400 time_in_s
from   dba_tables
where  last_analyzed > sysdate - 1
order  by 1 desc, table_name;


Last_analyzed is a date, so it only has precision to the second. So this is non-deterministic if you have small tables than take less than a second to analyze.

2. The auto degree is either 1 (for small object) or up to the limit calculated as follows:

PARALLEL_THREADS_PER_CPU X CPU_COUNT

http://www.oracle.com/technetwork/database/bi-datawarehousing/twp-bp-for-stats-gather-12c-1967354.pdf

3. How are you determining that the table has changed by more than 10%?

You should calculate it using the following:

select (m.inserts + m.updates + m.deletes) / t.num_rows
from   user_tab_modifications m
join   user_tables t
on     t.table_name = m.table_name;


If this is > 10%, are stats on the table locked?

4. The stale percentage (number of rows modified - default 10) determines whether an object needs stats or not. Objects below this threshold aren't analyzed. I don't have the exact algorithm, but it will be based on those the changed percentage (the query above) and those tables with no stats.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

thanks for very useful information

abhishek nayak, February 12, 2016 - 8:54 am UTC

thanks a lot Chris. the information is very helpful. thanks again.

Regards Abhishek
Connor McDonald
February 12, 2016 - 11:07 am UTC

Glad we could help.

More to Explore

Analytics

Analytic SQL got you confused? Check out Connor McDonald's complete video course.