Cassandra和查询层次结构 [英] Cassandra and querying hierarchies
问题描述
我正在调查Cassandra,但在下列任何文件中找不到答案。
我需要在深层次结构中查询范围。我已经确定表示层次结构的最简单的方法是将每个级别作为列。例如:
原产地价格ID
Europe.Germany VW Group.Audi 20000 1
欧洲。德国VW集团.Porshe 21000 2
欧洲。德国宝马19000 3
SQL示例:
SELECT ID FROM CompositeTable WHERE(原点STARTS WITH'Europe')
AND(制造商STARTS WITH' VW集团,而不是'VW集团.Porshe'或是'宝马')
和(价格BETWEEN 18000和22000)
结果:
ID = [1,3]
Cassandra可以在复合索引中执行此类搜索吗?
解决方案Cassandra中的复合键是DBMS中的一种
多列索引
,如果您在表中有c1,c2和c3索引列从c1到c6。 DB将总是尝试使用您的索引,如果查询是=,> (c1),(c1,c2)或(c1,c2,c3)而不是(c2),(c2,c3),...的操作, (c3)或(c1,c3)。 case在cassandra是一样的,但在这里你有多列索引在c1到c6 [因为列首先排序基于c1和冲突转移到c2和后续]
I am investigating Cassandra, but cannot find an answer in any documentation to the following.
I need to query ranges across a deep hierarchy. I have determined that the easiest way to represent the hierarchy is to have each level as a column. For example:
Origin Manufacturer Price ID Europe.Germany VW Group.Audi 20000 1 Europe.Germany VW Group.Porshe 21000 2 Europe.Germany BMW 19000 3
Here is a pseudo SQL example:
SELECT ID FROM CompositeTable WHERE (Origin STARTS WITH 'Europe') AND (Manufacturer STARTS WITH 'VW Group' AND IS NOT 'VW Group.Porshe' OR IS 'BMW') AND (Price BETWEEN 18000 AND 22000)
Result:
ID = [1, 3]
Can Cassandra perform this type of search across a composite index?
解决方案Composite Keys in Cassandra is a kind of
multiple-column index
in DBMS, where if you have index on c1, c2 and c3 in a table with columns from c1 to c6. DB will always try to use you index if the query is for=, > , <, >=, <=
operation on (c1), (c1,c2) or (c1, c2, c3) but not for (c2), (c2, c3), (c3) or (c1, c3). The case is the same in cassandra but here you have multiple-column index on c1 to c6 [since the columns are sorted first based on c1 and the collision carries over to c2 and follows on]这篇关于Cassandra和查询层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!