{"record":{"id":"51c930188afc4ebe","repo":"apache/cassandra","slug":"secondary-indexes-are-not-supported-on-compact-val","errorCode":null,"errorMessage":"Secondary indexes are not supported on compact value column of COMPACT STORAGE tables","messagePattern":"Secondary indexes are not supported on compact value column of COMPACT STORAGE tables","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java","lineNumber":285,"sourceCode":"            if (column.type.isCollection())\n                throw ire(COLLECTIONS_WITH_DURATIONS_NOT_SUPPORTED);\n\n            if (column.type.isTuple())\n                throw ire(TUPLES_WITH_DURATIONS_NOT_SUPPORTED);\n\n            if (column.type.isUDT())\n                throw  ire(UDTS_WITH_DURATIONS_NOT_SUPPORTED);\n\n            throw ire(DURATIONS_NOT_SUPPORTED);\n        }\n\n        if (table.isCompactTable())\n        {\n            TableMetadata.CompactTableMetadata compactTable = (TableMetadata.CompactTableMetadata) table;\n            if (column.isPrimaryKeyColumn())\n                throw new InvalidRequestException(PRIMARY_KEY_IN_COMPACT_STORAGE);\n            if (compactTable.compactValueColumn.equals(column))\n                throw new InvalidRequestException(COMPACT_COLUMN_IN_COMPACT_STORAGE);\n        }\n\n        if (column.isPartitionKey() && table.partitionKeyColumns().size() == 1)\n            throw ire(ONLY_PARTITION_KEY, column);\n\n        if (target.type == Type.FULL && isNonSAIIndex && (!baseType.isCollection() || column.type.isMultiCell()))\n            throw ire(FULL_ON_FROZEN_COLLECTIONS);\n\n        if (!baseType.isCollection() && target.type != Type.SIMPLE)\n            throw ire(NON_COLLECTION_SIMPLE_INDEX, target.type, column);\n\n        // Frozen collections are only supported with SAI indexes.\n        if (isNonSAIIndex && baseType.isCollection() && !column.type.isMultiCell())\n        {\n            if (target.type == Type.VALUES || target.type == Type.KEYS || target.type == Type.KEYS_AND_VALUES)\n            {\n                throw ire(CREATE_ON_FROZEN_COLUMN, target.type.toString(), column.name, column.name);\n            }","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java#L267-L303","documentation":"For COMPACT STORAGE tables the single hidden/compact value column holds the thrift-encoded cell value; it is not indexable by a legacy secondary index. When the index target equals `compactTable.compactValueColumn`, InvalidRequestException (COMPACT_COLUMN_IN_COMPACT_STORAGE) is thrown.","triggerScenarios":"`CREATE INDEX ... ON compact_table (value_column)` where the named column is the compact value column of a `WITH COMPACT STORAGE` table (the column written via thrift `insert` or exposed as the single non-key column).","commonSituations":"Legacy thrift tables where users attempt to index the sole value column to speed up lookups; automated DDL generated from thrift metadata.","solutions":["Drop COMPACT STORAGE (`ALTER TABLE ... DROP COMPACT STORAGE`) so the value becomes a normal column, then create the index.","Restructure queries to filter by primary key, or migrate the data into a modern table where the value column is a regular column and can be indexed.","Consider SAI (if the version supports it) after dropping compact storage."],"exampleFix":"-- before\nCREATE INDEX ON legacy_compact (value); -- value is the compact value column\n\n-- after\nALTER TABLE legacy_compact DROP COMPACT STORAGE;\nCREATE INDEX ON legacy_compact (value);","handlingStrategy":"validation","validationCode":"TableMetadata t = session.getCluster().getMetadata().getKeyspace(\"ks\").getTable(\"t\");\nif (t.getOptions().getCompactStorage())\n    throw new IllegalStateException(\"create index on compact value column not supported; DROP COMPACT STORAGE first\");","typeGuard":null,"tryCatchPattern":"try { session.execute(createIndex); }\ncatch (InvalidQueryException e) {\n  if (e.getMessage().contains(\"compact value column\"))\n      throw new IllegalStateException(\"ALTER TABLE ... DROP COMPACT STORAGE, then index the column\", e);\n  throw e;\n}","preventionTips":["Identify the compact value column (single non-key column in thrift tables) before writing index DDL","Treat COMPACT STORAGE tables as indexing-hostile; migrate them first","Never auto-generate indexes for every column of legacy compact tables"],"tags":["cassandra","compact-storage","secondary-index","thrift"],"backgroundTag":"unsupported-operation","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"}