{"record":{"id":"196d8491a6cf49f8","repo":"apache/cassandra","slug":"keyspace-name-s-doesn-t-match-index-name-s","errorCode":null,"errorMessage":"Keyspace name '%s' doesn't match index name '%s'","messagePattern":"Keyspace name '(.+?)' doesn't match index name '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java","lineNumber":386,"sourceCode":"        {\n            this.tableName = tableName;\n            this.indexName = indexName;\n            this.rawIndexTargets = rawIndexTargets;\n            this.attrs = attrs;\n            this.ifNotExists = ifNotExists;\n        }\n\n        public CreateIndexStatement prepare(ClientState state)\n        {\n            String keyspaceName = tableName.hasKeyspace()\n                                ? tableName.getKeyspace()\n                                : indexName.hasKeyspace() ? indexName.getKeyspace() : state.getKeyspace();\n\n            if (tableName.hasKeyspace() && !keyspaceName.equals(tableName.getKeyspace()))\n                throw ire(KEYSPACE_DOES_NOT_MATCH_TABLE, keyspaceName, tableName);\n\n            if (indexName.hasKeyspace() && !keyspaceName.equals(indexName.getKeyspace()))\n                throw ire(KEYSPACE_DOES_NOT_MATCH_INDEX, keyspaceName, tableName);\n            \n            // Set the configured default 2i implementation if one isn't specified with USING:\n            if (attrs.customClass == null)\n            {\n                if (DatabaseDescriptor.getDefaultSecondaryIndexEnabled())\n                    attrs.customClass = DatabaseDescriptor.getDefaultSecondaryIndex();\n                else\n                    // However, operators may require an implementation be specified\n                    throw ire(MUST_SPECIFY_INDEX_IMPLEMENTATION);\n            }\n            \n            // If we explicitly specify the index type \"legacy_local_table\", we can just clear the custom class, and the\n            // non-custom 2i creation process will begin. Otherwise, if an index type has been specified with \n            // USING, make sure the appropriate custom index is created.\n            if (attrs.customClass != null)\n            {\n                if (!attrs.isCustom && attrs.customClass.equalsIgnoreCase(CassandraIndex.NAME))\n                    attrs.customClass = null;","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java#L368-L404","documentation":"Same keyspace-consistency check as for the table, but applied to the index name: when CREATE INDEX gives the index a keyspace qualifier, it must equal the resolved keyspace of the table, otherwise the statement is rejected.","triggerScenarios":"CREATE INDEX otherks.idx ON ks.t (col) — indexName.hasKeyspace() is true but its keyspace differs from the resolved keyspaceName of the table.","commonSituations":"Typos in the keyspace prefix on the index name; template-generated DDL where table and index keyspaces are substituted from different variables; multi-tenant scripts reusing one statement across keyspaces.","solutions":["Qualify index and table with the same keyspace: CREATE INDEX ks.idx ON ks.t (col).","Drop the keyspace qualifier from the index name and rely on the session keyspace.","Regenerate the DDL script with consistent keyspace substitution for both identifiers."],"exampleFix":"// before\nCREATE INDEX wrongks.idx ON ks.t (col);\n\n// after\nCREATE INDEX ks.idx ON ks.t (col);","handlingStrategy":"validation","validationCode":"if (indexName.includesKeyspace() && !indexName.getKeyspace().equals(resolveTableKeyspace(tableName))) throw new IllegalArgumentException(\"Index keyspace must match table keyspace\");","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (InvalidQueryException e) { if (e.getMessage().startsWith(\"Keyspace name\")) { /* align index-name qualifier with table keyspace */ } else throw e; }","preventionTips":["Generate index names without keyspace prefixes and rely on the table's keyspace","Review templated DDL for divergent keyspace variables","Validate identifier keyspaces in CI before applying migrations"],"tags":["cassandra","cql","keyspace","naming"],"backgroundTag":"invalid-argument-value","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"}