All Products
Search
Document Center

Tablestore:Query index information about a table

Last Updated:Aug 28, 2024

You can execute the show index statement to query the index information about a table, such the index name, index fields, and index type.

Note

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

Prerequisites

Usage notes

Tablestore SDK for .NET V5.0.0 or later supports SQL queries. To perform SQL queries by using Tablestore SDK for .NET, make sure that your SDK version is 5.0.0 or later. We recommend that you use the latest SDK. For more information, see Version history of Tablestore SDK for .NET.

Parameters

Parameter

Description

query

The SQL statement. Configure the parameter based on the required feature.

Examples

The following sample code provides an example on how to run the show index in test_table statement to query the index information about the table named test_table:

/// <summary>
/// Query index information about a table. 
/// </summary>
/// <param name="otsClient"></param>
public static void DescribeIndex(OTSClient otsClient)
{
    SQLQueryRequest sqlQueryRequest = new SQLQueryRequest("show index in test_table");

    SQLQueryResponse sqlQueryResponse = otsClient.SQLQuery(sqlQueryRequest);

    SQLTableMeta sqlTableMeta = sqlQueryResponse.GetSQLResultSet().GetSQLTableMeta();
    Console.WriteLine(JsonConvert.SerializeObject(sqlTableMeta.GetSchema()));

    ISQLResultSet resultSet = sqlQueryResponse.GetSQLResultSet();
    while (resultSet.HasNext())
    {
        ISQLRow row = resultSet.Next();
        Console.WriteLine(row.GetString("Table") + " " + row.GetLong("Non_unique") + " " + row.GetString("Key_name") + " " +
                          row.GetLong("Seq_in_index") + " " + row.GetString("Column_name") + " " + row.GetString("Index_type"));
    }
}

References

  • If you want to use a specific search index to query data when you use the SQL query feature, you can execute the CREATE TABLE statement to create a mapping table for the search index. For more information, see Create mapping tables for search indexes.

  • You can execute SQL statements to query data based on the fields of an index. For more information, see Query data.