apache/cassandra · error · InvalidRequestException

The table '%s' does not exist in the keyspace '%s'.

Error message

The table '%s' does not exist in the keyspace '%s'.

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/db/virtual/PartitionKeyStatsTable.java:166

    }

    @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)
    {
        List<SSTableReader> sstables = getSStables(metadata, range);
        if (sstables.isEmpty())
            return UnfilteredRowIterators.noRowsIterator(metadata, partitionKey, Rows.EMPTY_STATIC_ROW, DeletionTime.LIVE, false);

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Check the exact table name in system_schema.tables and correct typos.
  2. Skip stale entries whose table was dropped or renamed; they are leftovers.
  3. Recreate the table if it was dropped unintentionally.
  4. Regenerate partition key stats against the current schema.

Example fix

// before
-- key references 'myks.oldtable' which was renamed
// after
-- confirm name first:
SELECT table_name FROM system_schema.tables WHERE keyspace_name = 'myks';
Defensive patterns

Strategy: validation

Validate before calling

Row r = session.execute("SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?", ks, tbl).one();
if (r == null) throw new IllegalStateException("Table does not exist: " + ks + "." + tbl);

Try / catch

try { session.execute(statsQuery); }
catch (InvalidRequestException e) { if (e.getMessage().contains("does not exist in the keyspace")) { /* skip stale stats entry */ } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Inspecting stats for a dropped/renamed table; stale partition_key_stats rows after schema changes; scripts with hand-crafted or copy-pasted 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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/30a590f84acfd7e5. Report an issue: GitHub.