apache/cassandra · error · InvalidRequestException

Cannot execute this query as it might involve data…

Error message

Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING

What it means

Cassandra refuses queries whose restrictions would require scanning and filtering non-key rows without an index, because performance is unpredictable. When non-primary-key column restrictions exist, no queriable index covers them, and ALLOW FILTERING was not specified, StatementRestrictions throws this error.

Solutions

  1. Create an index on the filtered column: CREATE INDEX / CREATE CUSTOM INDEX ... USING 'StorageAttachedIndex'
  2. Denormalize: add the column to the primary key in a query table
  3. Append ALLOW FILTERING if the filtered dataset is provably small and performance is acceptable
  4. Use a separate search system (e.g. SAI + vector or external index) for high-cardinality filters

Example fix

// before
SELECT * FROM users WHERE email = 'a@b.com';
// after
CREATE CUSTOM INDEX users_email_idx ON users (email) USING 'StorageAttachedIndex';
SELECT * FROM users WHERE email = 'a@b.com';
Defensive patterns

Strategy: validation

Validate before calling

// Check every WHERE column is part of the primary key or has an index before executing;
// consult system_schema.indexes for the table.

Try / catch

catch (InvalidRequestException e) {
  if (e.getMessage().contains("ALLOW FILTERING")) {
    // create index or rewrite query; do not blindly append ALLOW FILTERING
  }
}

Prevention

When it happens

Trigger: SELECT * FROM t WHERE regular_col = 'x' with no index on regular_col and no ALLOW FILTERING; also clustering-column slices in statements that don't allow them without filtering.

Common situations: New developers querying by non-key columns as if it were SQL; schema changes that dropped an index the query relied on; ad-hoc debugging queries in cqlsh.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java:377

            else
            {
                // We do not support indexed vector restrictions that are not part of an ANN ordering
                Optional<ColumnMetadata> vectorColumn = nonPrimaryKeyRestrictions.columns()
                                                                                 .stream()
                                                                                 .filter(c -> c.type.isVector())
                                                                                 .findFirst();
                if (vectorColumn.isPresent() && indexRegistry.listIndexes().stream().anyMatch(i -> i.dependsOn(vectorColumn.get())))
                    throw invalidRequest(StatementRestrictions.VECTOR_INDEXES_ANN_ONLY_MESSAGE);
            }

            if (hasQueriableIndex)
            {
                usesSecondaryIndexing = true;
            }
            else
            {
                if (!allowFiltering && requiresAllowFilteringIfNotSpecified(table, false))
                    throw invalidRequest(allowFilteringMessage(state));
            }

            filterRestrictions.add(nonPrimaryKeyRestrictions);
        }

        if (usesSecondaryIndexing)
            validateSecondaryIndexSelections();
    }

    public static boolean requiresAllowFilteringIfNotSpecified(TableMetadata metadata, boolean isPrimaryKey)
    {
        if (!metadata.isVirtual())
            return true;

        VirtualTable tableNullable = VirtualKeyspaceRegistry.instance.getTableNullable(metadata.id);
        assert tableNullable != null;
        return isPrimaryKey ? !tableNullable.allowFilteringPrimaryKeysImplicitly() : !tableNullable.allowFilteringImplicitly();
    }

View on GitHub (pinned to 88fd0f6a0e)