apache/cassandra · error · InvalidConstraintDefinitionException
There can not be more than 2 constraints (not including non-
Error message
There can not be more than 2 constraints (not including non-equal relations) on a column '%s' but you have specified %s
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/constraints/AbstractFunctionSatisfiabilityChecker.java:102
constraint.relationType(),
constraint.getSupportedOperators()));
}
}
/**
* Checks if there are no duplicate constraints having same operator.
*
* @param columnMetadata medata of a column
* @param filteredConstraints pair of all constraints and all constraints having not-equal operator
*/
private void checkNumberOfConstraints(ColumnMetadata columnMetadata, Pair<List<CONSTRAINT_TYPE>, List<CONSTRAINT_TYPE>> filteredConstraints)
{
List<? extends AbstractFunctionConstraint<CONSTRAINT_TYPE>> allConstraints = filteredConstraints.left;
List<? extends AbstractFunctionConstraint<CONSTRAINT_TYPE>> notEqualConstraints = filteredConstraints.right;
if ((allConstraints.size() - notEqualConstraints.size() > 2))
{
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",
columnMetadata.name,
allConstraints.size()));
}
if (notEqualConstraints.size() > 1)
{
Set<String> uniqueTerms = new TreeSet<>();
for (AbstractFunctionConstraint<CONSTRAINT_TYPE> notEqual : notEqualConstraints)
{
if (!uniqueTerms.add(notEqual.term()))
throw new InvalidConstraintDefinitionException(format("There are duplicate constraint definitions on column '%s': %s",
columnMetadata.name,
notEqual));
}
}
}
private void ensureSatisfiability(ColumnMetadata columnMetadata,View on GitHub (pinned to 88fd0f6a0e)
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.
Example fix
// before CREATE TABLE t (x int CHECK x > 0 AND x < 100 AND x = 42); // after CREATE TABLE t (x int CHECK x > 0 AND x < 100);
Defensive patterns
Strategy: validation
Validate before calling
List<Constraint> perColumn = constraintsFor(column);
long nonNeq = perColumn.stream().filter(c -> c.op != Operator.NEQ).count();
if (nonNeq > 2) throw new IllegalArgumentException("Max 2 non-NEQ constraints per column"); Try / catch
try {
session.execute(schemaDdl);
} catch (InvalidRequestException e) {
if (e.getMessage().contains("more than 2 constraints")) {
log.error("Reduce constraint count on column: {}", e.getMessage());
} else throw e;
} Prevention
- 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
When it happens
Trigger: CREATE TABLE/ALTER TABLE attaching three or more equality/ordering CHECK constraints (excluding NEQ) to the same column.
Common situations: Gradually accumulating CHECK clauses on a column (min, max, equality, ranges); migrations from RDBMS schemas that allow arbitrary numbers of CHECK constraints.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- %s constraint of relation '%s' is not supported. Only these
- There are duplicate constraint definitions on column '%s': %
- Constraints combination of %s is not supported: %s %s %s, %s
- There are duplicate constraint definitions on column '%s'.
- Constraints of %s are not satisfiable: %s %s %s, %s %s %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/3a2fb7ae87ba48c1.
Report an issue: GitHub.