Dark Mode

Use Storage-Attached Indexing (SAI) to create one or more indexes on DataStax Astra DB database tables. For cloud applications with high-volume data, SAI indexes make data writes and query retrieval faster. For more, see the https://docs.datastax.com/en/storage-attached-index/6.8/sai/saiTOC.html[SAI guide, window="_blank"].

In the CQL Console, login and add SAI indexes on existing tables.Follow the examples below to create SAI indexes on the products , ordersbycustomer , and productsbyorders tables of the Better Botz sample app.To learn more about SAI, see https://www.datastax.com/dev/cassandra-indexing[Indexing in Cassandra with Storage Attached Indexes (SAI), window="_blank"].To make it easier for you, some of these steps are repeated here.

If you prefer to use Katacoda to learn how to use SAI, follow the scenario through the link below:

Create a database using Astra DB.

If you named your keyspace something other than betterbotz , change betterbotz in the USE statements below to match your keyspace name, such as USE mykeyspace .

  • Open a browser, navigate to Astra DB, and log in.
  • From the Databases page, select the CQL Console tab to open the CQL shell (CQLSH).
  • Enter the username and password you set when you created the database.
  • At the CQLSH prompt, enter the keyspace name.
  • 1
  • If you used a prior version of Better Botz that created the products and orders tables, remove these tables:
  • 1

We'll create enhanced versions in the next step.

  • Copy the following CQL statements and paste them at the CQLSH prompt:
  • 1
  • Create Storage-Attached Indexing (SAI) indexes on columns in the tables.

It is not necessary to define indexes on each table's primary key.

You cannot index a partition key when there is only one column comprising that key.However, if you have tables with composite partition keys (two or more columns setting the partition criteria), in each SAI index you can specify one of the columns that comprise the composite partition key.See https://docs.datastax.com/en/storage-attached-index/6.8/sai/saiUsing.html[Examine column index and query rules, window="_blank"].

  • 1
  • Load data in the Better Botz tables.In the CQLSH prompt for your database, copy and paste the following INSERT statements to insert data into the tables.
  • 1

*This is an extremely small amount of data!* The point of this topic is to show the mechanics of the SAI index creation process.

Your Better Botz tables now have SAI-indexed data.Let's check it out!

Enter some queries that specify the SAI-indexed columns, and observe the results.You'll need to scroll down to see all the examples.

  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1

Results

Your Better Botz database now has SAI indexes defined!For high-volume data, SAI indexes make data writes and query retrieval faster.For more, see the SAI guide.