SHOW INDEX

Function

Displays the index information of a table.

Precautions

  • If schema_name is not specified, tables in the current schema are queried.
  • If the specified table is in schema_name.table_name format and schema_name is specified, the schema of schema_name is used.

Syntax

SHOW { INDEX | INDEXES | KEYS }
   { FROM | IN } table_name
   [{FROM | IN} schema_name ]
   [ WHERE expr ]

Parameter Description

  • table_name

     Table name. You can specify a table name or **schema\_name.table\_name**.
    
  • schema_name

     Schema name. This parameter is optional. If this parameter is not specified, the current schema is queried.
    

Output Column Description

ColumnDescription
TableName of the table to which the index belongs
Non_uniqueWhether the index is a non-unique index
Key_nameIndex name
Seq_in_indexSequence number of the index column in the index
Column_nameColumn name of the index column
CollationThe value can be A (ascending order by default), D (descending order), or NULL (indexes cannot be sorted).
CardinalityCalculated based on pg_statistic.stadistinct and pg_class.reltuples:
stadistinct > 0: stadistinct
stadistinct = 0: NULL
stadistinct < 0: reltuples * stadistinct * -1
Sub_partIndex prefix If the column is only partially indexed, the value is the number of index characters. If the entire column is indexed, the value is NULL. Currently, the prefix index is not supported. The value is NULL.
PackedHow to pack the key value. Specify pack_keys when creating a table. Otherwise, NULL is returned. Not supported currently. The value is NULL.
NullIf the value may contain NULL, the value is YES. Otherwise, the value is ''.
Index_typeIndex method, such as Btree and HASH.
CommentIf the value of indisusable in the pg_index table is true, disabled is displayed. If the value of indisusable in the pg_index table is false, '' is displayed.
Index_commentComment specified by COMMENT when an index is created

Examples

--Create an index and a table.
openGauss=# CREATE SCHEMA tst_schema;
openGauss=# SET SEARCH_PATH TO tst_schema;

openGauss=# CREATE TABLE tst_t1
openGauss-# (
openGauss(# id int primary key,
openGauss(# name varchar(20) NOT NULL
openGauss(# );
openGauss=# CREATE INDEX tst_t1_name_ind on tst_t1(name);

--View the index of a table.
openGauss=# show index from tst_t1 ;
 table  | non_unique |    key_name     | seq_in_index | column_name | collation | cardinality | sub_part | packed | null | index_type | comment | index_comment 
--------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------
 tst_t1 | t          | tst_t1_name_ind |            1 | name        | A         |             |          |        |      | btree      |         | 
 tst_t1 | f          | tst_t1_pkey     |            1 | id          | A         |             |          |        |      | btree      |         | 
(2 rows)

Helpful Links

N/A

Feedback
编组 3备份
    openGauss 2024-10-13 00:54:14
    cancel