如何在 ORDER BY 子句中使用此主键中的第二列以及使用 UPDATE 命令更新它

How can I use the second column in this primary key both in ORDER BY clause as well as update it using an UPDATE command

下面是table.

CREATE TABLE threadpool(
threadtype int, 
threadid bigint, 
jobcount bigint, 
valid boolean, 
PRIMARY KEY (threadtype, jobcount, threadid)
);

我想 运行 关于此 table 的以下 2 个查询。

  1. SELECT * FROM threadpool WHERE threadtype = 1 ORDER BY jobcount ASC LIMIT 1;

  2. UPDATE threadpool SET valid = false WHERE threadtype = 1 and threadid = 4;

第二次查询失败,原因如下。

InvalidRequest: code=2200 [Invalid query] message="PRIMARY KEY column "threadid" cannot be restricted (preceding column "jobcount" is either not restricted or by a non-EQ relation)"

任何人都可以帮助我对数据建模以支持上述两个查询。

您描述的数据模型无法正常工作,因为

  • 只能使用 CQL 语句递增数据类型 counter 的值
  • 计数器表只能将计数器作为 PK 旁边的单个列
  • 您不能按计数器值排序