{"record":{"id":"730a6c5dc14ea086","repo":"apache/cassandra","slug":"s-cannot-be-restricted-by-more-than-one-relation","errorCode":null,"errorMessage":"%s cannot be restricted by more than one relation if it includes an Equal","messagePattern":"(.+?) cannot be restricted by more than one relation if it includes an Equal","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java","lineNumber":180,"sourceCode":"                throw invalidRequest(\"More than one restriction was found for the start bound on %s\",\n                                     toCQLString(getColumnsInCommons(restriction, other)));\n            }\n\n            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     */","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java#L162-L198","documentation":"When a column is restricted by more than one relation, checkOperator() rejects the merge if any of them is an equality (or the column is restricted at token level). Multiple relations may only refine an inequality; an EQ plus anything else is contradictory or redundant, so it fails validation.","triggerScenarios":"Queries like WHERE pk = 1 AND pk = 2, or a column appearing in both an EQ and a token/INEQ restriction merged through MergedRestriction.validate().","commonSituations":"Dynamically generated WHERE clauses where the same column is added twice (once as filter, once as key lookup); duplicated query parameters in an application layer.","solutions":["Remove the redundant/contradictory duplicate restriction","Use IN for multiple values: WHERE pk IN (1, 2) instead of pk = 1 AND pk = 2","Deduplicate predicates by column name in query-building code"],"exampleFix":"// before\nSELECT * FROM users WHERE id = 1 AND id = 2;\n// after\nSELECT * FROM users WHERE id IN (1, 2);","handlingStrategy":"validation","validationCode":"const eqCount = predicates.filter(p => p.column === col && p.op === '=').length;\nif (eqCount > 1) throw new Error('Column ' + col + ' restricted by more than one relation including EQ');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict each column exactly once","Use IN instead of repeated EQ predicates","Deduplicate predicates by column in query-assembly code"],"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"}