apache/cassandra · error · InvalidRequestException

Cannot index value of size

Error message

Cannot index value of size %d for index %s on %s(%s) (maximum allowed size=%d)

What it means

CassandraIndex.validateIndexedValue rejects any indexed value whose serialized size is >= FBUtilities.MAX_UNSIGNED_SHORT (65535 bytes), because secondary index entries store the value in a length-prefixed structure limited to unsigned-short size. Thrown as InvalidRequestException during statement validation before execution.

Solutions

  1. Remove the index from the large column and query it by other means
  2. Reduce the size of the indexed value (truncate, hash it, or store out-of-band and index a reference key)
  3. Use Storage-Attached Indexes (SAI), which have different size constraints, if appropriate
  4. Split the data into a separate table keyed by the large value

Example fix

// before
CREATE INDEX ON messages (payload); // payload blob often >64KB
// after
CREATE INDEX ON messages (payload_hash); // index a small derived key instead
Defensive patterns

Strategy: validation

Validate before calling

if (value != null && value.remaining() >= 65535) throw new IllegalArgumentException("Indexed value too large: " + value.remaining());

Try / catch

try { session.execute(insert); } catch (InvalidRequestException e) { if (e.getMessage().contains("Cannot index value of size")) { /* drop index or shrink value */ } else throw e; }

Prevention

When it happens

Trigger: INSERT/UPDATE where the value of an indexed column is >= 65535 bytes serialized (large text/blob, big frozen collection); validatePartitionKey, validateClusterings, or validateRows hit it depending on which part is indexed.

Common situations: Indexing a blob or free-text column that grows large in production; indexing frozen collections that exceed 64KB; writes that previously passed before data grew.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/index/internal/CassandraIndex.java:636

                if (data != null)
                {
                    for (Cell<?> cell : data)
                    {
                        validateIndexedValue(getIndexedValue(null, null, cell.path(), cell.buffer()));
                    }
                }
            }
            else
            {
                validateIndexedValue(getIndexedValue(null, null, row.getCell(indexedColumn)));
            }
        }
    }

    private void validateIndexedValue(ByteBuffer value)
    {
        if (value != null && value.remaining() >= FBUtilities.MAX_UNSIGNED_SHORT)
            throw new InvalidRequestException(String.format(
                                                           "Cannot index value of size %d for index %s on %s(%s) (maximum allowed size=%d)",
                                                           value.remaining(),
                                                           metadata.name,
                                                           baseCfs.metadata,
                                                           indexedColumn.name.toString(),
                                                           FBUtilities.MAX_UNSIGNED_SHORT));
    }

    private ByteBuffer getIndexedValue(ByteBuffer rowKey,
                                       Clustering<?> clustering,
                                       Cell<?> cell)
    {
        return getIndexedValue(rowKey,
                               clustering,
                               cell == null ? null : cell.path(),
                               cell == null ? null : cell.buffer()
        );
    }

View on GitHub (pinned to 88fd0f6a0e)