为什么cassandra“选择”在二级密钥,但不是使用二级密钥更新? (1.2.8+) [英] Why can cassandra "select" on secondary key, but not update using secondary key? (1.2.8+)

查看:124
本文介绍了为什么cassandra“选择”在二级密钥,但不是使用二级密钥更新? (1.2.8+)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设这个表:

create table s4 (a timeuuid primary key, b timeuuid, stuff text);
create index s4_index1 on s4 (b);

这样工作:

select * from s4 where b = 259300f1-01bb-11e3-89a8-896ab45a266f;

但这会失败。为什么?

But this fails. Why? And how do I work around it?

update s4 set stuff='f' where b=259300f1-01bb-11e3-89a8-896ab45a266f;
error->> Bad Request: Non PRIMARY KEY b found in where clause


推荐答案

在不指定主键的情况下进行更新意味着Cassandra必须首先进行分布式搜索以获取所有记录。然后在内部发出所有这些记录的更新。虽然它是可能实现的,它是非常不同的Cassandra内的当前写路径。

Doing an update without specifying the primary key would mean Cassandra would have to first do the distributed search to get all of the records. Then internally issue the update for all of those records. While it would be possible to implement, it is very different from the current write path inside Cassandra.

当前的写路径查看插入/更新计算出什么节点

The current write path looks at the insert/update figures out what nodes it should be sent to based on the key, then sends the request on to those nodes to be written to disk.

更新X的写入路径其中Y ,其中Y是次要索引,将是非常不同的。它需要向每个节点发送更新请求,并等待搜索/更新过程完成。它将需要比正常写更长的时间,Cassandra擅长快速写入。

The write path for update X where Y, where Y is a secondary index, would be much different. It would require sending the update request to every node, and waiting for the search/update process to finish. It would take much longer than a normal write, and Cassandra excels at fast writes.

话虽如此,Cassandra项目总是对新特性的贡献和讨论开放。 http://wiki.apache.org/cassandra/HowToContribute

That being said, the Cassandra project is always open to contributions and discussion of new features. http://wiki.apache.org/cassandra/HowToContribute

对于我如何解决它。唯一的方法是自己执行select语句,然后自己更新所有行。或重新设计您的数据模型,以便您要做的更新基于主键。

For "How do I work around it". The only way is to perform the select statement yourself, and then update all the rows yourself. Or redesign your data model such that the update you want to do is based on a primary key.

这篇关于为什么cassandra“选择”在二级密钥,但不是使用二级密钥更新? (1.2.8+)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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