apache/cassandra · error · InvalidRequestException
ANN ordering does not support any other ordering
Error message
ANN ordering does not support any other ordering
What it means
A single ANN ordering cannot be combined with any other ORDER BY expression (clustering order or another column ordering). When one non-clustered (ANN) ordering exists alongside other orderings, the statement is rejected.
Source
Thrown at src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java:553
/**
* This is a hack to push ordering down to indexes.
* Indexes are selected based on RowFilter only, so we need to turn orderings into restrictions
* so they end up in the row filter.
*
* @param orderings orderings from the select statement
* @return the {@link RestrictionSet} with the added orderings
*/
private RestrictionSet addOrderingRestrictions(List<Ordering> orderings, RestrictionSet restrictionSet)
{
List<Ordering> annOrderings = orderings.stream().filter(o -> o.expression.hasNonClusteredOrdering()).collect(Collectors.toList());
if (annOrderings.size() > 1)
throw new InvalidRequestException("Cannot specify more than one ANN ordering");
else if (annOrderings.size() == 1)
{
if (orderings.size() > 1)
throw new InvalidRequestException("ANN ordering does not support any other ordering");
Ordering annOrdering = annOrderings.get(0);
if (annOrdering.direction != Ordering.Direction.ASC)
throw new InvalidRequestException("Descending ANN ordering is not supported");
SingleRestriction restriction = annOrdering.expression.toRestriction();
return restrictionSet.addRestriction(restriction);
}
return restrictionSet;
}
private void processPartitionKeyRestrictions(ClientState state, boolean hasQueriableIndex, boolean allowFiltering, boolean forView)
{
if (!type.allowPartitionKeyRanges())
{
checkFalse(partitionKeyRestrictions.isOnToken(),
"The token function cannot be used in WHERE clauses for %s statements", type);
if (partitionKeyRestrictions.hasUnrestrictedPartitionKeyComponents())
throw invalidRequest("Some partition key parts are missing: %s",View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Remove the extra ORDER BY column and sort/tie-break results in the application.
- Issue the ANN-only query and post-process client-side with the secondary sort.
- If secondary sort semantics are required, restrict the result set first and sort in memory.
Example fix
// before SELECT * FROM items ORDER BY ann_of(vec) : [0.1,0.2], created_at DESC; // after SELECT * FROM items ORDER BY ann_of(vec) : [0.1,0.2]; // sort by created_at client-side
Defensive patterns
Strategy: validation
Validate before calling
if (hasAnnOrdering(orderings) && orderings.size() > 1)
throw new IllegalArgumentException("ANN ordering cannot be combined with other orderings"); Try / catch
try { session.execute(stmt); }
catch (InvalidRequestException e) {
if (e.getMessage().equals("ANN ordering does not support any other ordering")) { /* strip secondary ORDER BY, sort client-side */ }
else throw e;
} Prevention
- When adding an ANN ORDER BY, emit no other ordering terms.
- Implement tie-breaking/sorting after fetching results.
- Wrap query builders so ANN queries bypass generic ordering injection.
When it happens
Trigger: SELECT ... FROM table WHERE ... ORDER BY ann_of(v) : [...], some_clustering_col ASC — an ANN ordering plus any additional ordering in the same query.
Common situations: Users expect vector search results sorted first by similarity then by clustering column (tie-breaking) and add both orderings; vector search in Cassandra does not support secondary sort within the ANN scan.
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
- Cannot specify more than one ANN ordering
- Descending ANN ordering is not supported
- Unsupported expression during ANN index query:
- %s cannot be restricted by more than one relation in an ANN
- ANN ordering is only supported on float vector indexes
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/ec4d33121b5b936f.
Report an issue: GitHub.