What is Cassandra's secondary index and materialized view?

Answer

Cassandra has limited support for querying non-partition-key columns. Secondary indexes: CREATE INDEX ON users (email);. Allows querying by email without the partition key. Warning: secondary indexes in Cassandra are not like SQL indexes. They are distributed — each node maintains an index for its local data, so a query hits all nodes. Avoid secondary indexes in production for high-cardinality columns (many unique values) or low-cardinality columns (few distinct values, huge results). They cause cluster-wide queries. Materialized views (MVs): pre-computed tables derived from a base table with a different primary key. Example: if the base table has PRIMARY KEY (user_id), a MV can have PRIMARY KEY (email, user_id) — enabling queries by email. Cassandra maintains the MV automatically on writes. Warning: MVs have performance implications — each write to the base table triggers a write to the MV. They have known issues with eventual consistency and are considered experimental by some. Prefer manually maintaining duplicate tables (query tables) over MVs for production use.