Back to questions
JuniorTheoryCommon
Why can't analysts run ad-hoc filters and GROUP BY reports on a table in the wide-column store Cassandra?
A Cassandra table is built for one query: the partition key picks the nodes, clustering columns order rows inside a partition. There are no joins; a filter on another column needs ALLOW FILTERING, a scan of every partition. Analytics runs on an extract.
- Treating
ALLOW FILTERINGas a harmless switch instead of a scan of every partition in the cluster - Modelling a Cassandra table like a normalised relational table and expecting joins to assemble the report
- Reading 'wide-column' as column-oriented storage, as in an analytical warehouse
- The product team now also needs orders by status — what do you add to the Cassandra schema?
- How would you copy a whole Cassandra table into the warehouse without any
ALLOW FILTERINGquery?
What it looks like. An orders table for the query "a customer's orders over a period, newest first":
CREATE TABLE shop.orders_by_customer (
customer_id uuid,
order_ts timestamp,
order_id uuid,
status text,
total decimal,
PRIMARY KEY ((customer_id), order_ts, order_id)
) WITH CLUSTERING ORDER BY (order_ts DESC, order_id ASC);
-- works: one partition, a contiguous range of the clustering column
SELECT * FROM shop.orders_by_customer
WHERE customer_id = ? AND order_ts >= '2026-11-01';
-- rejected: filter outside the key (with ALLOW FILTERING, a scan of every partition),
-- and GROUP BY takes only primary-key columns
SELECT status, sum(total) FROM shop.orders_by_customer
WHERE status = 'paid' GROUP BY status;- The partition key takes only equality or
IN; clustering columns are restricted in order, with no gaps. - A new query means a new table holding the same data (denormalisation):
orders_by_status, partitioned by status and day. The application writes to both. - CQL does have
GROUP BY, but only on primary-key columns in key order, starting with the partition key; it cannot group bystatus. - A secondary index (SAI in Cassandra 5.0) allows a filter on a non-key column without
ALLOW FILTERING, but it serves selective queries, not aggregates over the whole table.
The data-engineering takeaway. "All customers for the month" reports are not run in Cassandra: the table is extracted whole (by token-range scans, not ALLOW FILTERING) into a warehouse, where filters and joins are cheap. How Cassandra differs from other NoSQL families is a separate question; what matters here is that its schema fixes the read path.