Anterior  Próximo

Navegação:  e-Forms NFC-e 4.8.2.0 > Manual de Manutenção de Banco de Dados e-Forms > Manual de Manutenção de Banco de Dados e-Forms - Oracle > Guia de Configurações da Rotina de Manutenção de Banco de Dados > Índices > Fragmentação dos índices

Script Fragmentação de Índices

/*

TABELAS CRÍTICAS DO CONNECTOR, COM GRANDE VOLUME DE DADOS E QUE SÃO UTILIZADAS DURANTE O PROCESSAMENTO

- TBLOGDOCUMENT

- TBPROCESS

- TBPROCESSDATA

- TBLOGODCUMENTSTATUS

- TBLOGDOCMESSAGE

- TBSTATISTICS

- TBLOT

- TBLOTS

- TBDATABASEINPUT

 

Para verificar quais índices precisam ser reconstruidos rodar o script abaixo, antes de executar deve-se alterar o nome do owner dos objetos,

para isso substitua no script o valor <OWNER_NAME> pelo nome do usuário do connector.

Esse script se baseia em três indicadores para definir se um índice precisa ou não ser reconstruido "Deleted Entries", "Blevel", "Distinctiveness",

os valores desses indicadores vão sugerir a necessidade da reindexação.

Após a execução os índices fragmentados serão listados.

*/

------- RODAR PREFERENCIALMENTE DENTRO DE UMA JANELA DE MANUTENÇÃO ---------------

set serveroutput on

set verify off

declare

 c_name        INTEGER;

 ignore        INTEGER;

 height        index_stats.height%TYPE := 0;

 lf_rows       index_stats.lf_rows%TYPE := 0;

 del_lf_rows   index_stats.del_lf_rows%TYPE := 0;

 distinct_keys index_stats.distinct_keys%TYPE := 0;

 cursor c_indx is select owner, table_name, index_name from dba_indexes

   where owner like upper('<OWNER_NAME>');

 

begin

 dbms_output.enable (1000000);

 dbms_output.put_line ('Owner           Index Name                              % Deleted Entries Blevel Distinctiveness');

 dbms_output.put_line ('————— ————————————— —————– —— —————');

 c_name := DBMS_SQL.OPEN_CURSOR;

 

 for r_indx in c_indx loop

   DBMS_SQL.PARSE(c_name,'analyze index ' || r_indx.owner || '.' ||

   r_indx.index_name || ' validate structure',DBMS_SQL.NATIVE);

   ignore := DBMS_SQL.EXECUTE(c_name);

 

   select HEIGHT, decode (LF_ROWS,0,1,LF_ROWS), DEL_LF_ROWS, decode (DISTINCT_KEYS,0,1,DISTINCT_KEYS)

   into height, lf_rows, del_lf_rows, distinct_keys from index_stats;

 

   if ( height > 2 ) OR ( (del_lf_rows/lf_rows) > 0.2 and (del_lf_rows/lf_rows) <> 1)

     then dbms_output.put_line (rpad(r_indx.owner,16,' ') || rpad(r_indx.index_name,40,' ') ||

     lpad(round((del_lf_rows/lf_rows)*100,3),17,' ') ||

     lpad(height-1,7,' ') || lpad(round((lf_rows-distinct_keys)*100/lf_rows,3),16,' '));

   end if;

 end loop;

 

 DBMS_SQL.CLOSE_CURSOR(c_name);

end;