具有1个EQ限制和ORDER BY的cql3查询

Iva*_*nyy 8 cassandra cql3

使用CF:

CREATE TABLE history (
  domain text,
  iid text,
  timeid timeuuid,
  data text,
  comments text,
  PRIMARY KEY (domain, iid, timeid)
);
Run Code Online (Sandbox Code Playgroud)

我想像这样查询:

select domain, iid, timeid, data, comments from mappings
where domain = 'a' and iid = 'b'  order by timeid desc;
Run Code Online (Sandbox Code Playgroud)

但它失败并出现以下错误(cassandra 1.1.5):

Bad Request: Order by currently only support the ordering of columns following their declared order in the PRIMARY KEY
Run Code Online (Sandbox Code Playgroud)

我做错了吗?可能的解决方法是什么?谢谢

PS我使用单一的EQ限制和ORDER BY,但我需要至少2个限制和排序.

小智 9

您可以将"order by"列更改为主键中的第二列:

select * from history where domain = 'a' and iid = 'b' order by iid desc;

这有点令人困惑,因为你限制iid了相等,但它的工作原理 - 你将得到你的结果排序timeid.

我相信这是因为iidtimeid形成一个复合列,当您按iid降序排序时,它会对所有复合列组件进行排序,包括timeid.