Is there a way to efficiently get the top n smallest datapoints over the cluster key in Cassandra?

Viewed 42

I understand that for Cassandra data is sorted on the cluster key only per partition key.

I am wondering if Cassandra has optimizations on global scans. Lets say that the cluster key is an integer value, if I want to search over all data on a Cassandra cluster to find collections with values < 3. The Cassandra query engine will not need to continue looking at collections in a partition after encountering a number >= 3. Are there APIs (such as CDK) offered by Cassandra which exercise these optimizations?

2 Answers

There isn't a native CQL optimisation available for full table scans -- they will always be bad since Cassandra is optimised for OLTP workloads.

There are however optimisations done by the spark-cassandra-connector for analytics (OLAP) workloads with Spark.

OLTP vs OLAP are worlds apart so you have to use the right tool for the job. Cheers!

Querying by partition key is the best way the query in Cassandra. If you want to use clustering key for querying then you can use "ALLOW FILTERING" option. But it is recommended not to use "ALLOW FILTERING" in production.

For scanning complete table and filtering some data, you can use spark to do your work. Why bother C* for which it is not designed, better to take help of its friends (spark in this case)

Related