{"record":{"id":"ed807d0bd8cf1cad","repo":"apache/cassandra","slug":"indexes-cannot-be-both-included-and-excluded","errorCode":null,"errorMessage":"Indexes cannot be both included and excluded: ","messagePattern":"Indexes cannot be both included and excluded: ","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/filter/IndexHints.java","lineNumber":394,"sourceCode":"                                          IndexRegistry indexRegistry)\n    {\n        if (included != null && included.size() > maxIncludedOrExcludedIndexCount())\n            throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + included.size());\n\n        if (excluded != null && excluded.size() > maxIncludedOrExcludedIndexCount())\n            throw new InvalidRequestException(TOO_MANY_INDEXES_ERROR + excluded.size());\n\n        IndexHints hints = IndexHints.create(fetchIndexes(included, table, indexRegistry),\n                                             fetchIndexes(excluded, table, indexRegistry));\n\n        if (hints == IndexHints.NONE)\n            return hints;\n\n        // Ensure that no index is both included and excluded\n        Set<IndexMetadata> conflictingIndexes = Sets.intersection(hints.included, hints.excluded);\n        if (!conflictingIndexes.isEmpty())\n        {\n            throw new InvalidRequestException(CONFLICTING_INDEXES_ERROR + IndexMetadata.joinNames(conflictingIndexes));\n        }\n\n        // Ensure that all nodes in the cluster are in a version that supports index hints, including this one\n        Set<InetAddressAndPort> badNodes = MessagingService.instance().endpointsWithConnectionsOnVersionBelow(MessagingService.VERSION_60);\n        if (MessagingService.current_version < MessagingService.VERSION_60)\n            badNodes.add(FBUtilities.getBroadcastAddressAndPort());\n        if (!badNodes.isEmpty())\n            throw new InvalidRequestException(\"Index hints are not supported in clusters below 14.\");\n\n        return hints;\n    }\n\n    private static int maxIncludedOrExcludedIndexCount()\n    {\n        int guardrail = DatabaseDescriptor.getSecondaryIndexesPerTableFailThreshold();\n\n        // If no guardrail is configured, use a value that safely fits in a single byte for serialization:\n        return guardrail > 0 ? guardrail : 128;","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/filter/IndexHints.java#L376-L412","documentation":"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.","triggerScenarios":"A query that includes and excludes the same qualified index name — e.g. hint construction code merging user-provided include/exclude lists that overlap.","commonSituations":"Client-side query builders concatenating hints from different sources; user typos; scripts adding exclusions without checking existing includes.","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"],"exampleFix":"// before\nSELECT * FROM t WHERE ... ; -- INCLUDE INDEXES (idx_a) EXCLUDE INDEXES (idx_a)\n// after\nSELECT * FROM t WHERE ... ; -- INCLUDE INDEXES (idx_a)","handlingStrategy":"validation","validationCode":"Set<String> conflict = Sets.intersection(includedNames, excludedNames); if (!conflict.isEmpty()) throw new IllegalArgumentException(\"Conflicting hints: \" + conflict);","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"both included and excluded\")) fixHintListsAndRetry(); }","preventionTips":["Deduplicate include/exclude lists before building the query","Centralize hint construction so overlaps are impossible","Validate client-side with set intersection before execution"],"tags":["cassandra","index-hints","contradiction","cql"],"backgroundTag":"conflicting-config-options","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"}