In the Apache Cassandra one needs a secondary index on a column to filter by. However a secondary index on a boolean column is an antipattern.
I have a collection of posts, each has a single tag (there are approx. 30 tags). One query is to show posts, that have a certain tag (it means that tag is a good candidate to the clustering key AFAIK).
There is also a logics that assigns a boolean "visibility" property to each post. Another query should show only visible posts, tag doesn't matter (ordered by timestamp descending).
How to model the post?
答案 0 :(得分:1)
恕我直言,标签将成为二级指数的更好候选者。如果它是一个集群密钥,那么什么是分区密钥?
我会用3个表格对此进行建模:
Table 1
Primary key:PostId
Columns: Post Content
Table 2
Primary Key: ( (timebucket), timestamp, visibility)
Columns:PostId
Table 3
Primary Key: Tag
Columns:PostId