Indexing concepts
The data stored in CQL tables can be queried by a variety of methods. The main method uses the partition key defined for a table, and is called primary indexing. However, often a query must be selected using another column of a table, and secondary indexing is required. Secondary indexing use fast, efficient lookup of data that matches a given condition.
Cassandra has the following types of indexing available:
Indexing type | Astra DB Serverless | Astra DB Classic | Apache Cassandra | DataStax Enterprise (DSE) |
---|---|---|---|---|
Primary indexing |
✓ |
✓ |
✓ |
✓ |
Storage-attached indexing (SAI) |
✓ |
✓ |
✓ |
|
Secondary indexing (2i) |
✓ |
✓ |
✓ |
|
DSE Search indexing |
✓ |
✓ |
After any index is created, data can be queried using that index.
Primary indexing
The primary index is the partition key in Cassandra. The storage engine of Cassandra uses the partition key to store rows of data, and the most efficient and fast lookup of data matches the partition key.
Storage-attached indexing (SAI)
SAI uses indexes for non-partition columns, and attaches the indexing information to the SSTables that store the rows of data. SAI is the most appropriate indexing method for most use cases.
Secondary indexing (2i)
Secondary indexing are the original built-in indexes for Cassandra. These indexes are a local index, stored in a hidden table on each node of a Cassandra cluster, separate from the table that contains the values being indexed. This indexing method is only recommended when used in conjunction with a partition key.
DSE Search indexing
DataStax Enterprise (DSE) also features a Apache Solr-Apache Lucene search indexing method. This indexing method focuses on tokenized text search.