Query index information for a mapping table
Use Tablestore SDK for Java to query information about the primary key and associated indexes, including index names, fields, and types.
Prerequisites
-
Install the Tablestore SDK for Java and initialize a client.
-
Use Tablestore SDK for Java 5.13.0 or later.
Description
Call the sqlQuery method to execute a SHOW INDEX statement and query the index information for a mapping table.
SQLQueryResponse sqlQuery(SQLQueryRequest request)
For a data table mapping, the result contains the primary key and the fields of the secondary and search indexes that are created for the data table. For a search index mapping, the result contains only the primary key and the fields of the specified search index.
The following example queries the index information for the example_search_index_mapping search index mapping and reads commonly used fields from the response.
SQLQueryRequest request =
new SQLQueryRequest("SHOW INDEX IN example_search_index_mapping");
SQLQueryResponse response = client.sqlQuery(request);
SQLResultSet resultSet = response.getSQLResultSet();
while (resultSet.hasNext()) {
SQLRow row = resultSet.next();
System.out.println(
row.getString("Table") + ", "
+ row.getString("Key_name") + ", "
+ row.getString("Column_name") + ", "
+ row.getString("Index_type"));
}
Parameters
SQLQueryRequest contains the following parameter.
|
Name |
Type |
Description |
|
query (required) |
String |
The |
Response
SQLQueryResponse contains the following fields related to mapping table indexes.
|
Field |
Type |
Description |
|
|
SQLStatementType |
The SQL statement type, which is obtained by calling |
|
|
ByteString |
The serialized index information. Call |
Result set fields
Each row in the SQLResultSet represents a primary key, secondary index, or search index field and contains the following columns.
|
Field |
Type |
Description |
|
|
String |
The mapping table name. |
|
|
Long |
Whether duplicate values are allowed. |
|
|
String |
The index name. The primary key is returned as |
|
|
Long |
The one-based position of the field in the index. |
|
|
String |
The index field name. |
|
|
String |
Whether the field is a predefined column of the data table. |
|
|
String |
The query type of the search index field. |
|
|
String |
The sort order of the field in the index. |
|
|
Long |
The estimated number of distinct values in the index. |
|
|
Long |
The index prefix length of the field. |
|
|
String |
The index compression method. |
|
|
String |
Whether the field can be null. |
|
|
String |
The index type. A global secondary index is returned as |
|
|
String |
The index remarks. |
|
|
String |
The index comment. |
|
|
String |
Whether the index is visible. |
|
|
String |
The index expression. |