Cassandra,查询主键,跳过聚类列(timeuuid)

Cassandra, query the primary key, skipping the clustering column (timeuuid)

我还是 Cassandra 的新手,我有一个问题想解决,但我已经尝试过了,但我做不到。

我想获得所有喜欢特定 post 的用户以及特定用户喜欢的所有 post 并且我有一个喜欢和不喜欢的按钮,当用户点击喜欢按钮时post 我将信息保存到这些 table 中,这是有效的,但是当用户单击不同按钮时,我如何从下面的这些 table 中删除该特定行

CREATE TABLE social.post_likedby_user (
   userid bigint,
   timeuuid timestamp,
   postid bigint,
   content text,
   creation_date text,
   liked boolean,
   PRIMARY KEY (userid, timeuuid, postid)
)  WITH CLUSTERING ORDER BY (timeuuid DESC);

CREATE TABLE social.user_likeby_post (
   postid bigint,
   timeuuid timestamp,
   userid bigint,
   name text,
   username text,
   email text,
   phone text,
   birthday text,
   PRIMARY KEY (postid, timeuuid, userid)
)  WITH CLUSTERING ORDER BY (timeuuid DESC);

我查询了好几个都没有结果

DELETE FROM post_likedby_user WHERE userid = ? AND postid = ?
DELETE FROM user_likeby_post WHERE postid = ? AND userid = ?

如何在不知道 timeuuid 的情况下查询此 table。我认为问题是 timeuuid 列,我不想使用 ALLOW FILTERING 因为我读到它不利于生产

在这种情况下我们还需要一个 table post_timeuuids:

CREATE TABLE social.post_timeuuids (
   userid bigint,
   postid bigint,
   timeuuid timestamp,
   PRIMARY KEY (userid, postid, timeuuid)
) 

因此,要查询 timeuuid 值,您 运行 查询如下:

select timeuuid from post_timeuuids where userid = ? and postid = ?;

现在您可以使用这些值 运行 删除查询:

DELETE FROM post_likedby_user WHERE userid = ? AND timeuuid = ? AND postid = ? 

或者作为替代方法,您可以从 "post_timeuuids" table 中删除而不是删除。在应用程序方面,您应该考虑 "post_timeuuids" 中的数据:如果那里没有时间戳,则意味着该特定 post.

的用途没有 "likes"

下面的文章解释了为什么在没有 'timeuuid' 集群键

的情况下您不能 运行 查询 post_likedby_user

https://rollerweblogger.org/roller/entry/composite_keys_in_cassandra