GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #9238

New issue
Copy link
New issue
Copy link
Closed
humemai/arcadedb-embedded-python
#187
humemai/arcadedb-embedded-python#187
Closed
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#9238
humemai/arcadedb-embedded-python
#187
Copy link
Assignees
lvca
Labels
bugengineCore engine: document/schema APIseverity:minorCosmetic, documentation, edge case, or a workaround existssql
Milestone
26.10.1

Description

@tae898
tae898
opened on Oct 4, 2026
Issue body actions

An 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):

  • BinaryCondition.isIndexAware: an = whose right side is early calculated is index aware whatever its value; only an empty collection opts out.
  • SelectExecutionPlanner: an index-aware condition moves into the index key and is removed from the remaining filter, so no record is checked against it afterwards.
  • FetchFromIndexStep.init skips a seek with a null range bound (min()/max() of an indexed property under a range on it read the whole range: SELECT min(a) FROM V WHERE a > ? takes 145 ms (openCypher 795 ms) where ORDER BY a LIMIT 1 takes 0.2-0.5 ms #8812) and one with a null IN element (SQL: x IN ? with a list that holds null, and x IN (SELECT ...) over a subquery that returns a null, also return the records whose x is null when the index stores null keys, where a scan and a literal x IN [1, null] do not #9032), but not one with a null equality value, which then goes to index.get (or to index.range as a prefix when it is shorter than the index key) and finds the null entries.
  • On a NULL_STRATEGY ERROR index, LSMTreeIndexMutable.get calls checkForNulls, which throws for a lookup as it does for a write.
  • The scan's = is false when either side is null: QueryOperatorEquals.equals.

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.

Activity

  1. github-actions
    added
    bug
    engineCore engine: document/schema API
    severity:minorCosmetic, documentation, edge case, or a workaround exists
    sql
    on Oct 4, 2026
  2. lvca
    added
    in progressThe team is actively working on this issue
    on Oct 4, 2026
  3. lvca
    self-assigned this
    on Oct 4, 2026
  4. lvca
    added this to the 26.10.1 milestone on Oct 4, 2026
  5. tae898
    added 2 commits that reference this issue on Oct 5, 2026

    bindings: ArcadeData#9237 and ArcadeData#9236 tripwires become plain …

    d012d82

    bindings: known issues and strict xfail tripwires for upstream Arcade…

    cde639b
  6. lvca
    added 2 commits that reference this issue on Oct 5, 2026

    fix(#9238,#9224,#9164): CI index equality with null, accept() re-chec…

    1250562

    Merge pull request #9246 from ArcadeData/fix/9164-9224-9166-9238-9066

    111aa40
  7. lvca commented on Oct 5, 2026

    @lvca
    lvca
    on Oct 5, 2026
    Member
    More actions

    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.

  8. lvca
    removed
    in progressThe team is actively working on this issue
    on Oct 5, 2026
  9. lvca
    closed this as completedon Oct 5, 2026
  10. lvca commented on Oct 5, 2026

    @lvca
    lvca
    on Oct 5, 2026
    Member
    More actions

    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.

  11. tae898
    added 2 commits that reference this issue on Oct 5, 2026

    bindings: tripwires for upstream ArcadeData#9238 become plain tests; …

    429332a

    bindings: the ArcadeData#9274 tripwires become plain tests (PR Arcade…

    ca86239
  12. tae898 commented on Oct 5, 2026

    @tae898
    tae898
    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.

  13. tae898
    added a commit that references this issue on Oct 5, 2026

    bindings: the ArcadeData#9242 and ArcadeData#9274 tripwires become pl…

    3e82926
  14. oc007us
    added a commit that references this issue on Oct 6, 2026

    fix(ArcadeData#9164,ArcadeData#9224,ArcadeData#9238,ArcadeData#9066):…

    d6808ac
  15. robfrank
    added 2 commits that reference this issue on Oct 6, 2026

    fix(#9164,#9224,#9238,#9066): bound Mongo aggregation regex, bind eve…

    deb2de4

    fix(#9238,#9224,#9164): CI index equality with null, accept() re-chec…

    1207720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @lvca
    lvca

Labels

bugengineCore engine: document/schema APIseverity:minorCosmetic, documentation, edge case, or a workaround existssql

Type

No type

Projects

No projects

    Milestone

    • 26.10.1

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.