Query index information for a mapping table

Updated at:

Tablestore SDK for Python queries the names, fields, and types of the primary key and associated indexes of a mapping table.

Prerequisites

  • Install Tablestore SDK for Python and initialize a client.

  • SQL query requires version 5.4.2 or later. We recommend that you use the latest version.

Description

Call the exe_sql_query method to execute a SHOW INDEX statement and query the primary key and associated indexes of a mapping table.

def exe_sql_query(self, query)
Note

For a data table mapping, the result contains the primary key and fields of secondary indexes and search indexes on the data table. For a search index mapping, the result contains only the primary key and fields of the specified search index.

The following example queries index information for example_search_table.

query = "SHOW INDEX IN example_search_table"
row_list, _, _ = client.exe_sql_query(query)

for row in row_list:
    values = dict(row.attribute_columns)
    print(values["Key_name"], values["Column_name"], values["Index_type"])

Parameters

The exe_sql_query method contains the following parameter.

Name

Type

Description

query (required)

String

The SHOW INDEX IN <mapping_table_name> statement to execute, where <mapping_table_name> is the mapping table name.

Response

The exe_sql_query method returns a tuple that contains the following elements.

Element

Type

Description

row_list

List[Row]

A list of index fields. Each row corresponds to a primary key, secondary index, or search index field.

table_capacity_units

List[Tuple]

Read and write CUs consumed by data tables. Each tuple contains a table name and a CapacityUnit object.

search_capacity_units

List[Tuple]

Read and write CUs consumed by search indexes. Each tuple contains a search index name and a CapacityUnit object.

Result-set fields

Field

Type

Description

Table

String

The mapping table name.

Non_unique

Integer

Whether duplicate index values are allowed. 0 means no and 1 means yes.

Key_name

String

The index name. A primary key returns PRIMARY.

Seq_in_index

Integer

The field position in the index, starting from 1.

Column_name

String

The index field name.

Is_defined_column

String

Whether the field is a predefined column of the data table.

Search_type

String

The query type of a search index field.

Collation

String

The field sort order in the index.

Cardinality

Integer

The estimated number of distinct values in the index.

Sub_part

Integer

The index-field prefix length.

Packed

String

The index compression method.

Null

String

Whether the field can be null.

Index_type

String

The index type. A global secondary index returns GlobalIndex, a local secondary index returns LocalIndex, and a search index returns SearchIndex.

Comment

String

The index remarks.

Index_comment

String

The index comment.

Visible

String

Whether the index is visible.

Expression

String

The index expression.