DataStax Storage-Attached Indexing (SAI) lets you create one or multiple secondary indexes on the same database table, with each SAI index based on any column. SAI provides more functionality compared to Cassandra secondary indexes, is faster at writes compared to any Cassandra or DSE Search index, and uses significantly less disk space.
In this scenario, we'll learn how to:
- Create an Astra database
- Install and configure cqlsh
- Create a table in Astra
- Create SAI indexes on columns
- Perform SELECT queries based on indexed columns
Astra is a great Cassandra as a Service offering, making setup easy for us. Let's get started!
This scenario is also available on our datastax.com/dev site, where you can find many more resources to help you succeed with Apache Cassandra™.
Using Storage-Attached Indexing (SAI) for Apache Cassandra™
Create your Astra Database
Defining one or more SAI indexes based on any column in a database table subsequently gives you the ability to run performant queries that specify the indexed column.
What is an index?An index provides a means to access data in Cassandra using attributes other than the partition key. The benefit of an index is fast, efficient lookup of data that matches a given condition.
First of all though, you are going to need to setup an Astra database and an initial keyspace. Astra is cloud-native Cassandra-as-a-Service, built on Apache Cassandra.
Have an existing Astra database and keyspace?
-- Move on to Step 2.
If you don't have an Astra account, set one up - it's easy.
Go to the Astra page in your browser: astra.datastax.com.
When you log in the first time you'll find yourself looking at the Astra dashboard. If you don't have a database yet, you will need to create one. Click on the "Add Database" button.
Now you can select your plan, we recommend the Free tier for experimenting. (You can't choose your provider if Free tier is chosen.) Then select your region.Then click the "Configure" button in the lower right of the screen.
Next you will provide a database name, keyspace, username and password. You should fill in the specific values we have provided (but choose your own password, it must include a number). Then click the "Create Database" button. It will take a few minutes for your database to initiallize.
Don't forget your password - you will need it soon.