Query index information for a mapping table

Updated at:

Use Tablestore SDK for Java to query information about the primary key and associated indexes, including index names, fields, and types.

Prerequisites

Description

Call the sqlQuery method to execute a SHOW INDEX statement and query the index information for a mapping table.

SQLQueryResponse sqlQuery(SQLQueryRequest request)
Note

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

The following example queries the index information for the example_search_index_mapping search index mapping and reads commonly used fields from the response.

SQLQueryRequest request =
        new SQLQueryRequest("SHOW INDEX IN example_search_index_mapping");
SQLQueryResponse response = client.sqlQuery(request);

SQLResultSet resultSet = response.getSQLResultSet();
while (resultSet.hasNext()) {
    SQLRow row = resultSet.next();
    System.out.println(
            row.getString("Table") + ", "
                    + row.getString("Key_name") + ", "
                    + row.getString("Column_name") + ", "
                    + row.getString("Index_type"));
}

Parameters

SQLQueryRequest contains the following parameter.

Name

Type

Description

query (required)

String

The SHOW INDEX IN <mapping_table_name> statement to execute. mapping_table_name specifies the mapping table name.

Response

SQLQueryResponse contains the following fields related to mapping table indexes.

Field

Type

Description

type

SQLStatementType

The SQL statement type, which is obtained by calling getSQLStatementType(). For a SHOW INDEX statement, the value is SQL_SELECT.

rows

ByteString

The serialized index information. Call getSQLResultSet() to obtain the parsed SQLResultSet.

Result set fields

Each row in the SQLResultSet represents a primary key, secondary index, or search index field and contains the following columns.

Field

Type

Description

Table

String

The mapping table name.

Non_unique

Long

Whether duplicate values are allowed. 0 indicates no and 1 indicates yes.

Key_name

String

The index name. The primary key is returned as PRIMARY.

Seq_in_index

Long

The one-based position of the field in the index.

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 the search index field.

Collation

String

The sort order of the field in the index.

Cardinality

Long

The estimated number of distinct values in the index.

Sub_part

Long

The index prefix length of the field.

Packed

String

The index compression method.

Null

String

Whether the field can be null.

Index_type

String

The index type. A global secondary index is returned as GlobalIndex, a local secondary index is returned as LocalIndex, and a search index is returned as SearchIndex.

Comment

String

The index remarks.

Index_comment

String

The index comment.

Visible

String

Whether the index is visible.

Expression

String

The index expression.