{"record":{"id":"472a23d53c5a9356","repo":"apache/cassandra","slug":"the-keyspace-s-does-not-exist","errorCode":null,"errorMessage":"The keyspace '%s' does not exist.","messagePattern":"The keyspace '(.+?)' does not exist\\.","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java","lineNumber":162,"sourceCode":"                                     .addRegularColumn(COLUMN_SSTABLES, CounterColumnType.instance)\n                                     .build();\n        sizeEstimateColumn = metadata.regularColumns().getSimple(0);\n        sstablesColumn = metadata.regularColumns().getSimple(1);\n    }\n\n    @Override\n    public UnfilteredPartitionIterator select(DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits)\n    {\n        if (clusteringIndexFilter.isReversed())\n            throw new InvalidRequestException(REVERSED_QUERY_ERROR);\n\n        ByteBuffer[] key = ((CompositeType) this.metadata.partitionKeyType).split(partitionKey.getKey());\n        String keyspace = UTF8Type.instance.getString(key[0]);\n        String table = UTF8Type.instance.getString(key[1]);\n\n        KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(keyspace);\n        if (ksm == null)\n            throw invalidRequest(KEYSPACE_NOT_EXIST_ERROR, keyspace);\n\n        TableMetadata metadata = ksm.getTableOrViewNullable(table);\n        if (metadata == null)\n            throw invalidRequest(TABLE_NOT_EXIST_ERROR, table, keyspace);\n\n        if (!metadata.partitioner.supportsSplitting())\n            throw invalidRequest(PARTITIONER_NOT_SUPPORTED, metadata.partitioner.getClass().getName(), table, keyspace);\n\n        AbstractBounds<PartitionPosition> range = getBounds(metadata, clusteringIndexFilter, rowFilter);\n        return new SingletonUnfilteredPartitionIterator(select(partitionKey, metadata, clusteringIndexFilter, range));\n    }\n\n    private List<SSTableReader> getSStables(TableMetadata metadata, AbstractBounds<PartitionPosition> range)\n    {\n        return Lists.newArrayList(ColumnFamilyStore.getIfExists(metadata).getTracker().getView().liveSSTablesInBounds(range.left, range.right));\n    }\n\n    private UnfilteredRowIterator select(DecoratedKey partitionKey, TableMetadata metadata, ClusteringIndexFilter clusteringIndexFilter, AbstractBounds<PartitionPosition> range)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java#L144-L180","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSELECT * FROM system.partition_key_stats WHERE partition_key = ... FOR keyspace 'ks_old' (dropped)\n// after\n-- confirm it exists first:\nSELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = 'myks';","handlingStrategy":"validation","validationCode":"Row r = session.execute(\"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = ?\", ks).one();\nif (r == null) throw new IllegalStateException(\"Keyspace does not exist: \" + ks);","typeGuard":null,"tryCatchPattern":"try { session.execute(\"SELECT * FROM system.partition_key_stats WHERE ...\", ); }\ncatch (InvalidRequestException e) { if (e.getMessage().contains(\"does not exist\")) { /* treat as stale entry, skip */ } else throw e; }","preventionTips":["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."],"tags":["virtual-table","schema","keyspace-not-found","invalid-request"],"backgroundTag":"resource-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}