【发布时间】:2017-04-02 15:41:02
【问题描述】:
我有一个通知表和附加索引
CREATE TABLE notification (
postid double,
userid double,
type text,
message text,
hasread boolean,
postdate timestamp,
PRIMARY KEY (userid, postdate)
) WITH CLUSTERING ORDER BY (postdate DESC);
CREATE INDEX postid ON notification(postid);
假设我插入了几行
select * from notification;
userid | postdate | hasread | message | postid | type
--------+---------------------------------+---------+------------------------+--------+---------
104 | 2016-11-18 17:21:32.692000+0000 | False | Let\'s do it together! | 70521 | newpost
104 | 2016-11-18 17:21:26.511000+0000 | False | Let\'s do it together! | 90521 | newpost
103 | 2016-11-18 17:20:17.284000+0000 | False | Let\'s do it together! | 40521 | newpost
103 | 2016-11-18 17:20:02.925000+0000 | False | Let\'s do it together! | 40521 | newpost
103 | 2016-11-18 17:19:55.643000+0000 | False | Let\'s do it together! | 30521 | newpost
103 | 2016-11-18 17:19:49.029000+0000 | False | Let\'s do it together! | 60521 | newpost
如果我做简单的查询,即
select * from notification where postid=40521;
那么结果似乎很好
userid | postdate | hasread | message | postid | type
--------+---------------------------------+---------+------------------------+--------+---------
103 | 2016-11-18 17:20:17.284000+0000 | False | Let\'s do it together! | 40521 | newpost
103 | 2016-11-18 17:20:02.925000+0000 | False | Let\'s do it together! | 40521 | newpost
或者让我们得到这样的一行
select * from notification where postid=60521;
单行看起来还不错
userid | postdate | hasread | message | postid | type
--------+---------------------------------+---------+------------------------+--------+---------
103 | 2016-11-18 17:19:49.029000+0000 | False | Let\'s do it together! | 60521 | newpost
但是,当我在一行中更新 hasread 行时,我会丢失 postdate 错误,即聚类列
update notification set hasread=true where postid=60521 and userid=103;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Some clustering keys are missing: postdate"
我需要按排序顺序获取列表,这就是我必须使用 postdate 作为聚类列的原因。 但是同时我需要更新特定的行。我想这是关于设计的,但仍然无法弄清楚。任何建议,将不胜感激。
【问题讨论】: