GeezerVison is showing github.com — Follow-up to #9032: SQL `p = ?` with the parameter bound to null returns the records whose `p` is null or missing through an index that stores null keys (`NULL_STRATEGY INDEX`, or any composite index), where a scan and the literal `p = null` return none · Issue #9238 · ArcadeData/arcadedb
Follow-up to #9032: SQL p = ? with the parameter bound to null returns the records whose p is null or missing through an index that stores null keys (NULL_STRATEGY INDEX, or any composite index), where a scan and the literal p = null return none #9238DescriptionAn SQL equality whose value is a parameter bound to null is answered through an index with the records whose key is null, when the index stores null keys. A scan of the same type returns no record for the same query, and so does the literal p = null on the indexed type. PR #9163 fixed this for IN (#9032) and left the equality as it was on purpose ("IN turns a null into "matches nothing", an equality keeps its own handling", the javadoc of hasNullInKeySlot), so I am filing the equality on its own. The docs say an equality with null matches nothing, so I read the index as the one that is wrong.
What the differential found on main 1addb51950 (an indexed type against an unindexed twin with the same rows, 36 index shapes: LSM_TREE and HASH, NOTUNIQUE and UNIQUE, NULL_STRATEGY SKIP, INDEX and ERROR, on (p), (p, q) and (q, p)):
- A single-property index with
NULL_STRATEGY INDEX (NOTUNIQUE, UNIQUE, NOTUNIQUE_HASH, UNIQUE_HASH): WHERE p = ? returns the records whose p is null and the records without p (through a UNIQUE index only one of them, SQL p IS NULL through a UNIQUE or UNIQUE_HASH index with NULL_STRATEGY INDEX returns one of the records whose p is null, and count(*) counts one #9237).
- Every composite index, including one created with the default
NULL_STRATEGY SKIP, which keeps a key unless all of its properties are null (SQL on a composite index with the default NULL_STRATEGY SKIP: a record whose first indexed property is null (and a later one is not) comes back twice from ORDER BY, is counted twice by GROUP BY ... ORDER BY, and matches WHERE a < 5 #8978): WHERE q = 7 AND p = ? returns the record with q = 7 whose p is null, whether p is the first or the second property of the index. WHERE p = ? alone does the same on an LSM_TREE index whose first property is p.
- An
LSM_TREE index with NULL_STRATEGY ERROR: the query throws IllegalArgumentException, the "cannot be NULL" refusal meant for a write (see Where), instead of returning no record. (A HASH index with ERROR stores null keys, A HASH index accepts NULL_STRATEGY ERROR and then stores null and missing keys without an error #9074, which the open PR fix(#5712,#9074,#9169): unordered tagged hash buckets, NULL_STRATEGY ERROR on hash, new page size defaults #9222 addresses, and then answers like INDEX.)
DELETE ... WHERE p = ? and UPDATE ... WHERE q = 7 AND p = ? delete and update those records.
- A named parameter (
p = :x) behaves the same as ?.
On the same 36 shapes these answer like the scan: the literal p = null and q = 7 AND p = null, p <> ?, NOT (p = ?), p IN [null], p IN ? with [null] (the #9163 fix), and p IS NULL and p <=> ?, which return the null records (apart from p IS NULL through a single-property UNIQUE or UNIQUE_HASH index with NULL_STRATEGY INDEX, which returns one of them, the separate issue above). openCypher WHERE n.p = $x, {p: $x}, n.q = 7 AND n.p = $x, and their DETACH DELETE and SET forms answer like the scan on every shape (except that reads through a composite HASH index throw when the seek has only part of the key, which a null trailing parameter causes; filed as #9236 with non-null values), because NodeIndexSeek drops a null leading value (L218-L220) and cuts the key at a null trailing one (L183-L188), and the WHERE filter still runs after the seek.
An application that passes an optional filter as a bound parameter (for example WHERE tenant = ? AND parent = ?, with parent null for a top-level row) gets a different answer depending on which indexes the type has, and a DELETE with such a parameter removes records a scan keeps.
Where (permalinks at 1addb51950):
The docs agree with the scan (sql-where.adoc L109-L113): "Comparing with a missing or NULL value is neither true nor false but unknown, as in standard SQL. This applies to =, ...", "Likewise age = NULL and age <> NULL match nothing", and "To test for a missing value use IS NULL, IS NOT NULL or the null-safe <=>".
Repro
# lib/ holds the engine jar built at the commit under test and its dependencies
javac -cp 'lib/*' -d cls NullEqualityThroughIndex.java
java -Xmx2g -XX:+UseCompactObjectHeaders --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED -cp 'lib/*:cls' NullEqualityThroughIndex ./db
Scan has no index, LsmIndex an LSM_TREE index with NULL_STRATEGY INDEX, Composite a composite index on (q, p) with the default null strategy, HashIndex a NOTUNIQUE_HASH index with NULL_STRATEGY INDEX, and LsmError an LSM_TREE index with NULL_STRATEGY ERROR (it holds only the record with p = 1, the null ones cannot be stored).
import com.arcadedb.database.*;
import com.arcadedb.query.sql.executor.*;
import java.util.*;
public class NullEqualityThroughIndex {
public static void main(String[] args) {
System.out.println("ArcadeDB " + com.arcadedb.Constants.getRawVersion() + " (" + com.arcadedb.Constants.getBuildNumber() + "), Java "
+ System.getProperty("java.version"));
try (Database db = new DatabaseFactory(args[0]).create()) {
final String[] types = { "Scan", "LsmIndex", "Composite", "HashIndex", "LsmError" };
for (String t : types) {
db.command("sql", "CREATE VERTEX TYPE " + t);
db.command("sql", "CREATE PROPERTY " + t + ".id INTEGER");
db.command("sql", "CREATE PROPERTY " + t + ".p INTEGER");
db.command("sql", "CREATE PROPERTY " + t + ".q INTEGER");
}
db.command("sql", "CREATE INDEX ON LsmIndex (p) NOTUNIQUE NULL_STRATEGY INDEX");
db.command("sql", "CREATE INDEX ON Composite (q, p) NOTUNIQUE");
db.command("sql", "CREATE INDEX ON HashIndex (p) NOTUNIQUE_HASH NULL_STRATEGY INDEX");
db.command("sql", "CREATE INDEX ON LsmError (p) NOTUNIQUE NULL_STRATEGY ERROR");
db.transaction(() -> {
for (String t : new String[] { "Scan", "LsmIndex", "Composite", "HashIndex" }) {
db.newVertex(t).set("id", 1, "p", 1, "q", 7).save();
db.newVertex(t).set("id", 2, "p", null, "q", 7).save();
db.newVertex(t).set("id", 3, "q", 7).save(); // p not set
}
db.newVertex("LsmError").set("id", 1, "p", 1, "q", 7).save();
});
System.out.println("Each type holds (id, p, q) = (1, 1, 7), (2, null, 7), (3, not set, 7); LsmError holds only id 1");
final Map<String, Object> x = new HashMap<>();
x.put("x", null);
final String[] sql = { "p = ?", "p = :x", "p = null", "p <=> ?", "p IS NULL", "q = 7 AND p = ?" };
for (String where : sql) {
final StringBuilder sb = new StringBuilder();
for (String t : types)
sb.append(String.format("%s %-12s ", t, ids(db, "sql", "SELECT id FROM " + t + " WHERE " + where, where.contains(":x") ? x : null)));
System.out.printf(" SQL WHERE %-16s %s%n", where, sb);
}
final StringBuilder sb = new StringBuilder();
for (String t : types) {
db.begin();
sb.append(String.format("%s %-12s ", t, ids(db, "sql", "DELETE FROM " + t + " RETURN BEFORE WHERE p = ?", null)));
db.rollback();
}
System.out.printf(" SQL DELETE ... WHERE p = ? %s (rolled back)%n", sb);
final StringBuilder cy = new StringBuilder();
for (String t : types)
cy.append(String.format("%s %-12s ", t, ids(db, "cypher", "MATCH (n:" + t + ") WHERE n.p = $x RETURN n.id AS id", x)));
System.out.printf(" Cypher WHERE n.p = $x %s%n", cy);
System.out.println(" ? and $x are bound to null");
}
}
static String ids(Database db, String language, String query, Map<String, Object> named) {
try (ResultSet rs = named != null ? db.command(language, query, named) : db.command(language, query, (Object) null)) {
final List<Integer> ids = new ArrayList<>();
rs.forEachRemaining(r -> ids.add(r.<Integer>getProperty("id")));
Collections.sort(ids);
return ids.toString();
} catch (Exception e) {
return e.getClass().getSimpleName();
}
}
}
Output on main 1addb51950 (the engine jar's build stamp is 1addb51950), Temurin 25.0.4 with -XX:+UseCompactObjectHeaders:
ArcadeDB 26.10.1-SNAPSHOT (1addb519505253cbad99d1744d1abd23972928a8), Java 25.0.4
Each type holds (id, p, q) = (1, 1, 7), (2, null, 7), (3, not set, 7); LsmError holds only id 1
SQL WHERE p = ? Scan [] LsmIndex [2, 3] Composite [] HashIndex [2, 3] LsmError IllegalArgumentException
SQL WHERE p = :x Scan [] LsmIndex [2, 3] Composite [] HashIndex [2, 3] LsmError IllegalArgumentException
SQL WHERE p = null Scan [] LsmIndex [] Composite [] HashIndex [] LsmError []
SQL WHERE p <=> ? Scan [2, 3] LsmIndex [2, 3] Composite [2, 3] HashIndex [2, 3] LsmError []
SQL WHERE p IS NULL Scan [2, 3] LsmIndex [2, 3] Composite [2, 3] HashIndex [2, 3] LsmError []
SQL WHERE q = 7 AND p = ? Scan [] LsmIndex [2, 3] Composite [2, 3] HashIndex [2, 3] LsmError IllegalArgumentException
SQL DELETE ... WHERE p = ? Scan [] LsmIndex [2, 3] Composite [] HashIndex [2, 3] LsmError IllegalArgumentException (rolled back)
Cypher WHERE n.p = $x Scan [] LsmIndex [] Composite [] HashIndex [] LsmError []
? and $x are bound to null
Temurin 21.0.12 printed the same lines apart from the Java version on the first line.
Versions affected: main 417314c18d (2026-09-17) printed the same lines apart from the first line, on Temurin 25 and 21. The record whose p is null comes back through the index on both builds; it is not new.
Expected: an equality whose value is null matches no record, through an index as in a scan: on every type above, p = ?, p = :x, and q = 7 AND p = ? with null return [], the DELETE deletes nothing, and the ERROR index answers [] instead of throwing. The index step could skip a seek whose equality slot holds null, as it does for a null range bound and a null IN element, or BinaryCondition.isIndexAware could leave an = with a null value to the scan, as the literal p = null already is.
Duplicates checked: gh search issues --repo ArcadeData/arcadedb for "null index equality", "NULL_STRATEGY", "= null", "null parameter index", "equality null index", "IS NULL index", "null key composite index", and "null parameter". The nearest are #9032 (closed by #9163: the same lookup for a null IN element; its description named the equality seek too, but its repro and title were IN, and the fix kept to IN), #8833 (closed: a range with only an upper bound on a NULL_STRATEGY INDEX index returned the null records), #8812 (closed: a null range bound), #8978 (closed: a composite SKIP index and a leading null), #4591 (closed: three-valued IN and NOT IN in a scan), #6952 (closed: the MongoDB wire protocol compiled a filter on a null field to = :param, which a scan never matches), and #9074 (open: a HASH index with NULL_STRATEGY ERROR stores null keys). I found no issue for an equality with a null value through an index. Activitylvca commented on Oct 5, 2026 Fixed in #9246 (26.10.1). An equality whose value is null (p = ? with null, p = :x) now matches no record through an index, exactly as in a scan: no null-key records are returned, DELETE/UPDATE do not touch them, and a NULL_STRATEGY ERROR index no longer throws. Use IS NULL or <=> to find null values. Note: such a query now falls back to a scan instead of an index lookup.
❤️ 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. lvca commented on Oct 5, 2026 Fixed in #9246 (26.10.1): an equality with a null value (p = ? bound to null) now matches no record through an index, as it does in a scan. DELETE/UPDATE no longer touch the null records, and a NULL_STRATEGY ERROR index no longer throws. <=> and IS NULL 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. tae898 commented on Oct 5, 2026 ContributorAuthor More actions Checked on upstream main 5a90b0f (the merge of #9246 that closes this issue, #9066, #9164, and #9224; engine jars built by CI from that commit, no ha-raft shaded jar on the classpath) against e2294d3 (the merge of #9262, built by CI; it is the build before #8980 and #9246). The repro is the one filed in this issue, unchanged. One JVM per run, in a container limited to 2 cores and 2 GB (-Xmx1g), on Temurin 25.0.4 with -XX:+UseCompactObjectHeaders and on Temurin 21.0.12. The comparison build is the nearest one I had: it differs from the first parent of the merge only by #8980 (SQL aggregates, ORDER BY, and Type.increment), which touches none of the files #9246 changes for this issue.
Verdict for the issue as filed: fixed on both JDKs for a statement whose text is first run with null, with one exception that is tracked in #9274 and fixed by #9276 (the cached-plan case, explained after the differential). The filed repro (NullEqualityThroughIndex, unchanged) now gives the scan's answer for every form and every index type it holds:
| statement (null bound) |
build |
Scan (oracle) |
LSM, NULL_STRATEGY INDEX |
composite (q, p) |
HASH, NULL_STRATEGY INDEX |
LSM, NULL_STRATEGY ERROR |
SQL WHERE p = ? |
before |
[] |
[2, 3] |
[] |
[2, 3] |
IllegalArgumentException |
|
after |
[] |
[] |
[] |
[] |
[] |
SQL WHERE p = :x |
before |
[] |
[2, 3] |
[] |
[2, 3] |
IllegalArgumentException |
|
after |
[] |
[] |
[] |
[] |
[] |
SQL WHERE p = null |
before |
[] |
[] |
[] |
[] |
[] |
|
after |
[] |
[] |
[] |
[] |
[] |
SQL WHERE p <=> ? |
before |
[2, 3] |
[2, 3] |
[2, 3] |
[2, 3] |
[] |
|
after |
[2, 3] |
[2, 3] |
[2, 3] |
[2, 3] |
[] |
SQL WHERE p IS NULL |
before |
[2, 3] |
[2, 3] |
[2, 3] |
[2, 3] |
[] |
|
after |
[2, 3] |
[2, 3] |
[2, 3] |
[2, 3] |
[] |
SQL WHERE q = 7 AND p = ? |
before |
[] |
[2, 3] |
[2, 3] |
[2, 3] |
IllegalArgumentException |
|
after |
[] |
[] |
[] |
[] |
[] |
SQL DELETE ... WHERE p = ? |
before |
[] |
[2, 3] |
[] |
[2, 3] |
IllegalArgumentException |
|
after |
[] |
[] |
[] |
[] |
[] |
Cypher WHERE n.p = $x |
before |
[] |
[] |
[] |
[] |
[] |
|
after |
[] |
[] |
[] |
[] |
[] |
The output on each build is the same on both JDKs.
To check the adjacent forms I ran a differential (NullEqualityMore): 22 index kinds on an INTEGER and on a STRING property (LSM and HASH, NOTUNIQUE and UNIQUE, NULL_STRATEGY INDEX, SKIP, and ERROR, composite with the property first and last, composite HASH), each with a twin type with the same rows and no index as the oracle, and 22 predicates (= ?, = :x, = null, the reversed operand ? = c, :x = c, null = c, <=> ?, IS NULL, IS NOT NULL, != ?, <> :x, IN [?], IN :x with a list holding null, >= ?, < :x, q = 7 AND c = ?, c = ? AND q = 7, q = 7 AND c = :x, c = ? AND q = ?, c = ? OR q = 8, NOT (c = ?), c = ? AND c IS NULL) through SELECT, UPDATE (the records touched), and DELETE (rolled back), plus openCypher: 1496 statements per build and JDK, each statement text first run with null. A statement counts as right when the indexed type gives the twin's result (or both throw).
| statements equal to the scan twin |
before e2294d3635 JDK 25 |
JDK 21 |
after 5a90b0f52a JDK 25 |
JDK 21 |
|
1160 of 1496 |
1160 of 1496 |
1496 of 1496 |
1496 of 1496 |
On the build before, the statements that differ from the scan twin are, by predicate (each as SELECT, UPDATE, and DELETE where those apply): c = ?, c = :x, q = 7 AND c = ?, c = ? AND q = 7, q = 7 AND c = :x, c = ? AND q = ? (q bound 7), c = ? OR q = 8, c = ? AND c IS NULL. The predicates that already matched the scan on the build before are c = null, ? = c (reversed), :x = c (reversed), null = c (reversed), c <=> ? (null-safe), c IS NULL, c IS NOT NULL, c != ?, c <> :x, c IN [?], c IN :x, c >= ?, c < :x, NOT (c = ?), n.c = $x, n.c IS NULL. After the fix none of the 1496 statements differs from its scan twin, on either JDK.
The one gap I found in this build, a statement that had already run with a non-null value and then ran with null reusing its cached index plan, is #9274; #9276 fixed it, and I verified that in that issue (#9274 (comment)). Everything above is about statements whose text is first run with null, which is how each statement was run here.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|