CASSANDRA CQL and Data Modeling 2 — Questions and Answers
Question 1: What is 'ALLOW FILTERING' in CQL and why should it be used with caution?
- It enables full-text search on TEXT columns
- It forces Cassandra to scan all partitions to satisfy a query without a partition key, which is expensive (Correct answer)
- It allows filtering on materialized view columns
- It enables server-side filtering with secondary indexes only
Correct answer: It forces Cassandra to scan all partitions to satisfy a query without a partition key, which is expensive
ALLOW FILTERING permits queries without a partition key filter but causes a full cluster scan, which is extremely inefficient on large datasets.
Question 2: What is the purpose of a secondary index in Cassandra?
- To partition data across more nodes
- To allow queries on non-primary-key columns without needing ALLOW FILTERING (Correct answer)
- To compress SSTable files
- To deduplicate rows with the same clustering key
Correct answer: To allow queries on non-primary-key columns without needing ALLOW FILTERING
A secondary index builds a local index on each node for a non-primary-key column, enabling filtered queries on that column across all partitions.
Question 3: In Cassandra data modeling, what is 'denormalization'?
- Removing duplicate columns from a table
- Storing duplicate data in multiple tables to support different query patterns efficiently (Correct answer)
- Normalizing data into separate tables with foreign keys
- Partitioning a large table into smaller ones
Correct answer: Storing duplicate data in multiple tables to support different query patterns efficiently
Because Cassandra cannot perform joins, data is intentionally duplicated across multiple tables, each designed for a specific query access pattern.
Question 4: What does the CQL statement 'UPDATE ... IF EXISTS' provide?
- A batch update across multiple partitions
- A lightweight transaction that only applies the update if the row already exists (Correct answer)
- An upsert that creates the row if missing
- A conditional update using Paxos consensus
Correct answer: A lightweight transaction that only applies the update if the row already exists
IF EXISTS uses Cassandra's lightweight transaction (LWT) mechanism backed by Paxos to perform a compare-and-swap, only updating if the row already exists.
Question 5: Which CQL collection type stores an ordered list of elements that allows duplicate values?
- SET
- MAP
- LIST (Correct answer)
- FROZEN
Correct answer: LIST
The LIST type stores an ordered collection of elements and permits duplicates, unlike SET which is unordered and deduplicated.
Question 6: What is the maximum recommended size for a Cassandra partition?
- 100 MB (Correct answer)
- 1 GB
- 100 KB
- 10 GB
Correct answer: 100 MB
Partitions should ideally stay under 100 MB; very large partitions degrade read/write performance and complicate repairs and compaction.
What is 'ALLOW FILTERING' in CQL and why should it be used with caution?