我在创建基于时间的有序表时遇到了奇怪的行为。 通常使用status_by_user表的模式,最新状态应始终位于顶部,当检索插入的数据时,我发现它没有正确排序。 (看一下cqlsh输出)
我遗失了什么?
-- Running on Cassandra-2.0.4
-- Inserted some pseudo randomly data from 2013 and 2014
CREATE TABLE status_by_user (
id timeuuid,
uname text
status_ts timestamp,
status_ts_day int, -- YYYYMMDD
status_comment text,
PRIMARY KEY ((uname,status_ts_day),id)
) WITH CLUSTERING ORDER BY (id DESC);
cqlsh> select dateOf(id),status_ts from status_by_user LIMIT 110;
dateOf(id) | status_ts
------------------------------------------+------------------------------------------
2014-03-08 18:46:39Romance Standard Time | 2014-03-08 18:46:39Romance Standard Time
2014-03-08 18:46:38Romance Standard Time | 2014-03-08 18:46:38Romance Standard Time
2014-03-08 18:46:38Romance Standard Time | 2014-03-08 18:46:38Romance Standard Time
2014-03-08 06:46:39Romance Standard Time | 2014-03-08 06:46:39Romance Standard Time
2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
2014-03-08 06:46:38Romance Standard Time | 2014-03-08 06:46:38Romance Standard Time
2014-03-08 06:46:37Romance Standard Time | 2014-03-08 06:46:37Romance Standard Time
2014-03-08 06:46:37Romance Standard Time | 2014-03-08 06:46:37Romance Standard Time
2014-03-08 06:46:37Romance Standard Time | 2014-03-08 06:46:37Romance Standard Time
2014-03-15 19:46:39Romance Standard Time | 2014-03-15 19:46:39Romance Standard Time
2014-03-15 19:46:39Romance Standard Time | 2014-03-15 19:46:39Romance Standard Time
2014-03-15 19:46:39Romance Standard Time | 2014-03-15 19:46:39Romance Standard Time
2014-03-15 19:46:38Romance Standard Time | 2014-03-15 19:46:38Romance Standard Time
2014-03-15 19:46:38Romance Standard Time | 2014-03-15 19:46:38Romance Standard Time
2014-03-15 19:46:38Romance Standard Time | 2014-03-15 19:46:38Romance Standard Time
2014-03-15 17:46:39Romance Standard Time | 2014-03-15 17:46:39Romance Standard Time
2014-03-15 17:46:39Romance Standard Time | 2014-03-15 17:46:39Romance Standard Time
2014-03-15 17:46:38Romance Standard Time | 2014-03-15 17:46:38Romance Standard Time
2014-03-15 17:46:37Romance Standard Time | 2014-03-15 17:46:37Romance Standard Time
2014-03-15 17:46:37Romance Standard Time | 2014-03-15 17:46:37Romance Standard Time
2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
2013-12-19 01:46:39Romance Standard Time | 2013-12-19 01:46:39Romance Standard Time
2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
2013-12-19 01:46:38Romance Standard Time | 2013-12-19 01:46:38Romance Standard Time
2013-12-19 01:46:37Romance Standard Time | 2013-12-19 01:46:37Romance Standard Time
2013-10-24 00:46:39Romance Daylight Time | 2013-10-24 00:46:39Romance Daylight Time
2013-10-24 00:46:39Romance Daylight Time | 2013-10-24 00:46:39Romance Daylight Time
2013-10-24 00:46:38Romance Daylight Time | 2013-10-24 00:46:38Romance Daylight Time
2013-10-24 00:46:37Romance Daylight Time | 2013-10-24 00:46:37Romance Daylight Time
2013-10-24 00:46:37Romance Daylight Time | 2013-10-24 00:46:37Romance Daylight Time
2013-10-24 00:46:37Romance Daylight Time | 2013-10-24 00:46:37Romance Daylight Time
? ->2013-12-25 01:46:39Romance Standard Time | 2013-12-25 01:46:39Romance Standard Time
2013-12-25 01:46:38Romance Standard Time | 2013-12-25 01:46:38Romance Standard Time
2013-12-25 01:46:38Romance Standard Time | 2013-12-25 01:46:38Romance Standard Time
2013-12-25 01:46:38Romance Standard Time | 2013-12-25 01:46:38Romance Standard Time
2013-12-25 01:46:37Romance Standard Time | 2013-12-25 01:46:37Romance Standard Time
? ->2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
2014-01-16 01:46:39Romance Standard Time | 2014-01-16 01:46:39Romance Standard Time
2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
2014-01-16 01:46:38Romance Standard Time | 2014-01-16 01:46:38Romance Standard Time
..
..
(110 rows)
更新
我认为在订购数据时没有考虑主键的分区部分“(uname,status_ts_day)”,因为知道订购是通过聚类键“id”完成的。
有人可以澄清一下吗?
cqlsh> select uname,status_ts_day,dateOf(id), status_ts from trans.status_by_user LIMIT 110;
uname | status_ts_day | dateOf(id) | status_ts
--------+---------------+------------------------------------------+------------------------------------------
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test47 | 20140319 | 2014-03-19 06:13:20Romance Standard Time | 2014-03-19 06:13:20Romance Standard Time
test10 | 20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
test10 | 20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
test10 | 20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
test10 | 20140114 | 2014-01-14 13:13:20Romance Standard Time | 2014-01-14 13:13:20Romance Standard Time
test10 | 20140114 | 2014-01-14 11:13:20Romance Standard Time | 2014-01-14 11:13:20Romance Standard Time
test10 | 20140114 | 2014-01-14 11:13:20Romance Standard Time | 2014-01-14 11:13:20Romance Standard Time
test2 | 20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
test2 | 20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
test2 | 20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
test2 | 20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
test2 | 20140123 | 2014-01-23 12:13:20Romance Standard Time | 2014-01-23 12:13:20Romance Standard Time
test66 | 20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
test66 | 20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
test66 | 20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
test66 | 20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
test66 | 20131120 | 2013-11-20 12:13:20Romance Standard Time | 2013-11-20 12:13:20Romance Standard Time
test34 | 20131223 | 2013-12-23 00:13:20Romance Standard Time | 2013-12-23 00:13:20Romance Standard Time
test34 | 20131223 | 2013-12-23 00:13:20Romance Standard Time | 2013-12-23 00:13:20Romance Standard Time
test33 | 20140305 | 2014-03-05 06:13:20Romance Standard Time | 2014-03-05 06:13:20Romance Standard Time
test33 | 20140305 | 2014-03-05 06:13:20Romance Standard Time | 2014-03-05 06:13:20Romance Standard Time
(110 rows)
提前感谢任何建议。