You can execute the show index statement to query the index information about tables.

Note For more information about the show index statement, see Query the index information about a table.

Prerequisites

Parameters

Parameter Description
query The SQL statement. Configure the parameter based on the required feature.

Examples

Execute the show index in test_table statement to query index information about the table named test_table.

func showIndex(client *tablestore.TableStoreClient) {
    // Create a SQL request. 
    request := &tablestore.SQLQueryRequest{Query: "show index in test_table"}

    // Obtain the response to the SQL request. 
    response, err := client.SQLQuery(request)
    if err != nil {
        panic(err)
    }

    // Obtain the schema of the returned results of the SQL request. 
    columns := response.ResultSet.Columns()
    fmt.Printf("response table schema: %v\n", columns)

    // Use SQL ResultSet to obtain all returned results of the SQL request. 
    fmt.Println("response resultset:")
    resultSet := response.ResultSet
    for resultSet.HasNext() {
        row := resultSet.Next()
        tableName, _ := row.GetStringByName("Table")
        fmt.Printf("%v, ", tableName)
        nonUnique, _ := row.GetInt64ByName("Non_unique")
        fmt.Printf("%v, ", nonUnique)
        keyName, _ := row.GetStringByName("Key_name")
        fmt.Printf("%v, ", keyName)
        seqInIndex, _ := row.GetInt64ByName("Seq_in_index")
        fmt.Printf("%v, ", seqInIndex)
        columnName, _ := row.GetStringByName("Column_name")
        fmt.Printf("%v, ", columnName)
        indexType, _ := row.GetStringByName("Index_type")
        fmt.Printf("%v\n", indexType)
    }
}

Sample output:

response table schema: [Table:STRING Non_unique:INTEGER Key_name:STRING Seq_in_index:INTEGER Column_name:STRING Is_defined_column:STRING Search_type:STRING Collation:STRING Cardinality:INTEGER Sub_part:INTEGER Packed:STRING Null:STRING Index_type:STRING Comment:STRING Index_comment:STRING Visible:STRING Expression:STRING]
response resultset:
test_table, 0, PRIMARY, 1, pk,
test_table, 1, test_table_index, 1, pk, SearchIndex
test_table, 1, test_table_index, 2, bool_value, SearchIndex
test_table, 1, test_table_index, 3, double_value, SearchIndex
test_table, 1, test_table_index, 4, long_value, SearchIndex
test_table, 1, test_table_index, 5, string_value, SearchIndex