通过show index语句查询表的索引描述信息。
说明 关于show index语句的更多信息,请参见查询索引描述信息。
前提条件
参数
参数 | 说明 |
---|---|
query | SQL语句,请根据所需功能进行设置。 |
示例
使用show index in test_table
语句查询test_table表的索引描述信息。
func showIndex(client *tablestore.TableStoreClient) {
// 创建SQL请求。
request := &tablestore.SQLQueryRequest{Query: "show index in test_table"}
// 获取SQL的响应结果。
response, err := client.SQLQuery(request)
if err != nil {
panic(err)
}
// 获取SQL返回值的Schema。
columns := response.ResultSet.Columns()
fmt.Printf("response table schema: %v\n", columns)
// 通过SQL ResultSet遍历获取SQL的返回结果。
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)
}
}
返回结果示例如下:
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