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 #9238: a statement first run with a value keeps its index plan, so a later run with null returns the null-key records again, and a DELETE removes them · Issue #9274 · ArcadeData/arcadedb

Follow-up to #9238: a statement first run with a value keeps its index plan, so a later run with null returns the null-key records again, and a DELETE removes them #9274

New issue
Copy link
New issue
Copy link
Closed
#9276
Closed
Follow-up to #9238: a statement first run with a value keeps its index plan, so a later run with null returns the null-key records again, and a DELETE removes them#9274
#9276
Copy link
Assignees
lvca
Labels
bugengineCore engine: document/schema APIseverity:criticalData loss, corruption, crash/hang, security hole, or product unusablesql
Milestone
26.10.1

Description

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

Summary

#9246 (the fix for #9238) makes an equality whose value is null match no record through an index, by deciding at planning time that the index cannot answer it. A statement that has already run with a non-null value keeps its index plan, and the next run of the same statement text with null reuses that plan, so the null-key records come back again: the bug of #9238 returns for any statement that was first run with a value. A DELETE does the same and removes the null-key records, so data is lost.

On 111aa40457 (the merge of #9246), Temurin 25.0.4 with -XX:+UseCompactObjectHeaders and Temurin 21.0.12, the output of the repro below is identical on both JDKs:

SELECT p = ? with 1, null, 1, null: [1] [2, 3] [1] [2, 3]
records left after DELETE with 99 then null (3 expected): 3
records left after DELETE (no id filter) with 99 then null (3 expected): 1

Expected [1] [] [1] [] and 3 records left each time. The first run of the same statement with null is correct ([]); only a run after a non-null value is wrong. With -Darcadedb.sqlStatementCache=0 the output is [1] [] [1] [] and 3, 3 (measured on Temurin 25), and on 354396071e, before #9246, it is [1] [2, 3] [1] [2, 3] and 3, 1, which is the original #9238.

Where (at 111aa40)

BinaryCondition.isIndexAware returns vl != null for the equality (L259) and right.execute((Result) null, info.getContext()) != null for the other form (L277): the decision depends on the parameter value of the run that plans the statement. The plan is then cached by statement text and reused by a run with another value, as the measurements above show (the cache off gives the right answers).

Repro

Run with the engine jar and its dependencies on the classpath, as java CachedPlanNull.java <empty directory>.

import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.query.sql.executor.ResultSet;

import java.util.ArrayList;
import java.util.List;

/**
 * After PR #9246 (#9238): a statement first run with a value keeps a plan through the index, and its next run with null reuses it.
 * Usage: java -cp "<engine jars>/*" CachedPlanNull.java <empty-dir>
 */
public class CachedPlanNull {
  static List<Integer> ids(final Database db, final Object value) {
    final List<Integer> ids = new ArrayList<>();
    try (final ResultSet rs = db.query("sql", "SELECT id FROM T WHERE p = ?", value)) {
      rs.forEachRemaining(r -> ids.add(r.getProperty("id")));
    }
    java.util.Collections.sort(ids);
    return ids;
  }

  public static void main(final String[] args) {
    try (final DatabaseFactory factory = new DatabaseFactory(args[0] + "/db")) {
      try (final Database db = factory.create()) {
        db.command("sql", "CREATE DOCUMENT TYPE T");
        db.command("sql", "CREATE PROPERTY T.id INTEGER");
        db.command("sql", "CREATE PROPERTY T.p INTEGER");
        db.command("sql", "CREATE INDEX ON T (p) NOTUNIQUE NULL_STRATEGY INDEX");
        db.transaction(() -> {
          db.newDocument("T").set("id", 1, "p", 1).save();
          db.newDocument("T").set("id", 2, "p", null).save();
          db.newDocument("T").set("id", 3).save();
        });
        // expected [1], [], [1], []
        System.out.println("SELECT p = ? with 1, null, 1, null: " + ids(db, 1) + " " + ids(db, (Object) null) + " " + ids(db, 1) + " "
            + ids(db, (Object) null));
        // expected: nothing deleted (3 records stay)
        db.transaction(() -> db.command("sql", "DELETE FROM T WHERE p = ? AND id > 100", 99));
        db.transaction(() -> db.command("sql", "DELETE FROM T WHERE p = ? AND id > 100", (Object) null));
        System.out.println("records left after DELETE with 99 then null (3 expected): " + db.countType("T", false));
        db.transaction(() -> db.command("sql", "DELETE FROM T WHERE p = ?", 99));
        db.transaction(() -> db.command("sql", "DELETE FROM T WHERE p = ?", (Object) null));
        System.out.println("records left after DELETE (no id filter) with 99 then null (3 expected): " + db.countType("T", false));
        db.drop();
      }
    }
  }
}

Expected

A null equality matches no record on every run of a statement, whatever value the statement was run with before: the plan must not depend on the value of the run that happened to plan it, or the value test must move to execution (the index step skipping the seek when its equality value is null, as it already does for a null range bound and a null IN element).

Near misses

#9238 and PR #9246 (this is a hole in that fix). #9245 and #9247 (the SQL cache and parameter numbers: another way a cached plan is reused for a statement it does not fit, fixed in #9252 and #9251). #9032 (the same lookup for a null IN element).

Activity

  1. github-actions
    added
    bug
    engineCore engine: document/schema API
    severity:criticalData loss, corruption, crash/hang, security hole, or product unusable
    sql
    on Oct 5, 2026
  2. robfrank
    added this to the 26.11.1 milestone on Oct 5, 2026
  3. lvca
    added
    in progressThe team is actively working on this issue
    on Oct 5, 2026
  4. lvca
    self-assigned this
    on Oct 5, 2026
  5. lvca
    modified the milestones: 26.11.1, 26.10.1 on Oct 5, 2026
  6. lvca
    added 7 commits that reference this issue on Oct 5, 2026

    review(#9274): cover CI, unique, null literal and range-side null; ti…

    cb55df9

    review(#9274): rename the null-rejecting slot mask

    170311a

    review(#9274): rename parameter, wrap Javadoc, cover null-first and I…

    79a5200

    review(#9274): cover count(*) and null first slot, drop redundant reload

    801cfed

    review(#9274): null-key fixtures for composite and unique tests, asse…

    96149e8

    review(#9274): accurate fixture comment

    4d73943

    Merge pull request #9276 from ArcadeData/fix/9274-null-eq-cached-plan

    d36b4ca
  7. lvca
    closed this as completedin #9276on Oct 5, 2026
  8. lvca
    removed
    in progressThe team is actively working on this issue
    on Oct 5, 2026
  9. lvca commented on Oct 5, 2026

    @lvca
    lvca
    on Oct 5, 2026
    Member
    More actions

    Fixed in #9276 (merged).

    Confirmed: a statement first run with a value kept its index plan, and a later run of the same text with a null parameter reused it, returning (and for DELETE, removing) the records whose key is null. The null check was made when the plan was built; it is now made on every execution, so a null equality matches no record whatever the statement was run with before. Regression tests cover SELECT, DELETE, composite, case-insensitive and unique indexes.

    This restores the intended behavior of #9238, so no documentation change is needed.


    ❤️ 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.

  10. tae898 commented on Oct 5, 2026

    @tae898
    tae898
    on Oct 5, 2026
    ContributorAuthor
    More actions

    Verified the fix of #9276 on upstream main d36b4ca (CI-built jars, no HA-raft shaded jar), against 111aa40, where this was filed. Temurin 25.0.4 with compact object headers and Temurin 21.0.12 give identical output.

    The statement text is run with a value, then null, then the value again. Expected [1] [] [1]:

    index and parameter form before after
    NOTUNIQUE, positional (value, null, value, null) [1] [2, 3] [1] [2, 3] [1] [] [1] []
    NOTUNIQUE index, named parameter [1] [2, 3] [1] [1] [] [1]
    NOTUNIQUE_HASH index, positional [1] [2, 3] [1] [1] [] [1]
    UNIQUE index, positional [1] [2, 3] [1] [1] [] [1]
    NULL_STRATEGY ERROR index, named [1] raised IllegalArgumentException: Indexed key T[p] cannot be NULL ([null]) [1] [1] [] [1]
    composite (q, p), named [1] [] [1] [1] [] [1]

    The unfiltered DELETE FROM T WHERE p = ? run with 99 and then with null leaves 1 of 3 records before and 3 of 3 after.

    The hash index, NULL_STRATEGY ERROR (which no longer raises on the second run), and the named-parameter form are not in your list of regression tests, and they now answer like the others. The composite index, which was not affected before, still answers correctly.

    Thank you for the quick fix.

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

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

    ca86239

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

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

    fix(ArcadeData#9274): decide a null equality at execution, so a cache…

    2196b18
  13. robfrank
    added 7 commits that reference this issue on Oct 6, 2026

    fix(#9274): decide a null equality at execution, so a cached index pl…

    a83b5a4

    review(#9274): cover CI, unique, null literal and range-side null; ti…

    f148f84

    review(#9274): rename the null-rejecting slot mask

    1ecb1cd

    review(#9274): rename parameter, wrap Javadoc, cover null-first and I…

    4053d05

    review(#9274): cover count(*) and null first slot, drop redundant reload

    d06a1da

    review(#9274): null-key fixtures for composite and unique tests, asse…

    dec0f10

    review(#9274): accurate fixture comment

    2c80289
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:criticalData loss, corruption, crash/hang, security hole, or product unusablesql

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.