{"record":{"id":"9dd64fd2c8813197","repo":"apache/cassandra","slug":"duplicate-index-name-s-in-keyspace-s","errorCode":null,"errorMessage":"Duplicate index name %s in keyspace %s","messagePattern":"Duplicate index name (.+?) in keyspace (.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/schema/KeyspaceMetadata.java","lineNumber":423,"sourceCode":"        StringBuilder result = new StringBuilder(cqlString);\n        SchemaDescriptionsUtil.appendCommentOnKeyspace(result, this);\n        SchemaDescriptionsUtil.appendSecurityLabelOnKeyspace(result, this);\n        return result.toString();\n    }\n\n    public void validate(ClusterMetadata metadata)\n    {\n        validateKeyspaceName(name, ConfigurationException::new);\n        params.validate(name, null, metadata);\n        tablesAndViews().forEach(TableMetadata::validate);\n\n        Set<String> indexNames = new HashSet<>();\n        for (TableMetadata table : tables)\n        {\n            for (IndexMetadata index : table.indexes)\n            {\n                if (indexNames.contains(index.name))\n                    throw new ConfigurationException(format(\"Duplicate index name %s in keyspace %s\", index.name, name));\n\n                indexNames.add(index.name);\n            }\n        }\n    }\n\n    static Optional<KeyspaceDiff> diff(KeyspaceMetadata before, KeyspaceMetadata after)\n    {\n        return KeyspaceDiff.diff(before, after);\n    }\n\n    public static final class KeyspaceDiff\n    {\n        public final KeyspaceMetadata before;\n        public final KeyspaceMetadata after;\n\n        public final TablesDiff tables;\n        public final ViewsDiff views;","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/schema/KeyspaceMetadata.java#L405-L441","documentation":"Thrown from KeyspaceMetadata.validate when two or more tables within the same keyspace contain indexes with the same name. Cassandra requires index names to be unique keyspace-wide, so schema announcements (announceNewKeyspace/announceKeyspaceUpdate) fail with a ConfigurationException.","triggerScenarios":"Creating a schema (loading a snapshot schema, applying a DDL script, or programmatic schema construction) where two tables in keyspace K each define an index named 'idx_x'; validate iterates all tables' indexes and detects the duplicate before announcing the keyspace.","commonSituations":"Hand-written CQL migration scripts reusing a name like 'idx_name' across tables, programmatic schema builders generating default index names, restoring a hand-edited schema file, ORMs that name indexes per-entity without keyspace scoping.","solutions":["Rename one of the indexes so names are unique within the keyspace (e.g. prefix with table name: tbl1_col_idx).","Find the offenders: SELECT keyspace_name, table_name, index_name FROM system_schema.indexes WHERE keyspace_name='ks' and look for duplicated names.","If generated programmatically, make your naming scheme include the table name to guarantee uniqueness."],"exampleFix":"// before\nCREATE INDEX idx_user ON ks.users (email);\nCREATE INDEX idx_user ON ks.orders (user_email); // duplicate in ks\n// after\nCREATE INDEX users_email_idx ON ks.users (email);\nCREATE INDEX orders_user_email_idx ON ks.orders (user_email);","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (String idx : allIndexNamesInKeyspace(\"ks\")) if (!seen.add(idx)) throw new IllegalStateException(\"Duplicate index name: \" + idx);","typeGuard":null,"tryCatchPattern":"try { keyspaceMetadata.validate(); } catch (ConfigurationException e) { if (e.getMessage().startsWith(\"Duplicate index name\")) renameIndexAndRetry(); else throw e; }","preventionTips":["Adopt a naming convention that embeds the table name: <table>_<column>_idx.","Before applying DDL scripts, run SELECT index_name FROM system_schema.indexes WHERE keyspace_name = 'ks'.","Never reuse bare names like 'idx1' across tables in the same keyspace."],"tags":["cassandra","schema","index","naming-conflict"],"backgroundTag":"conflicting-config-options","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"}