OBKV-Tableはグローバルインデックスをサポートしており、SQLの動作と同じです。
適用範囲
グローバルインデックスをパーティション化する場合、クライアントの対応範囲により、使用できるパーティショニング方式は次のとおりです。
パーティショニング方式 |
Javaクライアント |
|---|---|
| key | サポート |
| hash | サポート |
| range | サポート |
クライアントは複雑な式を解析・計算できないため、パーティションキーには1つ以上の列を直接指定する必要があります。列を使った式は指定できません。例を以下に示します。
サポート |
サポートなし |
|---|---|
CREATE INDEX idx ON tb(C2) GLOBAL PARTITION BY HASH(C2); CREATE INDEX idx ON tb(C2) GLOBAL PARTITION BY RANGE(C2, C3); |
CREATE INDEX idx ON tb(C2) GLOBAL PARTITION BY HASH(C2+C3); |
Javaクライアントの使用例
例:
public void test_update() throws Exception {
test_update("test_global_hash_hash", 20);
test_update("test_global_key_key", 20);
test_update("test_global_range_range", 20);
}
public void test_update(String tableName, int recordCount) throws Exception {
try {
client.addRowKeyElement(tableName, new String[] { "C1" });
String[] properties_name = { "C2", "C3" };
// prepare data
for (int i = 0; i < recordCount; i++) {
int key = gen_key(i);
long affectRows = client.insert(tableName, new Object[] { key }, properties_name,
new Object[] { key + 1, ("hello " + key).getBytes() });
Assert.assertEquals(1, affectRows);
}
// update global index key
for (int i = 0; i < recordCount; i++) {
int key = gen_key(i);
long affectRows = client.update(tableName, new Object[] { key },
new String[] { "C2" }, new Object[] { key + 2 });
Assert.assertEquals(1, affectRows);
Map<String, Object> result = client.get(tableName, new Object[] { key },
properties_name);
Assert.assertEquals(key + 2, result.get("C2"));
Assert.assertEquals("hello " + key, result.get("C3"));
}
// update other key
for (int i = 0; i < recordCount; i++) {
int key = gen_key(i);
long affectRows = client.update(tableName, new Object[] { key },
new String[] { "C3" }, new Object[] { "hi " + key });
Assert.assertEquals(1, affectRows);
Map<String, Object> result = client.get(tableName, new Object[] { key },
properties_name);
Assert.assertEquals(key + 2, result.get("C2"));
Assert.assertEquals("hi " + key, result.get("C3"));
}
checkIndexTableRow(tableName, recordCount);
} finally {
// delete data
for (int i = 0; i < recordCount; i++) {
int key = gen_key(i);
long affectRows = client.delete(tableName, new Object[] { key });
Assert.assertEquals(1, affectRows);
}
checkIndexTableRow(tableName, 0);
}
}
Javaクライアントでグローバルインデックスを使用するその他の例については、GitHub Javaクライアント グローバルインデックスを参照してください。