{"record":{"id":"6c906029bfdfbb34","repo":"apache/cassandra","slug":"s-cannot-be-restricted-by-more-than-one-relation-6c9060","errorCode":null,"errorMessage":"%s cannot be restricted by more than one relation in an ANN ordering","messagePattern":"(.+?) cannot be restricted by more than one relation in an ANN ordering","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java","lineNumber":187,"sourceCode":"                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());\n        return commons;\n    }\n","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java#L169-L205","documentation":"Cassandra rejects an ANN (approximate nearest neighbor) ORDER BY query when the ANN column has more than one restriction relation attached. ANN search requires exactly one ordering relation per restricted column, so MergedRestriction.checkOperator throws this InvalidRequest at query validation time before execution.","triggerScenarios":"Issuing a SELECT with 'ORDER BY col ANN OF [..]' where col is also restricted by multiple relations (e.g. merged from a multicolumn restriction or duplicate WHERE clauses on the same column).","commonSituations":"Building vector-search queries programmatically and appending duplicate relations on the vector column; combining a secondary restriction with ANN ordering in the same restriction set.","solutions":["Keep exactly one restriction relation on the ANN-ordered column","Move filtering of the vector column out of the ANN restriction set and use ALLOW FILTERING or a secondary index for other predicates","Rewrite the query so the vector column appears only in the ANN ORDER BY clause"],"exampleFix":"// before\nSELECT * FROM t WHERE v : [1,2] AND v : [1,2] ORDER BY v ANN OF [1,2];\n// after\nSELECT * FROM t WHERE id = 5 ORDER BY v ANN OF [1,2];","handlingStrategy":"validation","validationCode":"// client-side before building query\nif (restrictionsOn(annColumn).length > 1) throw new Error(\"ANN column must have exactly one relation\");","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) { if (e.getMessage().contains(\"ANN ordering\")) fixQueryPlan(); }","preventionTips":["Emit at most one relation per ANN-ordered column in query builders","Add a unit test asserting generated ANN queries validate on a real session","Keep filtering predicates on separate columns from the ANN ordering column"],"tags":["cql","ann","vector-search","query-validation"],"backgroundTag":"invalid-argument-value","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"}