{"record":{"id":"3a2fb7ae87ba48c1","repo":"apache/cassandra","slug":"there-can-not-be-more-than-2-constraints-not-incl","errorCode":null,"errorMessage":"There can not be more than 2 constraints (not including non-equal relations) on a column '%s' but you have specified %s","messagePattern":"There can not be more than 2 constraints \\(not including non-equal relations\\) on a column '(.+?)' but you have specified (.+?)","errorType":"validation","errorClass":"InvalidConstraintDefinitionException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/constraints/AbstractFunctionSatisfiabilityChecker.java","lineNumber":102,"sourceCode":"                                                                      constraint.relationType(),\n                                                                      constraint.getSupportedOperators()));\n        }\n    }\n\n    /**\n     * Checks if there are no duplicate constraints having same operator.\n     *\n     * @param columnMetadata      medata of a column\n     * @param filteredConstraints pair of all constraints and all constraints having not-equal operator\n     */\n    private void checkNumberOfConstraints(ColumnMetadata columnMetadata, Pair<List<CONSTRAINT_TYPE>, List<CONSTRAINT_TYPE>> filteredConstraints)\n    {\n        List<? extends AbstractFunctionConstraint<CONSTRAINT_TYPE>> allConstraints = filteredConstraints.left;\n        List<? extends AbstractFunctionConstraint<CONSTRAINT_TYPE>> notEqualConstraints = filteredConstraints.right;\n\n        if ((allConstraints.size() - notEqualConstraints.size() > 2))\n        {\n            throw new InvalidConstraintDefinitionException(format(\"There can not be more than 2 constraints (not including non-equal relations) on a column '%s' but you have specified %s\",\n                                                                  columnMetadata.name,\n                                                                  allConstraints.size()));\n        }\n\n        if (notEqualConstraints.size() > 1)\n        {\n            Set<String> uniqueTerms = new TreeSet<>();\n            for (AbstractFunctionConstraint<CONSTRAINT_TYPE> notEqual : notEqualConstraints)\n            {\n                if (!uniqueTerms.add(notEqual.term()))\n                    throw new InvalidConstraintDefinitionException(format(\"There are duplicate constraint definitions on column '%s': %s\",\n                                                                          columnMetadata.name,\n                                                                          notEqual));\n            }\n        }\n    }\n\n    private void ensureSatisfiability(ColumnMetadata columnMetadata,","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/AbstractFunctionSatisfiabilityChecker.java#L84-L120","documentation":"AbstractFunctionSatisfiabilityChecker limits the number of constraints per column: at most 2 constraints excluding non-equal (NEQ) relations may be attached to a single column. Exceeding this limit makes satisfiability checking intractable/ambiguous, so checkNumberOfConstraints throws InvalidConstraintDefinitionException reporting the total constraint count.","triggerScenarios":"CREATE TABLE/ALTER TABLE attaching three or more equality/ordering CHECK constraints (excluding NEQ) to the same column.","commonSituations":"Gradually accumulating CHECK clauses on a column (min, max, equality, ranges); migrations from RDBMS schemas that allow arbitrary numbers of CHECK constraints.","solutions":["Reduce to at most two non-NEQ constraints per column, typically one lower and one upper bound.","Merge constraints logically, e.g. replace separate equality constraints with a single range or IN-style constraint.","If more bounds are needed, enforce extra rules at the application layer."],"exampleFix":"// before\nCREATE TABLE t (x int CHECK x > 0 AND x < 100 AND x = 42);\n// after\nCREATE TABLE t (x int CHECK x > 0 AND x < 100);","handlingStrategy":"validation","validationCode":"List<Constraint> perColumn = constraintsFor(column);\nlong nonNeq = perColumn.stream().filter(c -> c.op != Operator.NEQ).count();\nif (nonNeq > 2) throw new IllegalArgumentException(\"Max 2 non-NEQ constraints per column\");","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(schemaDdl);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"more than 2 constraints\")) {\n        log.error(\"Reduce constraint count on column: {}\", e.getMessage());\n    } else throw e;\n}","preventionTips":["Design schemas with at most lower/upper bound per constrained column","Track constraint counts in schema-migration tooling","Move extra business rules to the application layer"],"tags":["cassandra","cql","constraints","schema-definition"],"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"}