在Cassandra中集群键 [英] Clustering Keys in Cassandra

查看:700
本文介绍了在Cassandra中集群键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定的物理节点上,给定分区键的行按照聚簇键引起的顺序存储,使得以该聚簇顺序检索行特别有效。 http://cassandra.apache.org/doc/cql3/CQL.html#createTableStmt 什么

On a given physical node, rows for a given partition key are stored in the order induced by the clustering keys, making the retrieval of rows in that clustering order particularly efficient. http://cassandra.apache.org/doc/cql3/CQL.html#createTableStmt What kind of ordering is induced by clustering keys?

推荐答案

假设你的聚类键是

k1 t1, k2 t2, ..., kn tn


$ b b

其中ki是第i个密钥名称,ti是第i个密钥类型。然后,订单数据以词典顺序存储,其中使用该类型的比较器来比较每个维度。

where ki is the ith key name and ti is the ith key type. Then the order data is stored in is lexicographic ordering where each dimension is compared using the comparator for that type.

So(a1,a2,...,an) ; (b1,b2,...,bn),如果a1 < b1使用t1比较器,或者a1 = b1和a2 < b2,或者(a1 = b1和a2 = b2)和a3 < b3使用t3比较器等。

So (a1, a2, ..., an) < (b1, b2, ..., bn) if a1 < b1 using t1 comparator, or a1=b1 and a2 < b2 using t2 comparator, or (a1=b1 and a2=b2) and a3 < b3 using t3 comparator, etc..

这意味着找到具有特定k1 = a的所有行是有效的,因为数据被存储在一起。但是对于i> 1,找到所有具有ki = x的行是无效的。实际上,不允许这样的查询 - 允许的唯一聚类键约束指定零个或多个聚类键,从第一个开始, 。

This means that it is efficient to find all rows with a certain k1=a, since the data is stored together. But it is inefficient to find all rows with ki=x for i > 1. In fact, such a query isn't allowed - the only clustering key constraints that are allowed specify zero or more clustering keys, starting from the first with none missing.

例如,考虑架构

create table clustering (
    x text,
    k1 text,
    k2 int,
    k3 timestamp,
    y text,
    primary key (x, k1, k2, k3)
);

如果您进行了以下插入:

If you did the following inserts:

insert into clustering (x, k1, k2, k3, y) values ('x', 'a', 1, '2013-09-10 14:00+0000', '1');
insert into clustering (x, k1, k2, k3, y) values ('x', 'b', 1, '2013-09-10 13:00+0000', '1');
insert into clustering (x, k1, k2, k3, y) values ('x', 'a', 2, '2013-09-10 13:00+0000', '1');
insert into clustering (x, k1, k2, k3, y) values ('x', 'b', 1, '2013-09-10 14:00+0000', '1');

然后它们按此顺序存储在磁盘上(顺序 select * from聚集其中x ='x'返回):

then they are stored in this order on disk (the order select * from clustering where x = 'x' returns):

 x | k1 | k2 | k3                       | y
---+----+----+--------------------------+---
 x |  a |  1 | 2013-09-10 14:00:00+0000 | 1
 x |  a |  2 | 2013-09-10 13:00:00+0000 | 1
 x |  b |  1 | 2013-09-10 13:00:00+0000 | 1
 x |  b |  1 | 2013-09-10 14:00:00+0000 | 1

k1 排序占主导地位, c $ c> k2 ,然后 k3

k1 ordering dominates, then k2, then k3.

这篇关于在Cassandra中集群键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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