1

Reg Real-Time statistics which extends online statistics gathering(12c) to also include conventional DML statements. Real-time statistics helps the optimizer generate more optimal plans.Whereas bulk load operations gather all necessary statistics, real-time statistics augment rather than replace traditional statistics.

Oracle introduced new parameters

_optimizer_gather_stats_on_conventional_dml and _optimizer_use_stats_on_conventional_dml which are true by default and _optimizer_stats_on_conventional_dml_sample_rate at 100%

How does real time statistics works?

By default the _optimizer_gather_stats_on_conventional_dml is true so its automatically kicks off

When a DML operation is currently modifying a table (conventional), Oracle Database dynamically computes values for the most essential statistics if the above parameter is on.

Consider a example of table that is having lot of inserts and rows are increasing. Real-time statistics keep track of the increasing row count as rows are being inserted. If the optimizer performs a hard parse of a new query, then the optimizer can use the real-time statistics to obtain a more accurate cost estimate.

USER_TAB_COL_STATISTICS and USER_TAB_STATISITICS has columns NOTES tell real time statistics have been used. "STATS_ON_CONVENTIONAL_DML".

Execution Plan shows

|Id| Operation                        | Name|Rows|Bytes|Cost (%CPU)|Time| Pstart|Pstop|
---------------------------------------------------------------------------------------
| 0| INSERT STATEMENT                 |     |    |     |910 (100)|        |     |     |
| 1|  LOAD TABLE CONVENTIONAL         |SALES|    |     |         |        |     |     |
| 2|   OPTIMIZER STATISTICS GATHERING |     |918K|  25M|910   (2)|00:00:01|     |     |
| 3|    PARTITION RANGE ALL           |     |918K|  25M|910   (2)|00:00:01|   1 |  28 |
| 4|     TABLE ACCESS FULL            |SALES|918K|  25M|910   (2)|00:00:01|   1 |  28 |

Also the explain plan in the query used will tell in note section
    Note

    -----
    - dynamic statistics used: stats for conventional DML

LOAD TABLE CONVENTIONAL and OPTIMIZER STATISTICS GATHERING are the new parameters that have been added to the explain plan for this new feature.

can we apply real-time statistics only for a particular set of table . if yes, how can we achieve them ? , as we know getting real time statistics for any dml operation thats occuring for more that 100k rows is very costly operation

I tried finding out the way, but was not successfull

  • Be careful in wanting to know exactly how any parameters beginning with an underscore "_" as those are un-documented, and subject to change; so even if you could figure out how they currently work, it could change, or they could have bugs. If you encounter a performance issue where you have changed those parameters, the first thing Oracle Support will ask you to do is to un-set those parameters. – Mark Stewart May 18 at 15:10
0

First up, you should only change underscore parameters when instructed to do so by support. But more importantly for these parameters, Real-Time Statistics is only available on specific database offerings. See the license guide for details.

Changing these parameters is likely to be a violation of your license agreement!

LOAD TABLE CONVENTIONAL and OPTIMIZER STATISTICS GATHERING are the new parameters that have been added to the explain plan for this new feature.

These operations are not specific to Real-Time Statistics. OPTIMIZER STATISTICS GATHERING is for any operation that captures stats during execution. create table as select is an example that has done this for a while now.

LOAD TABLE CONVENTIONAL means the database does a conventional (not direct-path) insert.

You can disable Real-Time Statistics for:

  • A specific statement with the no_gather_optimizer_statistics hint
  • A table by locking stats for that table (though this will stop the background job gathering stats too!)

For example, only the first of these three inserts has the OPTIMIZER STATISTICS GATHERING operation:

set long 10000
set serveroutput off
cl scr
create table t as 
  select 1 c1 from dual
  connect by level <= 100;

insert /*+ monitor */into t 
with rws as (
  select level x from dual
  connect by level <= 10
)
  select * from rws;

select dbms_sqltune.report_sql_monitor (report_level=> 'basic +plan')
from   dual;

SQL Plan Monitoring Details (Plan Hash Value=2403765415)
======================================================================================================================================================
| Id |             Operation             | Name |  Rows   | Cost |   Time    | Start  | Execs |   Rows   | Read | Read  | Activity | Activity Detail |
|    |                                   |      | (Estim) |      | Active(s) | Active |       | (Actual) | Reqs | Bytes |   (%)    |   (# samples)   |
======================================================================================================================================================
|  0 | INSERT STATEMENT                  |      |         |      |         1 |     +0 |     1 |        0 |      |       |          |                 |
|  1 |   LOAD TABLE CONVENTIONAL         | T    |         |      |         1 |     +0 |     1 |        0 |    4 | 32768 |          |                 |
|  2 |    OPTIMIZER STATISTICS GATHERING |      |       1 |    2 |         1 |     +0 |     1 |       10 |      |       |          |                 |
|  3 |     VIEW                          |      |       1 |    2 |         1 |     +0 |     1 |       10 |      |       |          |                 |
|  4 |      CONNECT BY WITHOUT FILTERING |      |         |      |         1 |     +0 |     1 |       10 |      |       |          |                 |
|  5 |       FAST DUAL                   |      |       1 |    2 |         1 |     +0 |     1 |        1 |      |       |          |                 |
======================================================================================================================================================    

insert /*+ monitor no_gather_optimizer_statistics */ into t 
with rws as (
  select level x from dual
  connect by level <= 10
)
  select * from rws;

select dbms_sqltune.report_sql_monitor (report_level=> 'basic +plan')
from   dual;

SQL Plan Monitoring Details (Plan Hash Value=2403765415)
======================================================================================================================================
| Id |            Operation             | Name |  Rows   | Cost |   Time    | Start  | Execs |   Rows   | Activity | Activity Detail |
|    |                                  |      | (Estim) |      | Active(s) | Active |       | (Actual) |   (%)    |   (# samples)   |
======================================================================================================================================
|  0 | INSERT STATEMENT                 |      |         |      |         1 |     +0 |     1 |        0 |          |                 |
|  1 |   LOAD TABLE CONVENTIONAL        | T    |         |      |         1 |     +0 |     1 |        0 |          |                 |
|  2 |    VIEW                          |      |       1 |    2 |         1 |     +0 |     1 |       10 |          |                 |
|  3 |     CONNECT BY WITHOUT FILTERING |      |         |      |         1 |     +0 |     1 |       10 |          |                 |
|  4 |      FAST DUAL                   |      |       1 |    2 |         1 |     +0 |     1 |        1 |          |                 |
======================================================================================================================================    

exec dbms_stats.lock_table_stats ( user, 'T' );

insert /*+ monitor */into t 
with rws as (
  select level x from dual
  connect by level <= 10
)
  select * from rws;

select dbms_sqltune.report_sql_monitor (report_level=> 'basic +plan')
from   dual;

SQL Plan Monitoring Details (Plan Hash Value=2403765415)
======================================================================================================================================
| Id |            Operation             | Name |  Rows   | Cost |   Time    | Start  | Execs |   Rows   | Activity | Activity Detail |
|    |                                  |      | (Estim) |      | Active(s) | Active |       | (Actual) |   (%)    |   (# samples)   |
======================================================================================================================================
|  0 | INSERT STATEMENT                 |      |         |      |         1 |     +0 |     1 |        0 |          |                 |
|  1 |   LOAD TABLE CONVENTIONAL        | T    |         |      |         1 |     +0 |     1 |        0 |          |                 |
|  2 |    VIEW                          |      |       1 |    2 |         1 |     +0 |     1 |       10 |          |                 |
|  3 |     CONNECT BY WITHOUT FILTERING |      |         |      |         1 |     +0 |     1 |       10 |          |                 |
|  4 |      FAST DUAL                   |      |       1 |    2 |         1 |     +0 |     1 |        1 |          |                 |
======================================================================================================================================  

as we know getting real time statistics for any dml operation thats occuring for more that 100k rows is very costly operation

How do you know this?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.