Repository navigation
Description
Summary
SelectOperator.lt and le evaluate to BinaryComparator.compareTo(value, operand) < 0 / <= 0,
and BinaryComparator.compareTo(null, x) answers -1. A record that does not carry the property -
or carries it as an explicit null - therefore SATISFIES every < and <= predicate on it. gt and
ge are unaffected by the same -1, so the two directions disagree: a < 5 admits the nulls and
a >= 0 excludes them.
That alone is already a wrong answer against the obvious reading (and against what SQL does with the
same predicate). What makes it worse is that it is not stable: when an index exists on the property,
filterWithIndexesFinalNode answers the leaf from an index range scan, and index entries only exist
for records that HAVE the property, so the null-bearing records are never even offered to
evaluateWhere. The same select over the same data returns 12 rows with no index and 5 rows with
one. Creating an index is supposed to be a performance decision; here it silently changes the result.
Where (HEAD 28b71e3)
engine/src/main/java/com/arcadedb/query/select/SelectOperator.java:79
lt("<", false, 1) {
@Override
Object eval(final Document record, final Object left, final Object right) {
return BinaryComparator.compareTo(SelectExecutor.evaluateValue(record, left), SelectExecutor.evaluateValue(record, right))
< 0;
}
},
le("<=", false, 1) {
...
<= 0;against the null rule it inherits,
engine/src/main/java/com/arcadedb/serializer/BinaryComparator.java:572
public static int compareTo(final Object a, final Object b) {
if (a == null && b == null)
return 0;
else if (a != null && b == null)
return 1;
else if (a == null)
return -1;and the index path that disagrees with it,
engine/src/main/java/com/arcadedb/query/select/SelectExecutor.java:748
else if (node.operator == SelectOperator.lt)
cursor = node.index.range(ascendingOrder, null, false, new Object[] { rightValue }, false);
else if (node.operator == SelectOperator.le)
cursor = node.index.range(ascendingOrder, null, false, new Object[] { rightValue }, true);(is_null and is_not_null are deliberately excluded from CURSOR_BUILDABLE_OPERATORS precisely
because the index cannot answer about absent values - the same reasoning applies to lt/le as long
as they are defined to match them.)
Repro
One document type D with an INTEGER a; 5 records with a = 0..4, 5 records with no a property
at all, 2 records with a explicitly set to null. The same six selects run with and without an
LSM_TREE index on a, each next to the identical SQL:
=== index on a: false (5 rows a=0..4, 5 rows without 'a', 2 rows a=null)
a < 5 sql= 5 native=12
a <= 4 sql= 5 native=12
a > -1 sql= 5 native= 5
a >= 0 sql= 5 native= 5
a <> 99 sql=12 native=12
a between 0 and 4 sql= 5 native= 5
=== index on a: true (same data)
a < 5 sql= 5 native= 5
a <= 4 sql= 5 native= 5
a > -1 sql= 5 native= 5
a >= 0 sql= 5 native= 5
a <> 99 sql=12 native=12
a between 0 and 4 sql= 5 native= 5
Read the two a < 5 lines together: 12 rows without the index, 5 with it, same data, same query.
between is already consistent (its lower-bound compare rejects the null), and gt/ge are
consistent, so lt and le are the only two out of step.
Suggested fix
Make lt/le reject a null left operand explicitly, the way a missing value is rejected everywhere
else, e.g. evaluate the left value once and answer false when it is null before comparing - which
also makes them agree with gt/ge, with between, and with the index path, so the index stops
changing the answer. If instead the intent really is "absent sorts first", then lt/le must be
removed from CURSOR_BUILDABLE_OPERATORS so the index path stops disagreeing; but that direction
also leaves a < 5 and a >= 5 jointly exhaustive while a is null is true, which no caller is
likely to want. A regression test belongs next to the existing native-query tests and should assert
the with-index and without-index answers are equal for <, <=, >, >= and between over a type
where some records lack the property.
Scope / confidence
Reproduced end to end at HEAD with the index/no-index pair as the control. Rated high: it is a silent
wrong answer on the simplest possible native query, it is triggered by nothing more exotic than an
optional property, and the result depends on the physical schema rather than only on the data.
Reachable from documents(), vertices(), edges(), count(), exists() and stream(), all of
which share evaluateWhere.
Activity
Merge pull request #8094 from ArcadeData/fix/issues-8064-8042
lvca commentedon Sep 21, 2026
Fixed in #8094, released in 26.10.1.
With the native Select API,
where a < 5also matched records that have noaproperty at all, whilewhere a >= 0correctly excluded them. And the result was not even stable: the same query over the same data returned 12 rows without an index onaand 5 rows with one, because an index holds no entry for a record that is missing the property.A missing or null value is now treated the way SQL treats it: a comparison against it is never true. So
<,<=,>,>=andbetweenall agree with each other, and the answer no longer depends on whether an index happens to exist.To ask about absent values, use
is null/is not null, which are unchanged.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
fix(select): four silent wrong answers on the native Select API (Arca…