apache/cassandra · error · InvalidRequestException

%s cannot be restricted by more than one relation if it incl

Error message

%s cannot be restricted by more than one relation if it includes a IN

What it means

Same merge rule as error 3208 but for IN: a column restricted by more than one relation may not include an IN restriction. IN plus another relation on the same column cannot be merged into a single slice, so validation throws.

Source

Thrown at src/java/org/apache/cassandra/cql3/restrictions/MergedRestriction.java:184

            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)));
            }
        }
    }

    private static void checkOperator(SimpleRestriction restriction)
    {
        if (restriction.isColumnLevel() || restriction.isOnToken())
        {
            if (restriction.isEQ())
                throw invalidRequest("%s cannot be restricted by more than one relation if it includes an Equal",
                                      toCQLString(restriction.columns()));

            if (restriction.isIN())
                throw invalidRequest("%s cannot be restricted by more than one relation if it includes a IN",
                                     toCQLString(restriction.columns()));
            if (restriction.isANN())
                throw invalidRequest("%s cannot be restricted by more than one relation in an ANN ordering",
                                     toCQLString(restriction.columns()));
        }
    }

    /**
     * Returns the columns that are specified within the 2 {@code Restrictions}.
     *
     * @param restriction the first restriction
     * @param other the other restriction
     * @return the columns that are specified within the 2 {@code Restrictions}.
     */
    private static Set<ColumnMetadata> getColumnsInCommons(Restriction restriction, Restriction other)
    {
        Set<ColumnMetadata> commons = new HashSet<>(restriction.columns());
        commons.retainAll(other.columns());

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Combine values into a single IN list and drop the other restriction
  2. Drop the extra relation or the IN so only one relation remains on the column
  3. Guard the query builder to replace, not append, restrictions for the same column

Example fix

// before
SELECT * FROM t WHERE id IN (1, 2) AND id > 0;
// after
SELECT * FROM t WHERE id IN (1, 2);
Defensive patterns

Strategy: validation

Validate before calling

const rels = predicates.filter(p => p.column === col);
if (rels.some(p => p.op === 'IN') && rels.length > 1) throw new Error('IN on ' + col + ' combined with another relation');

Prevention

When it happens

Trigger: WHERE col IN (1,2) combined with another relation on col (e.g. col = 1 or col > 0) on a column-level or token restriction; MergedRestriction.checkOperator() detects isIN().

Common situations: Application code appending an IN filter on top of an existing equality/range filter for the same column; ORMs that emit IN when given list parameters plus other operators.

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/a0fd5bced99b18ea. Report an issue: GitHub.