【发布时间】:2017-11-04 13:30:43
【问题描述】:
这是我用来创建表的查询:
CREATE TABLE test.comments (msguuid timeuuid, page text, userid text, username text, msg text, timestamp int, PRIMARY KEY (msguuid));
我想获取按时间戳降序排序的最后 50 行。
如果我尝试类似:SELECT * FROM test.comments WHERE page = 'test' AND timestamp < 1496468332,我会收到此错误:
Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
我不想使用允许过滤,我希望查询尽可能快。
我在这里查看了另一个 stackoverflow 问题 Cassandra cql: how to select the LAST n rows from a table 并尝试了解决方案:
CREATE TABLE test.comments (msguuid timeuuid, page text, userid text, username text, msg text, timestamp int, PRIMARY KEY (msguuid)) WITH CLUSTERING ORDER BY (msguuid DESC);
然后我得到这个错误:InvalidRequest: Error from server: code=2200 [Invalid query] message="Only clustering key columns can be defined in CLUSTERING ORDER directive"
我是 Cassandra 的新手,如果这有一个明显的答案,请原谅我。我似乎无法让它工作。
如果有人可以帮助我,我将不胜感激。
【问题讨论】:
-
页面是索引字段吗?
-
是的,页面已编入索引
-
你使用的是哪个 cassandra 版本?
-
[cqlsh 5.0.1 |卡桑德拉 3.10 | CQL 规范 3.4.4 |原生协议 v4]
-
如何使用当前时间生成 msguuid ??