SAI Index Tables
The SAI (Storage-Attached Index) virtual tables provide introspection into index state, build progress, and per-SSTable index metadata. Available in Cassandra 5.0+.
Overview
Section titled “Overview”SAI indexes are tightly integrated with SSTable storage. These virtual tables expose:
- Index metadata and queryability status
- Per-SSTable index information
- Index segment details for debugging
| Table | Purpose |
|---|---|
sai_column_indexes | Index metadata and build status |
sai_sstable_indexes | Per-SSTable index info |
sai_sstable_index_segments | Detailed segment metadata |
sai_column_indexes
Section titled “sai_column_indexes”Metadata about SAI indexes including build status.
Schema
Section titled “Schema”VIRTUAL TABLE system_views.sai_column_indexes ( keyspace_name text, index_name text, table_name text, column_name text, analyzer text, is_building boolean, is_queryable boolean, is_string boolean, PRIMARY KEY (keyspace_name, index_name)) WITH CLUSTERING ORDER BY (index_name ASC)| Column | Type | Description |
|---|---|---|
keyspace_name | text | Keyspace name |
index_name | text | Index name |
table_name | text | Base table name |
column_name | text | Indexed column |
analyzer | text | Text analyzer (for string indexes) |
is_building | boolean | Index currently building |
is_queryable | boolean | Index ready for queries |
is_string | boolean | String-type index |
Example Queries
Section titled “Example Queries”-- All SAI indexesSELECT keyspace_name, index_name, table_name, column_name, is_queryable, is_buildingFROM system_views.sai_column_indexes;
-- Indexes currently buildingSELECT keyspace_name, index_name, table_name, column_nameFROM system_views.sai_column_indexesWHERE is_building = true;
-- Non-queryable indexes (building or failed)SELECT keyspace_name, index_name, is_buildingFROM system_views.sai_column_indexesWHERE is_queryable = false;
-- String indexes (check analyzer column for configured analyzers)SELECT keyspace_name, index_name, column_name, analyzerFROM system_views.sai_column_indexesWHERE is_string = true;Index States
Section titled “Index States”| is_queryable | is_building | State |
|---|---|---|
| true | false | Ready - normal operation |
| false | true | Building - queries may return partial results |
| false | false | Failed or not yet started |
| true | true | Queryable but rebuild in progress |
sai_sstable_indexes
Section titled “sai_sstable_indexes”Per-SSTable SAI index information.
Schema
Section titled “Schema”VIRTUAL TABLE system_views.sai_sstable_indexes ( keyspace_name text, index_name text, sstable_name text, table_name text, column_name text, cell_count bigint, min_row_id bigint, max_row_id bigint, start_token text, end_token text, format_version text, per_column_disk_size bigint, per_table_disk_size bigint, PRIMARY KEY (keyspace_name, index_name, sstable_name)) WITH CLUSTERING ORDER BY (index_name ASC, sstable_name ASC)| Column | Type | Description |
|---|---|---|
keyspace_name | text | Keyspace name |
index_name | text | Index name |
sstable_name | text | SSTable identifier |
table_name | text | Base table |
column_name | text | Indexed column |
cell_count | bigint | Number of indexed cells |
min_row_id | bigint | Minimum row ID in index |
max_row_id | bigint | Maximum row ID in index |
start_token | text | Start token range |
end_token | text | End token range |
format_version | text | Index format version |
per_column_disk_size | bigint | Index size for this column |
per_table_disk_size | bigint | Total index size for table |
Example Queries
Section titled “Example Queries”-- Index size per SSTableSELECT index_name, sstable_name, per_column_disk_size / 1048576 AS index_size_mb, cell_countFROM system_views.sai_sstable_indexesWHERE keyspace_name = 'my_keyspace';
-- SSTables with large indexes (> 100 MB)SELECT keyspace_name, index_name, sstable_name, per_column_disk_size / 1048576 AS size_mbFROM system_views.sai_sstable_indexesWHERE per_column_disk_size > 104857600;sai_sstable_index_segments
Section titled “sai_sstable_index_segments”Detailed segment information within SAI indexes. Useful for advanced debugging.
Schema
Section titled “Schema”VIRTUAL TABLE system_views.sai_sstable_index_segments ( keyspace_name text, index_name text, sstable_name text, segment_row_id_offset bigint, table_name text, column_name text, cell_count bigint, min_sstable_row_id bigint, max_sstable_row_id bigint, min_term text, max_term text, start_token text, end_token text, component_metadata map<text, map<text, text>>, PRIMARY KEY (keyspace_name, index_name, sstable_name, segment_row_id_offset)) WITH CLUSTERING ORDER BY (index_name ASC, sstable_name ASC, segment_row_id_offset ASC)| Column | Type | Description |
|---|---|---|
segment_row_id_offset | bigint | Segment offset within SSTable |
min_term | text | Minimum indexed term |
max_term | text | Maximum indexed term |
cell_count | bigint | Cells in this segment |
component_metadata | map | Detailed component info |
Example Queries
Section titled “Example Queries”-- Segment distribution for an indexSELECT sstable_name, segment_row_id_offset, cell_count, min_term, max_termFROM system_views.sai_sstable_index_segmentsWHERE keyspace_name = 'my_keyspace' AND index_name = 'my_index';
-- Term range analysisSELECT index_name, min_term, max_termFROM system_views.sai_sstable_index_segmentsWHERE keyspace_name = 'my_keyspace';Monitoring Use Cases
Section titled “Monitoring Use Cases”Index Build Monitoring
Section titled “Index Build Monitoring”-- Monitor index build progressSELECT keyspace_name, index_name, is_building, is_queryableFROM system_views.sai_column_indexesWHERE is_building = true;
-- Track build by watching SSTable coverageSELECT index_name, sstable_nameFROM system_views.sai_sstable_indexesWHERE keyspace_name = 'my_keyspace';Count distinct SSTables per index in application.
Index Size Analysis
Section titled “Index Size Analysis”-- SAI index sizes by tableSELECT table_name, per_column_disk_size / 1048576 AS index_mbFROM system_views.sai_sstable_indexesWHERE keyspace_name = 'my_keyspace';
-- Table sizes for comparisonSELECT table_name, mebibytes AS table_mbFROM system_views.disk_usageWHERE keyspace_name = 'my_keyspace';Sum index_mb per table in application and compare to table_mb to calculate overhead percentage.
Query Planning Insights
Section titled “Query Planning Insights”-- Term data for cardinality estimationSELECT index_name, column_name, min_termFROM system_views.sai_sstable_index_segmentsWHERE keyspace_name = 'my_keyspace';Count distinct terms per index/column in application for cardinality estimation.
Alerting Rules
Section titled “Alerting Rules”Index Not Queryable
Section titled “Index Not Queryable”-- Alert: Index not ready for queriesSELECT keyspace_name, index_name, is_buildingFROM system_views.sai_column_indexesWHERE is_queryable = false;Large Index Size
Section titled “Large Index Size”-- Get index sizes for alertingSELECT keyspace_name, index_name, per_column_disk_sizeFROM system_views.sai_sstable_indexes;Sum sizes per index in application. Alert when total exceeds 10 GB (10737418240 bytes).
Troubleshooting
Section titled “Troubleshooting”Index Build Stuck
Section titled “Index Build Stuck”Symptoms:
is_building = truefor extended periodis_queryable = false
Investigation:
-- Check indexed SSTablesSELECT sstable_nameFROM system_views.sai_sstable_indexesWHERE index_name = 'problematic_index';Count results in application to see how many SSTables are indexed.
Resolution:
- Check compaction status (builds happen during compaction)
- Review logs for errors
- Consider dropping and recreating the index
Partial Query Results
Section titled “Partial Query Results”Symptoms:
- Queries return fewer results than expected
is_queryable = truebutis_building = true
Explanation: During index build, queries only search already-indexed SSTables.
-- Check build progressSELECT index_name, is_queryable, is_buildingFROM system_views.sai_column_indexesWHERE keyspace_name = 'my_keyspace';High Index Overhead
Section titled “High Index Overhead”Symptoms:
- Index size approaching or exceeding table size
Investigation:
-- Index to data ratioSELECT index_name, per_column_disk_size / 1048576 AS index_mbFROM system_views.sai_sstable_indexesWHERE keyspace_name = 'my_keyspace';Sum index_mb per index in application and compare to table size from disk_usage.
Resolution:
- Review if index is needed
- Consider more selective indexing
- Evaluate alternative data models
Related Documentation
Section titled “Related Documentation”- Virtual Tables Overview - Introduction to virtual tables
- SAI Indexing - SAI index creation and usage
- Storage Tables - Disk usage monitoring