Why does querying based on the first clustering key require an ALLOW FILTERING?

Viewed 72

Say I have this Cassandra table:

CREATE TABLE orders (
  customerId int, 
  datetime date, 
  amount int, 
  PRIMARY KEY (customerId, datetime)
);

Then why would the following query require an ALLOW FILTERING:

SELECT * FROM orders WHERE date >= '2020-01-01'

Cassandra could just go to all the individual partitions (i.e. customers) and filter on the clustering key date. Since date is sorted there is no need to retrieve all the rows in orders and filter out the ones that match my where clause (as far as I understand it).

I hope someone can enlighten me.

Thanks

1 Answers

This happens because for normal work, Cassandra needs the partition key - it's used to find what machine(s) are storing the data for it. If you don't have partition key, like, in your example, Cassandra need to scan all data to find those that are matching your query. And this requires the use of the ALLOW FILTERING.

P.S. Data is sorted only inside the individual partitions, not globally.

Related