In this learning unit, you will:
- Understand the purpose of materialized views
- Use CQL statement
CREATE MATERIALIZED VIEW
- Explore several examples of using materialized views
- Learn about limitations of materialized views
Each table only supports a limited set of queries based on its primary key definition. To support additional queries, the most generic and efficient solution is to duplicate the same data into a new table with a different primary key. This process is frequently referred to as data denormalization and data duplication. The drawback is that now you have to do multiple inserts, updates and deletes to maintain the same data stored in multiple places. You may even need to use atomic batches in some cases.
To remove the burden of keeping multiple tables in sync from a developer, Cassandra supports an experimental feature called materialized views. A materialized view is a read-only table that automatically duplicates, persists and maintains a subset of data from a base table. Any change to data in a base table is automatically propagated to every view associated with this table.
Materialized views are great for convenience but you should also be aware of their limitations, which we discuss later in this presentation.