You can execute the show index statement to query the index information about tables.
Note For more information about the show index statement, see Query the index information about a table.
Prerequisites
- A Tablestore client is initialized. For more information, see Initialization.
- A mapping table is created. For more information, see Create tables and mapping tables.
Usage notes
Tablestore SDK for Java V5.13.0 or later supports the SQL query feature. Before you use the SQL query feature, make sure that Tablestore SDK for Java V5.13.0 or later is obtained. For more information about the version history of Tablestore SDK for Java, see Tablestore SDK for Java.
Parameters
Parameter | Description |
---|---|
query | The SQL statement. Configure the parameter based on the required feature. |
Examples
Execute the
show index in test_table
statement to query the index information about the table named test_table. private static void showIndexDemo(SyncClient client) {
// Create a SQL request.
SQLQueryRequest request = new SQLQueryRequest("show index in test_table");
// Obtain the response to the SQL request.
SQLQueryResponse response = client.sqlQuery(request);
// Obtain the schema of the returned results of the SQL query statement.
SQLTableMeta tableMeta = response.getSQLResultSet().getSQLTableMeta();
System.out.println("response table schema: " + tableMeta.getSchema());
// Use SQL ResultSet to obtain all returned results of the SQL query statement.
System.out.println("response resultset:");
SQLResultSet resultSet = response.getSQLResultSet();
while (resultSet.hasNext()) {
SQLRow row = showIndexResultSet.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") );
}
}
Sample output:
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