Reputation: 619
Using Cassandra as db:
Say we have this schema
primary_key((id1),id2,type)
with index
on type
, because we want to query by id1
and id2
.
Does query like
SELECT * FROM my_table WHERE id1=xxx AND type='some type'
going to perform well?
I wonder if we have to create and manage another table for this situation?
Upvotes: 2
Views: 151
Reputation: 2996
The way you are planning to use secondary index is ideal (which is rare). Here is why:
Overall, your data model should perform well and scale. Yet, if you look for optimal performances, I would suggest you use an additional table ((id1), type, id2).
Finale note: if you have a limited number of type, you might consider using solely ((id1), type, id2) as a single table. When querying by id1-id2, just issue a few parallel queries against the possible value of type.
The final decision needs to take into account your target latency, the disk usage (duplicating table with a different primary key is sometimes too expensive), and the frequency of each of your queries.
Upvotes: 1