文档

查询索引描述信息

更新时间:

通过show index语句查询表的索引描述信息,例如索引名称、索引字段、索引类型等。

说明

关于show index语句的更多信息,请参见查询索引描述信息

前提条件

注意事项

表格存储Java SDK从5.13.0版本开始支持SQL查询功能。使用SQL查询功能时,请确保获取了正确的表格存储Java SDK版本。关于Java SDK历史迭代版本的更多信息,请参见Java SDK历史迭代版本

参数

参数

说明

query

SQL语句,请根据所需功能进行设置。

示例

以下示例用于使用show index in test_table语句查询test_table表的索引描述信息。

private static void showIndexDemo(SyncClient client) {
    // 创建SQL请求。
    SQLQueryRequest request = new SQLQueryRequest("show index in test_table");

    // 获取SQL的响应结果。
    SQLQueryResponse response = client.sqlQuery(request);

    // 获取SQL返回值的Schema。
    SQLTableMeta tableMeta = response.getSQLResultSet().getSQLTableMeta();
    System.out.println("response table schema: " + tableMeta.getSchema());

    // 通过SQL ResultSet遍历获取SQL的返回结果。
    System.out.println("response resultset:");
    SQLResultSet resultSet = response.getSQLResultSet();
    while (resultSet.hasNext()) {
        SQLRow row = resultSet.next();
        System.out.println(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 table schema: [Table:STRING, Non_unique:INTEGER, Key_name:STRING, Seq_in_index:INTEGER, Column_name:STRING, Is_defined_column: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

相关文档

  • 如果在通过SQL查询数据时要使用指定的多元索引进行查询,您可以通过CREATE TABLE语句创建多元索引的映射关系实现。更多信息,请参见创建多元索引的映射关系

  • 您可以使用SQL根据查询到的字段进行数据查询。更多信息,请参见查询数据

  • 本页导读 (1)