apache/cassandra · error · InvalidRequestException
Column "%s" cannot be restricted by two inequalities not sta
Error message
Column "%s" cannot be restricted by two inequalities not starting with the same column
What it means
Cassandra throws this when merging two simple restrictions on the same column family because two inequality (>, >=, BETWEEN) restrictions exist whose leading column differs. Clustering-column ranges must form a single contiguous prefix; inequalities starting at different columns would make the slice bounds ambiguous, so Cassandra rejects the query at validation time.
Source
Thrown at src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java:155
throw invalidRequest(Relation.FROZEN_MAP_ENTRY_PREDICATES_NOT_SUPPORTED, column.name);
}
}
throw invalidRequest("Collection column %s can only be restricted by CONTAINS, CONTAINS KEY, NOT_CONTAINS, NOT_CONTAINS_KEY" +
" or map-entry equality if it already restricted by one of those",
restriction.firstColumn().name);
}
if (restriction.isSlice() && other.isSlice())
{
ColumnMetadata firstColumn = restriction.firstColumn();
ColumnMetadata otherFirstColumn = other.firstColumn();
if (!firstColumn.equals(otherFirstColumn))
{
ColumnMetadata column = firstColumn.position() > otherFirstColumn.position() ? firstColumn
: otherFirstColumn;
throw invalidRequest("Column \"%s\" cannot be restricted by two inequalities not starting with the same column",
column.name);
}
if ((restriction.operator() == Operator.GT || restriction.operator() == Operator.GTE || restriction.operator() == Operator.BETWEEN) &&
(other.operator() == Operator.GT || other.operator() == Operator.GTE || other.operator() == Operator.BETWEEN))
{
throw invalidRequest("More than one restriction was found for the start bound on %s",
toCQLString(getColumnsInCommons(restriction, other)));
}
if ((restriction.operator() == Operator.LT || restriction.operator() == Operator.LTE || restriction.operator() == Operator.BETWEEN) &&
(other.operator() == Operator.LT || other.operator() == Operator.LTE || other.operator() == Operator.BETWEEN))
{
throw invalidRequest("More than one restriction was found for the end bound on %s",
toCQLString(getColumnsInCommons(restriction, other)));
}
}
}View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Restructure the query so only one clustering column carries an inequality and all preceding clustering columns use EQ restrictions
- Query without one of the inequality predicates and filter client-side
- Change the table's clustering order (WITH CLUSTERING ORDER BY) or data model so the range column is a single clustering column
- Use ALLOW FILTERING with a secondary index on the second column if the data set is small
Example fix
// before SELECT * FROM metrics WHERE day > '2026-01-01' AND hour >= 12; // after SELECT * FROM metrics WHERE day = '2026-01-01' AND hour >= 12; // or query one range column only: SELECT * FROM events WHERE ts > :start AND ts < :end;
Defensive patterns
Strategy: validation
Validate before calling
// client-side pre-check before sending CQL
const ineqCols = predicates.filter(p => ['>','>='].includes(p.op)).map(p => p.column);
if (new Set(ineqCols).size > 1) throw new Error('Only one clustering column may carry an inequality: ' + ineqCols); Prevention
- Give each clustering prefix segment at most one range predicate
- Use EQ for all clustering columns before the range column
- Model time ranges on a single clustering column
- Test dynamic query builders against Cassandra's clustering-prefix rules
When it happens
Trigger: Issuing a CQL SELECT with two inequality restrictions on different clustering columns of the same primary key, e.g. WHERE clustering1 > 5 AND clustering2 >= 2 — MergedRestriction.validate() detects firstColumn() != other.firstColumn() and rejects.
Common situations: Users coming from SQL expect per-column range predicates to work; modeling time-series data with two clustering columns (e.g. day > X AND hour > Y) and forgetting Cassandra's clustering-prefix rules.
Understand the failure class
Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.
Related errors
- PRIMARY KEY column "%s" cannot be restricted (preceding colu
- More than one restriction was found for the start bound on %
- More than one restriction was found for the end bound on %s
- %s cannot be restricted by more than one relation if it incl
- %s cannot be restricted by more than one relation if it incl
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/6e5c80a704c165ee.
Report an issue: GitHub.