Run the show index statement to retrieve the index name, index fields, and index type for a table.
For more information about the show index statement, see Query the index information about a table.
Prerequisites
Before you begin, ensure that you have:
A Tablestore client initialized. For more information, see Initialize a Tablestore client
Usage notes
The SQL query feature requires Tablestore SDK for .NET V5.0.0 or later.
For more information, see Version history of Tablestore SDK for .NET .
Parameters
|
Parameter |
Description |
|
query |
The SQL statement to execute. Set this to a |
Examples
The following example runs show index in test_table against a table named test_table. The code submits the SQL query, reads the result set schema, then iterates over each row to print the index fields.
/// <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"));
}
}
Response fields
The result set returns the following fields for each index entry.
|
Field |
Type |
Description |
|
Table |
String |
The name of the table. |
|
Non_unique |
Long |
Specifies whether the index allows duplicate values. |
|
Key_name |
String |
The name of the index. |
|
Seq_in_index |
Long |
The position of the column in the index, starting from |
|
Column_name |
String |
The name of the indexed column. |
|
Index_type |
String |
The index type. |
References
To use a specific search index when querying data with the SQL query feature, run the
CREATE TABLEstatement to create a mapping table for the search index. For more information, see Create mapping tables for search indexes.To query data based on index fields using SQL statements, see Query data.