Cassandra复合密钥的误区 [英] Misunderstanding on Composite Key for Cassandra

查看:21
本文介绍了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?

提前致谢

切萨雷

推荐答案

如果您使用 Order Preserving Partitioning (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆