AQL `use-indexes` uses a sparse index for a range condition that can match `null` when an `OR` branch proves non-null, dropping rows
Author: the-ShallowCreated Oct 1, 2026Updated Oct 1, 2026
Description
When a FILTER has a < / <= range on an attribute and, in a conjunction, an OR whose one branch implies the
attribute is not null (d.b >= 0, d.b != null), the optimizer serves the range from a sparse index on that
attribute. A sparse index holds no document whose attribute is null, but the other OR branch still admits such
documents (null < 5 is true in AQL), so they are dropped. With the optimizer rules off, the query returns them.
Reproduction
db._create("sp");
db.sp.insert([{a: 1, b: null}, {a: 1, b: 7}]);
db.sp.ensureIndex({type: "persistent", fields: ["b"], sparse: true});
var q = "FOR d IN sp FILTER d.b < 5 AND (d.b >= 0 OR d.a == 1) RETURN d.a";
db._query(q).toArray(); // [] wrong
db._query(q, {}, {optimizer: {rules: ["-all"]}}).toArray(); // [ 1 ] correct
// the same with (d.b != null OR d.a == 1)Expected
[1] in both cases: the document {a: 1, b: null} satisfies d.b < 5 and d.a == 1.
Source: arangodb/arangodb