miércoles, 7 de enero de 2009

SELECT que generan redo (Block Cleanouts)

En principio no existe razón para pensar que una simple instrucción de SELECT pudiese generar redo, sin embargo en algunos casos es posible que esto ocurra. Este fenómeno se presenta cuanto la cantidad de bloques que han sido modificados excede el 10% del total de bloques disponibles en el buffer chache. Veamos:

1) Nuestra BD de ejemplo tiene un total de 16M definidos para el buffer cache

SQL> show parameter DB_CACHE_SIZE

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_cache_size big integer 16777216


2) El tamaño del bloque de datos principal es 8k

SQL> show parameter DB_BLOCK_SIZE

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_cache_size integer 8192


Si la cantidad de bits definidos para el buffer cache la dividimos entre el tamaño en bits del bloque da datos principal (16777216/8192) obtenemos el numero total de bloques de datos disponibles en nuestro buffer cache es decir 2048 bloques que representan el 100% por lo que el 10% viene dado por 204,8 redondeando tenemos un total de 205 bloques. Con este marco veamos el ejemplo práctico:

SQL> create table hr.t ( x char(2000),y char(2000),z char(2000));

Table created.

SQL> insert into hr.t select 'x', 'y', 'z' from all_objects where rownum <= 118;

118 rows created.

SQL> commit;

Commit complete.

SQL> select blocks from dba_segments where owner='HR' and segment_name='T';

BLOCKS
----------
128

SQL> set autotrace traceonly statistics

SQL> select * from hr.t;

118 rows selected.

Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
122 consistent gets
0 physical reads
0 redo size
7983 bytes sent via SQL*Net to client
580 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
118 rows processed

SQL> set autotrace off

SQL> drop table hr.t;

Table dropped.

SQL> create table hr.t ( x char(2000),y char(2000),z char(2000));

Table created.

SQL> insert into hr.t select 'x', 'y', 'z' from all_objects where rownum <= 119;

119 rows created.

SQL> commit;

Commit complete.

SQL> select blocks from dba_segments where owner='HR' and segment_name='T';

BLOCKS
----------
256

SQL> set autotrace traceonly statistics

SQL> select * from hr.t;

119 rows selected.


Statistics
----------------------------------------------------------
1 recursive calls
1 db block gets
140 consistent gets
0 physical reads
120 redo size
7988 bytes sent via SQL*Net to client
580 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
119 rows processed

SQL> select * from hr.t;

119 rows selected.

Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
138 consistent gets
0 physical reads
0 redo size
7988 bytes sent via SQL*Net to client
580 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
119 rows processed

No hay comentarios: