如何在两个选择的Cassandra查询中两次选择同一行?

发布于 2025-01-30 17:23:49 字数 628 浏览 3 评论 0原文

我正在与卡桑德拉(Cassandra)一起从事一个社交网络项目。用户可以订阅个人资料,并可以访问已订阅同一个人资料的人列表。我的目标是在一个名为 user_follows 的表中检索订阅个人资料的人列表。

CREATE TABLE users_follows (to_id text, from_id text, followed_at timestamp, PRIMARY KEY(to_id, from_id))

问题是有些配置文件可以拥有数千个订户,我不想一次获得所有订户。这就是为什么我想根据用户向下的距离,以20的速度获得列表。我的问题是,由于Cassandra始终返回相同的用户,因此我看不到如何检索列表的其他部分。

SELECT * FROM users_follows where to_id = 'xxxxx'

一个可能的解决方案是使用时间戳进行排序,但如果我想检索订阅用户的人列表(反向查询)这将无法使用。一种解决方案是使用实体视图,但我不确定鉴于表格的大小,它是否会非常最佳。或创建另一个表,一个 user_follows 和另一个 user_followers ,但我不建议这样做...。

I am working on a social networking project with cassandra. Users can subscribe to a profile and have access to the list of people who have subscribed to that same profile. My goal is to retrieve in a table called user_follows the list of people subscribed to a profile.

CREATE TABLE users_follows (to_id text, from_id text, followed_at timestamp, PRIMARY KEY(to_id, from_id))

The problem is that some profiles can have thousands of subscribers and I don't want to get them all at once. That's why I'd like to get the list in increments of 20 depending on how far down the user goes. My problem is that I can't see how to retrieve the other parts of the list after the first select because Cassandra always returns the same users.

SELECT * FROM users_follows where to_id = 'xxxxx'

A possible solution was to sort with a timestamp but in case I want to retrieve the list of people to whom a user is subscribed (the reverse query) this would not work. One solution would be to use materialized views but I'm not sure that it would be very optimal given the size of the table. Or to create a different table, one user_follows and another user_followers, but I don't think this is very recommended....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文