{"record":{"id":"130c77b906e3ad58","repo":"apache/cassandra","slug":"table-s-doesn-t-have-an-index-named-s","errorCode":null,"errorMessage":"Table %s doesn't have an index named %s","messagePattern":"Table (.+?) doesn't have an index named (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/filter/IndexHints.java","lineNumber":441,"sourceCode":"        {\n            IndexMetadata index = fetchIndex(indexName, table, indexRegistry);\n            indexes.add(index);\n        }\n\n        return indexes;\n    }\n\n    private static IndexMetadata fetchIndex(QualifiedName indexName, TableMetadata table, IndexRegistry indexRegistry)\n    {\n        String name = indexName.getName();\n        String keyspace = indexName.getKeyspace();\n\n        if (keyspace != null && !table.keyspace.equals(keyspace))\n            throw new InvalidRequestException(format(WRONG_KEYSPACE_ERROR, indexName));\n\n        Index index = indexRegistry.getIndexByName(name);\n        if (index == null)\n            throw new InvalidRequestException(format(MISSING_INDEX_ERROR, table.name, name));\n\n        return index.getIndexMetadata();\n    }\n\n    /**\n     * Returns a comparator of index query plans based on which one has the most included indexes, so it can be used to\n     * select the plans that satisfy the index hints first, and the plans that are closest to satisfy them later.\n     *\n     * @return a comparator of index query plans based on which one has the most included indexes\n     */\n    public Comparator<Index.QueryPlan> comparator()\n    {\n        return Comparator.comparing(plan -> Sets.intersection(included, metadata(plan.getIndexes())).size());\n    }\n\n    @Override\n    public String toString()\n    {","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/filter/IndexHints.java#L423-L459","documentation":"Thrown as an InvalidRequestException when the index registry has no index registered under the given name for the queried table. Cassandra looks up the index by name in the table's IndexRegistry; if it is absent the hint cannot be resolved. Message reads 'Table %s doesn't have an index named %s'.","triggerScenarios":"SELECT ... USING INDEX idx_name FROM tbl where idx_name is not a defined index on tbl (typo, index dropped, or index on another table).","commonSituations":"Index was DROPped or renamed but old queries still reference it; schema drift between application code and database; referencing an index that exists on a different table; case-sensitivity mistakes with quoted vs unquoted identifiers.","solutions":["Verify the index exists with DESCRIBE TABLE or querying system_schema.indexes and correct the name in the query","Create the missing index with CREATE INDEX if it should exist","Remove the USING INDEX clause so the query no longer depends on a specific index"],"exampleFix":"// before\nSELECT * FROM users USING INDEX usr_email_idx;\n// after\nSELECT * FROM users USING INDEX users_email_idx;","handlingStrategy":"validation","validationCode":"boolean exists = systemSchemaIndexes.stream().anyMatch(i -> i.keyspace.equals(table.keyspace) && i.name.equals(indexName) && i.table.equals(table.name));\nif (!exists) throw new InvalidRequestException(\"Table \" + table.name + \" doesn't have an index named \" + indexName);","typeGuard":null,"tryCatchPattern":"try { session.execute(query); }\ncatch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"doesn't have an index named\")) { /* recreate index or drop hint */ }\n    else throw e;\n}","preventionTips":["Verify index existence via system_schema.indexes before emitting USING INDEX clauses","Track schema migrations in sync with application query code","Be careful with quoted vs unquoted identifier casing"],"tags":["cql","invalid-request","index"],"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-17T15:17:12.973Z"}