Dba index fragmentation
Aller à la navigation
Aller à la recherche
| Fiche express | |
|---|---|
| Type | Script SQL*Plus de diagnostic |
| Domaine | Administration (index) |
| Voir aussi | Dba index stats · Dba index schema fragmentation report |
Dba index fragmentation calcule le taux de fragmentation d'un index précis, pour décider s'il vaut la peine d'être reconstruit (ALTER INDEX ... REBUILD).
Le script demande le nom d'un index (au format SCHEMA.INDEX_NAME), l'analyse via ANALYZE INDEX VALIDATE STRUCTURE, puis lit le résultat dans la vue INDEX_STATS.
Script
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING ON
SET LINESIZE 180
SET PAGESIZE 50000
SET VERIFY OFF
ACCEPT index_name CHAR PROMPT 'Enter index name [SCHEMA].index_name : '
ANALYZE INDEX &&index_name VALIDATE STRUCTURE;
COLUMN name HEADING 'Index Name' FORMAT a30
COLUMN del_lf_rows HEADING 'Deleted|Leaf Rows' FORMAT 999,999,999,999,999
COLUMN lf_rows_used HEADING 'Used|Leaf Rows' FORMAT 999,999,999,999,999
COLUMN ibadness HEADING '% Deleted|Leaf Rows' FORMAT 999.99999
SELECT
name
, del_lf_rows
, lf_rows - del_lf_rows lf_rows_used
, TO_CHAR(del_lf_rows / DECODE(lf_rows, 0, 0.01, lf_rows) * 100, '999.99999') ibadness
FROM index_stats
/
PROMPT Consider rebuilding any index if % of Deleted Leaf Rows is > 20%
UNDEFINE index_name
SET FEEDBACK 6
Colonnes / sortie
- Deleted Leaf Rows — entrées d'index marquées supprimées mais pas encore physiquement compactées.
- Used Leaf Rows — entrées réellement actives.
- % Deleted Leaf Rows — ratio des deux ; la règle de pouce classique est d'envisager un rebuild au-delà de 20%.
INDEX_STATS est une vue "scratchpad" : elle ne contient jamais qu'une seule ligne, celle du dernier ANALYZE INDEX ... VALIDATE STRUCTURE exécuté dans la session. Elle ne permet donc de traiter qu'un index à la fois — pour un balayage de tout un schéma, voir Dba index schema fragmentation report, qui boucle sur tous les index et automatise ce même calcul.
Voir aussi
- Dba index stats — détail complet des statistiques d'un index (au-delà du seul taux de fragmentation)
- Dba index schema fragmentation report — version batch, sur tous les index d'un schéma