Clustering key example

Let's say that we wanted to be able to offer up the same data, but to support a query for users by department. The table definition would change to something like this:

CREATE TABLE users_by_dept (  username TEXT,  email TEXT,  department TEXT,  title TEXT,  AD_groups TEXT,  PRIMARY KEY ((department),username))WITH CLUSTERING ORDER BY (username ASC)  AND COMPACTION = {'class':'LeveledCompactionStrategy',  'sstable_size_in_mb':'200'};

As the preceding table will be read more than it will be written to (users queried more often than they are added), we also designate use of LeveledCompactionStrategy.

The default compaction strategy is SizeTieredCompactionStrategy, which tends to favor read and write patterns that are either even ...

Get Mastering Apache Cassandra 3.x - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.