对Cassandra复合键的误解 [英] Misunderstanding on Composite Key for Cassandra
问题描述
我必须测试Cassandra的不同数据模型。我正在考虑使用由key1:key2作为行键的复合键。
例如,对于Cassandra上的这个配置,我可以查询以使所有行具有特定key1值和任何key2值,但除此之外是不可能的(获取具有特定key2的值和任何key1的所有行)。
是不是
I've to test different datamodels for Cassandra. I'm thinking about to use a composite key made by key1:key2 for the row key. With this configuration on Cassandra, for example, I can query to have all the rows having a specific key1 value and any key2 value but It's impossible otherwise (obtain all the rows having a specific key2's value and any key1). Is it right?
提前感谢
Cesare
推荐答案
如果你使用订单保留分区(OPP),那么是的,密钥将被存储排序,然后你可以获得一系列键A:A到A:Z - 但不一定是任何:A到任何:Z。
If you use Order Preserving Partitioning (OPP), then yes, the keys will be stored sorted, and then you can get slices over a range of keys e.g. A:A to A:Z -- but not necessarily any:A to any:Z.
但是,OPP不能保证在节点之间均匀分布密钥,你可能会得到太多或太少的键的热点。您可能想要使用随机分区(RP),通过在所有节点之间存储散列来分配密钥。
But, OPP is not guaranteed to evenly distribute the keys across the nodes and you could end up with "hot spots" of too many or too few keys. You probably want to use Random Partitioning (RP) which distributes the keys by storing by hash across all nodes.
但是,由于列是存储排序的,使用复合值相当强大的访问数据范围。
However, since Columns are stored sorted, using Composite values can be pretty powerful for accessing ranges of data.
有关使用Hector查询复合列的详细信息,请参见此问题 。
See this question for details on querying Composite columns using Hector .
如有必要,列名称可用作进行其他查找的Multiget查询的键。
If necessary, the column names could then be used as keys to do Multiget queries for additional lookups.
这篇关于对Cassandra复合键的误解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!