cassandra Cassandra keys Key ordering and allowed queries

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The partition key is the minimum specifier needed to perform a query using a where clause.

If you declare a composite clustering key, the order matters.

Say you have the following primary key:

PRIMARY KEY((part_key1, part_key_2), (clust_key_1, clust_key_2, clust_key_3))

Then, the only valid queries use the following fields in the where clause:

  • part_key_1, part_key_2
  • part_key_1, part_key_2, clust_key_1
  • part_key_1, part_key_2, clust_key_1, clust_key_2
  • part_key_1, part_key_2, clust_key_1, clust_key_2, clust_key_3

Example of invalid queries are:

  • part_key_1, part_key_2, clust_key_2
  • Anything that does not contain both part_key_1, part_key_2
  • ...

If you want to use clust_key_2, you have to also specify clust_key_1, and so on.

So the order in which you declare your clustering keys will have an impact on the type of queries you can do. In the opposite, the order of the partition key fields is not important, since you always have to specify all of them in a query.



Got any cassandra Question?