Andrei Toutoukine
Andrei Toutoukine

Reputation: 107

Filter on boolean column

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?

Upvotes: 0

Views: 1288

Answers (1)

jny
jny

Reputation: 8057

IMHO, tag would be a better candidate for a secondary index. If it is a clustering key, what is a partition key?

I would model this with 3 tables:

Table 1
Primary key:PostId 
Columns: Post Content
Table 2
Primary Key:  ( (timebucket), timestamp, visibility)
Columns:PostId
Table 3
Primary Key: Tag
Columns:PostId

Upvotes: 1

Related Questions