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
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
A mapping table is created. For more information, see Create mapping tables for tables.
Usage notes
Tablestore SDK for Java V5.13.0 and later support the SQL query feature. To use the SQL query feature, make sure that you use a version of Tablestore Java SDK that supports the SQL query feature. For more information about the version history of Tablestore SDK for Java, see Version history of Tablestore SDK for Java.
Parameters
Parameter | Description |
query | The SQL statement. Configure the parameter based on the required feature. |
Examples
The following sample code provides an example on how to run 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 an 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 request.
SQLTableMeta tableMeta = response.getSQLResultSet().getSQLTableMeta();
System.out.println("response table schema: " + tableMeta.getSchema());
// Use SQL ResultSet to obtain all returned results of the SQL request.
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") );
}
}
Sample response:
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
References
If you want to use a specific search index to query data when you use the SQL query feature, you can execute the
CREATE TABLE
statement to create a mapping table for the search index. For more information, see Create mapping tables for search indexes.You can execute SQL statements to query data based on the fields of an index. For more information, see Query data.