【发布时间】:2014-01-30 08:40:49
【问题描述】:
我有一个关于宽行、集群、手动索引等的问题......我希望有人可以在这里提供帮助。 CQL版本是3,Cassandra是2.0.1;
假设我有 CF '产品'
id timeuuid
location varchar
shopname varchar
expiry timestamp
count int
PRIMARY KEY (id)
我希望能够选择到期时订购的特定位置的产品。因此创建寄存器,如:
CF 'id_register_by_loc_expy'
location varchar
expiry timestamp
id timeuuid
PRIMARY KEY (location,expiry,id)
并希望选择到期时订购的特定店铺名称的产品。然后创建:
CF 'id_register_by_shopname_expy'
shopname vachar
expiry timestamp
id timeuuid
PRIMARY KEY (shopname,expiry,id)
这样我就可以进行高效的查询/切片,如下所示:
1.select id from id_reg_by_loc_expy where location = 'x'; // [按到期自然排序]
2.select id from id_reg_by_loc_expy where location = 'x' and expiry > 't1' and expiry
3.select * from products where id = 'id';
和;
4.select id from id_reg_by_shop_exp where shopname = 'y'; // [按到期自然排序]
和;
5.select id from id_reg_by_shop_count where shopname = 'y'; // [按数量自然排序]
等等。
如果集群键需要更改并且我需要对寄存器中这些特定行上的条目重新排序怎么办。
我遇到的问题是:
使用新的到期(或计数)重新插入会产生新的主键,因此不会更新我的旧条目。
我不能“更新 .. set expiry = 'x2' where ...”,因为到期是主键的一部分。
由于墓碑限制,使用新主键插入然后删除旧主键是一个不好的选择。
我尝试过的事情是:
-
CF 'id_reg_by_loc_expy'
location varchar expiry timestamp id timeuuid otherSecondaryIndex varchar PRIMARY KEY (location,id)
但是;
一个。这没有利用 Cassandra 的存储排序功能。我希望每行有很多产品,并且希望避免需要搜索整行;和
b.事实证明,我实际上无法进行如下查询:
(i)select id from id_reg_... where location='x' order by dtg asc;
错误请求:不支持带有二级索引的 ORDER BY。
Or
(ii)select id from id_reg_... where location='x' and expiry > 't1' and expiry
错误请求:使用 Equal 运算符的 by-columns 子句中不存在索引列
虽然我“可以”这样做:
(iii)select id from id_reg_... where location='x' and otherSecIndex='y' and expiry > 't1' and expiry
** 请注意,这需要我强制“允许过滤”并且似乎糟糕的设计包含另一个二级索引只是为了允许此查询..即我对“排序依据”查询不感兴趣的查询无论如何。
2. 使用 timeuuid 代替时间戳来表示过期。即使这在我找不到方法的情况下起作用,也无助于我的“按数量排序”意图。
我在这里遗漏了一些基本的东西吗?我需要继续使用所有墓碑缓解技术的答案吗?或者在我的应用程序中进行一些排序?
干杯, 蒂姆
【问题讨论】:
标签: cassandra timestamp cluster-analysis cql3