{"record":{"id":"30a590f84acfd7e5","repo":"apache/cassandra","slug":"the-table-s-does-not-exist-in-the-keyspace-s","errorCode":null,"errorMessage":"The table '%s' does not exist in the keyspace '%s'.","messagePattern":"The table '(.+?)' does not exist in the keyspace '(.+?)'\\.","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java","lineNumber":166,"sourceCode":"    }\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)\n    {\n        List<SSTableReader> sstables = getSStables(metadata, range);\n        if (sstables.isEmpty())\n            return UnfilteredRowIterators.noRowsIterator(metadata, partitionKey, Rows.EMPTY_STATIC_ROW, DeletionTime.LIVE, false);","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java#L148-L184","documentation":"In PartitionKeyStatsTable.select(), after resolving the keyspace, the embedded table name is resolved via ksm.getTableOrViewNullable(table). A null result means the named table (or view) does not exist in that keyspace, and this InvalidRequestException is thrown with the TABLE_NOT_EXIST_ERROR template. This typically reflects stale stats entries or a misspelled table name.","triggerScenarios":"SELECT on system.partition_key_stats whose partition key embeds a table name that does not resolve in the keyspace — after DROP TABLE with lingering stats, a renamed table, or a typo in the key.","commonSituations":"Inspecting stats for a dropped/renamed table; stale partition_key_stats rows after schema changes; scripts with hand-crafted or copy-pasted keys.","solutions":["Check the exact table name in system_schema.tables and correct typos.","Skip stale entries whose table was dropped or renamed; they are leftovers.","Recreate the table if it was dropped unintentionally.","Regenerate partition key stats against the current schema."],"exampleFix":"// before\n-- key references 'myks.oldtable' which was renamed\n// after\n-- confirm name first:\nSELECT table_name FROM system_schema.tables WHERE keyspace_name = 'myks';","handlingStrategy":"validation","validationCode":"Row r = session.execute(\"SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?\", ks, tbl).one();\nif (r == null) throw new IllegalStateException(\"Table does not exist: \" + ks + \".\" + tbl);","typeGuard":null,"tryCatchPattern":"try { session.execute(statsQuery); }\ncatch (InvalidRequestException e) { if (e.getMessage().contains(\"does not exist in the keyspace\")) { /* skip stale stats entry */ } else throw e; }","preventionTips":["Cross-check table names against system_schema.tables before stats queries.","Re-generate or prune partition_key_stats entries after DROP/RENAME TABLE.","Build query keys from current schema metadata, not cached old names."],"tags":["virtual-table","schema","table-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-14T16:17:12.679Z"}