apache/cassandra · error · InvalidRequestException
Indexes cannot be both included and excluded:
Error message
Indexes cannot be both included and excluded:
What it means
InvalidRequestException from IndexHints.fromCQLNames when one or more indexes appear in both the included and excluded sets. Such hints are contradictory, so the request is rejected, listing the conflicting index names.
Source
Thrown at src/java/org/apache/cassandra/db/filter/IndexHints.java:394
IndexRegistry indexRegistry)
{
if (included != null && included.size() > maxIncludedOrExcludedIndexCount())
throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + included.size());
if (excluded != null && excluded.size() > maxIncludedOrExcludedIndexCount())
throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + excluded.size());
IndexHints hints = IndexHints.create(fetchIndexes(included, table, indexRegistry),
fetchIndexes(excluded, table, indexRegistry));
if (hints == IndexHints.NONE)
return hints;
// Ensure that no index is both included and excluded
Set<IndexMetadata> conflictingIndexes = Sets.intersection(hints.included, hints.excluded);
if (!conflictingIndexes.isEmpty())
{
throw new InvalidRequestException(CONFLICTING_INDEXES_ERROR + IndexMetadata.joinNames(conflictingIndexes));
}
// Ensure that all nodes in the cluster are in a version that supports index hints, including this one
Set<InetAddressAndPort> badNodes = MessagingService.instance().endpointsWithConnectionsOnVersionBelow(MessagingService.VERSION_60);
if (MessagingService.current_version < MessagingService.VERSION_60)
badNodes.add(FBUtilities.getBroadcastAddressAndPort());
if (!badNodes.isEmpty())
throw new InvalidRequestException("Index hints are not supported in clusters below 14.");
return hints;
}
private static int maxIncludedOrExcludedIndexCount()
{
int guardrail = DatabaseDescriptor.getSecondaryIndexesPerTableFailThreshold();
// If no guardrail is configured, use a value that safely fits in a single byte for serialization:
return guardrail > 0 ? guardrail : 128;View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Remove the conflicting index from either the included or excluded set
- Pre-filter intersection of include/exclude names in client code before issuing the query
- Decide which behavior is intended for that index and keep only one hint
Example fix
// before SELECT * FROM t WHERE ... ; -- INCLUDE INDEXES (idx_a) EXCLUDE INDEXES (idx_a) // after SELECT * FROM t WHERE ... ; -- INCLUDE INDEXES (idx_a)
Defensive patterns
Strategy: validation
Validate before calling
Set<String> conflict = Sets.intersection(includedNames, excludedNames); if (!conflict.isEmpty()) throw new IllegalArgumentException("Conflicting hints: " + conflict); Try / catch
try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains("both included and excluded")) fixHintListsAndRetry(); } Prevention
- Deduplicate include/exclude lists before building the query
- Centralize hint construction so overlaps are impossible
- Validate client-side with set intersection before execution
When it happens
Trigger: A query that includes and excludes the same qualified index name — e.g. hint construction code merging user-provided include/exclude lists that overlap.
Common situations: Client-side query builders concatenating hints from different sources; user typos; scripts adding exclusions without checking existing includes.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- It's not possible to use all the specified included indexes
- Cannot have more than 'secondary_indexes_per_table_fail_thre
- category %s not found in %s
- GRANT operation is not supported by AllowAllAuthorizer
- REVOKE operation is not supported by AllowAllAuthorizer
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/ed807d0bd8cf1cad.
Report an issue: GitHub.