Spearfisher
Spearfisher

Reputation: 8783

Cassandra - filtering results on a boolean

I have a table looking like this:

CREATE TABLE table(
  user text,
  gender boolean,
  ...,
  PRIMARY KEY(user)
);

where gender stands for true for a male and false for a female.

I'd like to make 3 types of queries:

I have thought of adding the gender parameter to the primary key. This would make queries 2 and 3 straightforward and to retrieve all users, I would need to make queries 2 and 3 and then concatenate the results.

The problem is that my user table get really big and I have to paginate the results. This poses a problem when gender is part of the primary key as I have to pass both pageState in my API response to enable the user to query for more results.

Is there a better way to enable this kind of requests making paging relatively easy and straightforward?

Many thanks

Upvotes: 0

Views: 531

Answers (1)

G Quintana
G Quintana

Reputation: 4667

There are 2 questions in one.

First, the querying one. If you need these 3 types of queries then denormalize and create 3 tables: users, male_users and female_users.

Second, the paging one. If you're listing all users (or male/Female users) by querying at the table level results will be unsorted because multiple nodes will participate in elaborating the result and that partitions are hashed. If you're talking about paging at the UI level (only the first 100 users are fetched and displayed), it will be tricky. If you're talking about paging at the driver level (all users are fetched by chunks/pages), then it may be easier.

Upvotes: 2

Related Questions