You can execute the show index statement to query the index information about a table, such the index name, index fields, and index type.
For more information about the show index statement, see Query the index information about a table.
Prerequisites
A client is initialized. For more information, see Initialize a Tablestore client.
Parameters
|
Parameter |
Description |
|
query |
The SQL statement. Configure this parameter based on the required feature. |
Example
The following example shows how to use the show index in test_table statement to query index information for the test_table table.
func showIndex(client *tablestore.TableStoreClient) {
// Create an SQL request.
request := &tablestore.SQLQueryRequest{Query: "show index in test_table"}
// Obtain the SQL response.
response, err := client.SQLQuery(request)
if err != nil {
panic(err)
}
// Obtain the schema of the SQL return value.
columns := response.ResultSet.Columns()
fmt.Printf("response table schema:[")
for l := 0; l < len(columns); l++ {
fmt.Printf("%v:%v ", columns[l].Name, columns[l].Type.String())
}
// Traverse the SQL ResultSet to obtain the SQL return value.
fmt.Println("]\nresponse 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)
}
}
The following is a sample response:
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
References
-
To use a specific search index for an SQL query, create a mapping for the search index using the
CREATE TABLEstatement. For more information, see Create a mapping for a search index. -
Use SQL to query data based on specific fields. For more information, see Query data.