{"record":{"id":"a0fd5bced99b18ea","repo":"apache/cassandra","slug":"s-cannot-be-restricted-by-more-than-one-relation-a0fd5b","errorCode":null,"errorMessage":"%s cannot be restricted by more than one relation if it includes a IN","messagePattern":"(.+?) cannot be restricted by more than one relation if it includes a IN","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java","lineNumber":184,"sourceCode":"            if ((restriction.operator() == Operator.LT || restriction.operator() == Operator.LTE || restriction.operator() == Operator.BETWEEN) &&\n                    (other.operator() == Operator.LT || other.operator() == Operator.LTE || other.operator() == Operator.BETWEEN))\n            {\n                throw invalidRequest(\"More than one restriction was found for the end bound on %s\",\n                                     toCQLString(getColumnsInCommons(restriction, other)));\n            }\n        }\n    }\n\n    private static void checkOperator(SimpleRestriction restriction)\n    {\n        if (restriction.isColumnLevel() || restriction.isOnToken())\n        {\n            if (restriction.isEQ())\n                throw invalidRequest(\"%s cannot be restricted by more than one relation if it includes an Equal\",\n                                      toCQLString(restriction.columns()));\n\n            if (restriction.isIN())\n                throw invalidRequest(\"%s cannot be restricted by more than one relation if it includes a IN\",\n                                     toCQLString(restriction.columns()));\n            if (restriction.isANN())\n                throw invalidRequest(\"%s cannot be restricted by more than one relation in an ANN ordering\",\n                                     toCQLString(restriction.columns()));\n        }\n    }\n\n    /**\n     * Returns the columns that are specified within the 2 {@code Restrictions}.\n     *\n     * @param restriction the first restriction\n     * @param other the other restriction\n     * @return the columns that are specified within the 2 {@code Restrictions}.\n     */\n    private static Set<ColumnMetadata> getColumnsInCommons(Restriction restriction, Restriction other)\n    {\n        Set<ColumnMetadata> commons = new HashSet<>(restriction.columns());\n        commons.retainAll(other.columns());","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java#L166-L202","documentation":"Same merge rule as error 3208 but for IN: a column restricted by more than one relation may not include an IN restriction. IN plus another relation on the same column cannot be merged into a single slice, so validation throws.","triggerScenarios":"WHERE col IN (1,2) combined with another relation on col (e.g. col = 1 or col > 0) on a column-level or token restriction; MergedRestriction.checkOperator() detects isIN().","commonSituations":"Application code appending an IN filter on top of an existing equality/range filter for the same column; ORMs that emit IN when given list parameters plus other operators.","solutions":["Combine values into a single IN list and drop the other restriction","Drop the extra relation or the IN so only one relation remains on the column","Guard the query builder to replace, not append, restrictions for the same column"],"exampleFix":"// before\nSELECT * FROM t WHERE id IN (1, 2) AND id > 0;\n// after\nSELECT * FROM t WHERE id IN (1, 2);","handlingStrategy":"validation","validationCode":"const rels = predicates.filter(p => p.column === col);\nif (rels.some(p => p.op === 'IN') && rels.length > 1) throw new Error('IN on ' + col + ' combined with another relation');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When a column gets an IN, never add further relations to it","Merge all values into a single IN list at the builder level"],"tags":["cql","query-validation","duplicate-restrictions"],"backgroundTag":"invalid-query-parameter","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}