Adding a secondary index

There is one exception to this rule, and that is when a secondary index is in use. A secondary index should be a familiar concept to anyone who has worked with a relational database; in the relational world, they're often just referred to as indexes. Put simply, secondary indexes allow us to perform a reasonably efficient lookup of rows using columns other than the partition key.

In our case, we'd like to look up rows in user_follows by providing a value for the follower_username row but omitting a value for the followed_username partition key. To do this, we can use the CREATE INDEX statement:

CREATE INDEX ON "user_follows" ("follower_username");

The syntax here is pretty straightforward: we simply provide Cassandra ...

Get Learning Apache Cassandra - Second 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.