show index 文を実行して、インデックス名、インデックスフィールド、インデックスタイプなど、テーブルのインデックス情報をクエリできます。
説明
show index 文の詳細については、「テーブルのインデックス情報のクエリ」をご参照ください。
前提条件
クライアントが初期化されていること。 詳細については、「Tablestore クライアントの初期化」をご参照ください。
パラメーター
|
パラメーター |
説明 |
|
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 の戻り値のスキーマを取得します。
columns := response.ResultSet.Columns()
fmt.Printf("response table schema:[")
for l := 0; l < len(columns); l++ {
fmt.Printf("%v:%v ", columns[l].Name, columns[l].Type.String())
}
// SQL ResultSet を走査して SQL の戻り値を取得します。
fmt.Println("]\nresponse 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
参考
-
特定の検索インデックスを SQL クエリで使用するには、
CREATE TABLE文を使用して検索インデックスのマッピングを作成します。詳細については、「検索インデックスのマッピングを作成する」をご参照ください。 -
SQL を使用して、特定のフィールドに基づいてデータをクエリします。 詳細については、「データのクエリ」をご参照ください。