apache/cassandra · error · InvalidRequestException
The keyspace '%s' does not exist.
Error message
The keyspace '%s' does not exist.
What it means
The partition_key_stats virtual table encodes the keyspace and table name of each partition's owning table inside its partition key. In select(), the key is split and the named keyspace is looked up in Schema; if Schema.instance.getKeyspaceMetadata returns null the keyspace does not exist (anymore) and this InvalidRequestException is thrown using the KEYSPACE_NOT_EXIST_ERROR template.
Source
Thrown at src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java:162
.addRegularColumn(COLUMN_SSTABLES, CounterColumnType.instance)
.build();
sizeEstimateColumn = metadata.regularColumns().getSimple(0);
sstablesColumn = metadata.regularColumns().getSimple(1);
}
@Override
public UnfilteredPartitionIterator select(DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits)
{
if (clusteringIndexFilter.isReversed())
throw new InvalidRequestException(REVERSED_QUERY_ERROR);
ByteBuffer[] key = ((CompositeType) this.metadata.partitionKeyType).split(partitionKey.getKey());
String keyspace = UTF8Type.instance.getString(key[0]);
String table = UTF8Type.instance.getString(key[1]);
KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace);
if (ksm == null)
throw invalidRequest(KEYSPACE_NOT_EXIST_ERROR, keyspace);
TableMetadata metadata = ksm.getTableOrViewNullable(table);
if (metadata == null)
throw invalidRequest(TABLE_NOT_EXIST_ERROR, table, keyspace);
if (!metadata.partitioner.supportsSplitting())
throw invalidRequest(PARTITIONER_NOT_SUPPORTED, metadata.partitioner.getClass().getName(), table, keyspace);
AbstractBounds<PartitionPosition> range = getBounds(metadata, clusteringIndexFilter, rowFilter);
return new SingletonUnfilteredPartitionIterator(select(partitionKey, metadata, clusteringIndexFilter, range));
}
private List<SSTableReader> getSStables(TableMetadata metadata, AbstractBounds<PartitionPosition> range)
{
return Lists.newArrayList(ColumnFamilyStore.getIfExists(metadata).getTracker().getView().liveSSTablesInBounds(range.left, range.right));
}
private UnfilteredRowIterator select(DecoratedKey partitionKey, TableMetadata metadata, ClusteringIndexFilter clusteringIndexFilter, AbstractBounds<PartitionPosition> range)View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Verify the keyspace name with `DESCRIBE KEYSPACES` / system_schema.keyspaces and correct typos.
- Recreate the keyspace if it was dropped unintentionally.
- Ignore/skip stale partition_key_stats entries for dropped keyspaces; they are artifacts.
- Re-run the stats tooling so the table is repopulated with current keyspaces.
Example fix
// before SELECT * FROM system.partition_key_stats WHERE partition_key = ... FOR keyspace 'ks_old' (dropped) // after -- confirm it exists first: SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = 'myks';
Defensive patterns
Strategy: validation
Validate before calling
Row r = session.execute("SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?", ks).one();
if (r == null) throw new IllegalStateException("Keyspace does not exist: " + ks); Try / catch
try { session.execute("SELECT * FROM system.partition_key_stats WHERE ...", ); }
catch (InvalidRequestException e) { if (e.getMessage().contains("does not exist")) { /* treat as stale entry, skip */ } else throw e; } Prevention
- Validate keyspace existence in system_schema before querying stats tables.
- Expect stale entries after DROP KEYSPACE and skip them defensively.
- Avoid hand-crafting partition keys for stats tables; derive them from current schema.
When it happens
Trigger: SELECT against system.partition_key_stats with a partition key whose embedded keyspace name no longer resolves — typically after the keyspace was dropped while stale stats entries remain, or a typo in the manually supplied key.
Common situations: Querying stats for a recently dropped keyspace; referencing leftover partition-key rows after DROP KEYSPACE before stats are cleaned up; scripts with hand-crafted partition keys.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Unknown keyspace: '" + keyspaceName + "'
- Unknown object type: '" + objectType + "'. Valid types are:
- The table '%s' does not exist in the keyspace '%s'.
- Operator %s not supported for txn_id
- Modification is not supported by table %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/472a23d53c5a9356.
Report an issue: GitHub.