Cassandra &引用;错误请求:无法限制“U id”的主键部分;尝试使用where条件选择时
这是我的cassandra表,用于聊天类应用程序:Cassandra &引用;错误请求:无法限制“U id”的主键部分;尝试使用where条件选择时,cassandra,cql,cqlsh,Cassandra,Cql,Cqlsh,这是我的cassandra表,用于聊天类应用程序: CREATE TABLE tax_keyspace_dev.chat_messages ( message text, when timestamp, from_id text, to_id text, read boolean, participants text, PRIMARY KEY(participants, when, to_id) ); 此查询工作: select * from tax_keyspac
CREATE TABLE tax_keyspace_dev.chat_messages (
message text,
when timestamp,
from_id text,
to_id text,
read boolean,
participants text,
PRIMARY KEY(participants, when, to_id)
);
此查询工作:
select * from tax_keyspace_dev.chat_messages where participants='caone@one.com_shashank_shrivastava@acme.com' order by when;
但以下查询不起作用:
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;
错误为“请求错误:无法限制\u id的主键部分(不受限制或受非EQ关系限制时的前一部分)”
错误为“错误请求:缺少\u id的必需主键部分”
如果我从复合键中删除“to_id”并创建单独的索引,如下所示:
CREATE TABLE tax_keyspace_dev.chat_messages (
message text,
when timestamp,
from_id text,
to_id text,
read boolean,
participants text,
PRIMARY KEY(participants, when)
);
CREATE INDEX idx_chat_messages_to ON tax_keyspace_dev.chat_messages (to_id);
然后其他查询工作,但此查询失败:
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;
出现错误“请求错误:不支持具有第2个索引的ORDER BY。”
我如何设计我的表,使所有这些用例都可以工作
select * from tax_keyspace_dev.chat_messages where participants='caone@one.com_shashank_shrivastava@acme.com' order by when;
update tax_keyspace_dev.chat_messages set read=true where participants = 'caone@one.com_shashank_shrivastava@acme.com' and when = '2014-04-10 17:44:22+0530';
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;
使用cassandra时,主键的第一部分将成为分区键。因此,要转到一个特定的分区来检索该行,您需要始终使用equals约束指定主键
select * from tax_keyspace_dev.chat_messages where participants='caone@one.com_shashank_shrivastava@acme.com' order by when;
下面的查询建议您到达名为“参与者”的行分区,然后在使用ASC的默认顺序时按排序。由于默认情况下列是按升序排序的,因此可能也不需要按此顺序排序
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;
以下查询不起作用,因为您没有提供行分区来定位值。默认情况下,行分区键用于标识包含数据的SSTables。因此,默认情况下,卡桑德拉不支持这种昂贵的操作
发生的事情很简单。如果您错过了这个行分区键,cassandra必须扫描所有SSTables并从中获取数据。这可以通过使用允许筛选来实现,但是您的查询会变得昂贵,因为它不会使用bloom筛选器
update tax_keyspace_dev.chat_messages set read=true where participants = 'caone@one.com_shashank_shrivastava@acme.com' and when = '2014-04-10 17:44:22+0530';
在cassandra更新的情况下,它与insert没有什么不同。只需考虑使用地图操作的情况。您正试图修改一个值,但没有映射的完整键。在内部,cassandra存储的值是“参与者”when_to_id:value 嗯,我想我明白你的意思了。我将不进行排序,只在由于性能不可预测而导致一次性使用“允许筛选”时才使用它
update tax_keyspace_dev.chat_messages set read=true where participants = 'caone@one.com_shashank_shrivastava@acme.com' and when = '2014-04-10 17:44:22+0530';