IBM DB2 Query Toolbox - List all indexes in the Db2 database



Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

IBM Db2 Query Toolbox - List all indexes in the Db2 database

A consulta abaixo lista todos os índices no banco de dados Db2.
The query below lists all indexes in the Db2 database.

Consulta - Query

SELECT IND.INDSCHEMA AS SCHEMA_NAME
,      IND.INDNAME AS INDEX_NAME
,      IND.IID AS INDEX_ID
,       CASE IND.INDEXTYPE
           when 'BLOK' then 'Block index'
           when 'REG'  then 'Regular index'
           when 'CPMA' then 'Page map index for a column-organized table'
           when 'RCT ' then 'Key sequence index for a range-clustered table'
           when 'CLUS' then 'Clustering index'
           when 'TEXT' then 'Text index'
           when 'DIM'  then 'Dimension block index'
           when 'XPTH' then 'XML path index'
           when 'XRGN' then 'XML region index'
           when 'XVIL' then 'Index over XML column (logical)'
           when 'XVIP' then 'Index over XML column (physical)'
           end as index_type,
       CASE IND.UNIQUERULE 
           when 'P' then 'Primary key'
           when 'U' then 'Unique'
           when 'D' then 'Permits Duplicate'
       END AS TYPE
,      IND.TABNAME AS TABLE_NAME
,      LISTAGG(COLS.COLNAME, ', ')
           WITHIN GROUP (ORDER BY COLS.COLNAME) AS COLUMNS
  FROM SYSCAT.INDEXES IND
       JOIN SYSCAT.INDEXCOLUSE COLS
         ON IND.INDNAME = COLS.INDNAME
        AND IND.INDSCHEMA = COLS.INDSCHEMA
  WHERE IND.TABSCHEMA NOT LIKE 'SYS%'
  GROUP BY IND.INDNAME
  ,        IND.INDSCHEMA
  ,        IND.IID
  ,        IND.UNIQUERULE
  ,        IND.INDEXTYPE
  ,        IND.TABNAME
  ORDER BY SCHEMA_NAME
  ,        INDEX_NAME
  ,        INDEX_ID;

Colunas

  • schema_name - nome do esquema
  • index_name - nome do índice
  • index_id - id do índice (único na tabela)
  • index_type:
    • Índice de bloco
    • Índice regular
    • Índice do mapa de página para uma tabela organizada por colunas
    • Índice de sequência de chaves para uma tabela agrupada por intervalo
    • Índice de agrupamento
    • Índice de texto
    • Índice de bloco de dimensão
    • Índice de caminho XML
    • Índice de região XML
    • Índice sobre coluna XML (lógico)
    • Índice sobre coluna XML (físico)
  • modelo
    • CHAVE PRIMÁRIA
    • EXCLUSIVO
  • table_name - esquema e nome da tabela
  • colunas - lista de colunas de índice separadas por ","

Linhas

  • Uma linha representa um índice
  • Escopo das linhas: todos os índices do banco de dados (esquema)
  • Ordenado por nome de esquema, nome de índice

Columns

  • schema_name - name of schema
  • index_name - index name
  • index_id - id of index (unique in table)
  • index_type:
    • Block index
    • Regular index
    • Page map index for a column-organized table
    • Key sequence index for a range-clustered table
    • Clustering index
    • Text index
    • Dimension block index
    • XML path index
    • XML region index
    • Index over XML column (logical)
    • Index over XML column (physical)
  • type
    • PRIMARY KEY
    • UNIQUE
  • table_name - table schema and name
  • columns - list of index columns separated with ","

Rows

  • One row represents one index
  • Scope of rows: all indexes in the database (schema)
  • Ordered by schema name, index name

Resultado - Sample results


Copyright © Dataedo.