У меня есть таблица уведомлений и дополнительный индексзапись и запись обновлений на Кассандре вместе с кластерными колоннами
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 строки в одной строке, я получаю отсутствующая ошибка постданных, которая является столбцом кластеризации
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 для столбца кластеризации. Однако в то же время мне нужно обновить определенную строку. Я думаю, что речь идет о дизайне, но все еще не могла понять. Мы ценим любые предложения.
Спасибо Аарон, кажется, что я должен получить сначала постдатировать и обновление в соответствии с ней – mehmetsen80