Search code examples
cassandracql

Do I have to specify the partition key and all clustering keys in every query?


For example, if my primary key is a and clustering columns are b and c.

Can I only use the following in where condition?

select * from table where a = 1 and b = 2 and c = 3

Or are there any other queries that I can use?

I want to use

select * from table where a=1

and

select * from table where a = 1 and b = 2 and c = 3 and d = 4

Is that possible?

If not, then how can I model my data to make this possible?


Solution

  • Cassandra has lots of advantages, but it does not fit for every need.

    Cassandra is a good choice, when you need to handle large amount of writes. People like it, because Cassandra is easily scalable, can handle huge datasets and highly fault tolerant.

    You need to keep in mind that with Cassandra (if you really want to utilize it) the basic rule is to model your data to fit your queries. Don't model around relations. Don't model around objects. Model around your queries. This way you can minimize partition reads.

    And of course you can query not just the primary keys and partition columns. You can:

    but of course, these are not that effective as having a well-modeled table.