Skip to content

Index on an undeclared property keys an array value by its identity string ([J@1465649d): seeks miss it, UPDATE/DELETE leave its entry behind for good #11578

Closed

Description

@shaunpatterson

Summary

An index that openCypher creates on a property with no schema declaration (CREATE INDEX FOR (n:N) ON (n.l) before any n.l exists, key type STRING) keys a primitive-array value by its Java identity string: [J@10eb4f88 for a long[], [D@... for a double[], [B@4b62d8d1 for a byte[]. Over the HTTP API those arrays are common: a numeric list nested in a parameter (UNWIND $rows AS row CREATE (:N {l: row.l})) is stored as ARRAY_OF_LONGS / ARRAY_OF_DOUBLES, and a {"$bytes": ...} parameter is a byte[].

Three consequences, none of which raises an error:

  1. An index seek never finds such a record: MATCH (n:N) WHERE n.l = $p returns nothing, the label scan WHERE n.l = [7, 8] finds it.
  2. The key is a different string on every read of the record, so an UPDATE or DELETE of the value removes nothing. The old entry stays in the index for good. After 25 updates and 10 deletes of 51 records, the index holds 76 entries for 41 records, and keeps growing with every write.
  3. CHECK DATABASE reports 0 errors. REBUILD INDEX drops the stale entries, and writes new identity strings.

Reproduction

Standard library only, HTTP API (full script below):

docker run --rm -p 2480:2480 -e JAVA_OPTS="-Darcadedb.server.rootPassword=playwithdata" arcadedata/arcadedb:26.12.1-SNAPSHOT
python3 index_array_identity_key.py      # exit 1: bug present, 0: not, 2: could not run
ArcadeDB 26.12.1-SNAPSHOT (build e0c278a0540d895f40785a9b25426feb58e181b8/1794501834293/main)

CREATE INDEX FOR (n:N) ON (n.l)
UNWIND $rows AS row CREATE (:N {id: row.id, l: row.l})     $rows = [{id: 0, l: [0, 1]}, ... {id: 49, l: [49, 50]}]
CREATE (:N {id: 100, l: $b})                                $b = {'$bytes': 'AAEC'}

stored types:      [('ARRAY_OF_LONGS', 50), ('BINARY', 1)]
first index keys:  [['[B@678fd07b'], ['[J@11333943'], ['[J@14094b1b']]

MATCH (n:N) WHERE n.l = $p      ($p = [7, 8], index seek) -> []   (expected [7])
MATCH (n:N) WHERE n.l = [7, 8]  (label scan)              -> [7]

MATCH (n:N) WHERE n.id < 25 SET n.l = [n.id]          (25 updates of the indexed property)
MATCH (n:N) WHERE n.id >= 40 AND n.id < 50 DELETE n   (10 deletes)
records: 41   index entries: 76   (expected 41)   CHECK DATABASE totalErrors: 0
after REBUILD INDEX: index entries 41

BUG PRESENT

Versions

image index keys seek n.l = $p entries / records after the writes
26.7.2 [J@... misses 77 / 41
26.8.1 [J@... misses 76 / 41
26.9.1 [J@... misses 76 / 41
26.10.2 [J@... misses 76 / 41
26.11.1 [J@... misses 76 / 41
26.12.1-SNAPSHOT e0c278a054 [J@... misses 76 / 41

Not a regression. On 26.10.2 and older the REBUILD INDEX at the end of the script also fails ("Cannot create the index on type 'N.l' because the property does not exist"); 26.11.1 fixed that part.

Cause

LSMTreeIndexAbstract.convertKeysToDeclaredTypes turns each key into the index's key type with Type.convertIndexKeyOrNull(database, key, String.class). For a String target, Type.convert refuses an array only when a property is passed:

// An array's toString() is its class code and identity hash ("[B@72e34f77"): not the content, not stable, and
// not reversible. Refuse it rather than store that (issue #9041).
if (property != null && valueClass.isArray())
  throw inconvertible(value, "STRING", property);
...
return value.toString();

The index key conversion has no property, so the array reaches toString(). The STRING key type comes from OpenCypherQueryEngine (defaultKeyTypes[i] = Type.STRING for a property it cannot infer a type for). A List value does not hit this, it becomes "[7, 8]".

The arrays come from the HTTP parameter parser (JSONObject.toMap(true) keeps a numeric array nested in a parameter as long[]/double[], see #11575) and from the $bytes marker.

Suggested fix

Give an array key a stable text form in the index key conversion, the one its List would have (Arrays.toString / the element list, or Base64 for a byte[]), so that equal values get equal keys and the delete finds the entry it wrote. Refusing the key (indexing it under null, as convertIndexKeyOrNull does for other inconvertible keys) would at least stop the leak, but the seek would still miss the record. CHECK DATABASE comparing index entries with the records would have flagged this.

Workaround

Declare the property before creating the index (CREATE PROPERTY N.l LIST: the index gets key type LIST, the write converts the array, and the same script ends with 40 entries for 40 records), or send the list as a top-level parameter, which arrives as a List and is keyed "[7, 8]".

Environment

Official arcadedata/arcadedb Docker images 26.7.2, 26.8.1, 26.9.1, 26.10.2, 26.11.1 and 26.12.1-SNAPSHOT (build e0c278a0540d895f40785a9b25426feb58e181b8), default settings, Linux x86_64.

index_array_identity_key.py
#!/usr/bin/env python3
"""
Reproduction: an index created by openCypher on a property that has no schema declaration yet
(`CREATE INDEX FOR (n:N) ON (n.l)`, key type STRING) keys a primitive-array value by its Java
identity string: `[J@1465649d` for a long[], `[D@...` for a double[], `[B@...` for a byte[].

Over HTTP a numeric list nested in a parameter (`UNWIND $rows AS row ... row.l`) arrives as a long[] /
double[] and is stored as ARRAY_OF_LONGS / ARRAY_OF_DOUBLES; a `$bytes` parameter is a byte[]. So:

  * an index seek for the value never finds the record (`WHERE n.l = $p` misses it, the scan finds it);
  * the key of the same value differs between two reads of the record, so the UPDATE or DELETE of it
    removes nothing and the old entry stays in the index for good (the index grows with every write);
  * CHECK DATABASE reports no error. REBUILD INDEX drops the stale entries (and writes new random keys).

Type.convert refuses to turn an array into its identity string when a property is declared
(issue #9041), but the index key conversion runs without a property and falls through to toString().

Standard library only, HTTP API:

    docker run --rm -p 2480:2480 -e JAVA_OPTS="-Darcadedb.server.rootPassword=playwithdata" \
        arcadedata/arcadedb:26.12.1-SNAPSHOT
    python3 index_array_identity_key.py [--port 2480]

Exit status 1 when the bug is present, 0 otherwise, 2 if it could not run.
"""

from __future__ import annotations

import argparse
import base64
import json
import sys
import urllib.error
import urllib.request


class Server:
    def __init__(self, host: str, port: int, password: str):
        self.base = f'http://{host}:{port}'
        token = base64.b64encode(f'root:{password}'.encode()).decode()
        self.headers = {'Authorization': f'Basic {token}', 'Content-Type': 'application/json'}

    def post(self, path: str, body: dict) -> dict:
        req = urllib.request.Request(self.base + path, json.dumps(body).encode(), self.headers, method='POST')
        try:
            with urllib.request.urlopen(req, timeout=120) as resp:
                return json.loads(resp.read() or b'{}')
        except urllib.error.HTTPError as e:
            raise RuntimeError(f'HTTP {e.code}: {e.read().decode()[:300]}') from None

    def version(self) -> str:
        req = urllib.request.Request(self.base + '/api/v1/server', headers=self.headers)
        with urllib.request.urlopen(req, timeout=30) as resp:
            return json.loads(resp.read()).get('version', '?')

    def run(self, db: str, language: str, command: str, params: dict | None = None) -> list:
        body = {'language': language, 'command': command}
        if params is not None:
            body['params'] = params
        return self.post(f'/api/v1/command/{db}', body)['result']

    def fresh(self, db: str) -> None:
        try:
            self.post('/api/v1/server', {'command': f'drop database {db}'})
        except RuntimeError:
            pass
        self.post('/api/v1/server', {'command': f'create database {db}'})


DB = 'array_identity_key_repro'


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument('--host', default='127.0.0.1')
    ap.add_argument('--port', type=int, default=2480)
    ap.add_argument('--password', default='playwithdata')
    args = ap.parse_args()
    s = Server(args.host, args.port, args.password)
    try:
        print(f'ArcadeDB {s.version()}\n')
    except Exception as e:  # noqa: BLE001
        print(f'cannot reach server: {e}')
        return 2

    def cy(q, p=None):
        return s.run(DB, 'opencypher', q, p)

    def sql(q, p=None):
        return s.run(DB, 'sql', q, p)

    s.fresh(DB)
    cy('CREATE INDEX FOR (n:N) ON (n.l)')
    cy('UNWIND $rows AS row CREATE (:N {id: row.id, l: row.l})', {'rows': [{'id': i, 'l': [i, i + 1]} for i in range(50)]})
    cy('CREATE (:N {id: 100, l: $b})', {'b': {'$bytes': 'AAEC'}})

    stored = sql("SELECT l.type() AS t, count(*) AS c FROM N GROUP BY l.type() ORDER BY t")
    keys = sql('SELECT key FROM index:`N[l]` LIMIT 3')
    print('CREATE INDEX FOR (n:N) ON (n.l)')
    print('UNWIND $rows AS row CREATE (:N {id: row.id, l: row.l})     $rows = [{id: 0, l: [0, 1]}, ... {id: 49, l: [49, 50]}]')
    print("CREATE (:N {id: 100, l: $b})                                $b = {'$bytes': 'AAEC'}\n")
    print(f'stored types:      {[(r["t"], r["c"]) for r in stored]}')
    print(f'first index keys:  {[r["key"] for r in keys]}')

    seek = cy('MATCH (n:N) WHERE n.l = $p RETURN n.id AS id', {'p': [7, 8]})
    scan = cy('MATCH (n:N) WHERE n.l = [7, 8] RETURN n.id AS id')
    print(f'\nMATCH (n:N) WHERE n.l = $p      ($p = [7, 8], index seek) -> {[r["id"] for r in seek]}   (expected [7])')
    print(f'MATCH (n:N) WHERE n.l = [7, 8]  (label scan)              -> {[r["id"] for r in scan]}')

    cy('MATCH (n:N) WHERE n.id < 25 SET n.l = [n.id]')
    cy('MATCH (n:N) WHERE n.id >= 40 AND n.id < 50 DELETE n')
    records = sql('SELECT count(*) AS c FROM N')[0]['c']
    entries = sql('SELECT count(*) AS c FROM index:`N[l]`')[0]['c']
    check = sql('CHECK DATABASE')[0].get('totalErrors')
    print('\nMATCH (n:N) WHERE n.id < 25 SET n.l = [n.id]          (25 updates of the indexed property)')
    print('MATCH (n:N) WHERE n.id >= 40 AND n.id < 50 DELETE n   (10 deletes)')
    print(f'records: {records}   index entries: {entries}   (expected {records})   CHECK DATABASE totalErrors: {check}')
    sql('REBUILD INDEX `N[l]`')
    print(f'after REBUILD INDEX: index entries {sql("SELECT count(*) AS c FROM index:`N[l]`")[0]["c"]}')

    bug = any('@' in str(r['key']) for r in keys) or [r['id'] for r in seek] != [7] or entries != records
    print('\nBUG PRESENT' if bug else '\nno bug')
    return 1 if bug else 0


if __name__ == '__main__':
    sys.exit(main())

Activity

  1. added
    engine
    severity:minor
    on Nov 12, 2026
  2. shaunpatterson commented on Nov 12, 2026

    @shaunpatterson
    ContributorAuthor

    The same identity-string key also shows up on the lookup side, so records stored as a plain LIST are missed too. Over HTTP a numeric array nested in a parameter arrives as a long[] ($vs = [[1, 2]], $p = [[1, 2], [3]]), the seek turns the key into its toString(), and nothing matches. Literals and the label scan are fine:

    CREATE INDEX FOR (n:T) ON (n.k)                                  // before any data
    CREATE (:T {id: 1, k: [1, 2]}), (:T {id: 2, k: [[1, 2], [3]]})   // both stored as LIST
    statement no index Cypher index on T(k)
    MATCH (n:T) WHERE n.k IN $vs RETURN n.id ($vs = [[1, 2]]) [1] []
    MATCH (n:T) WHERE n.k IN [[1, 2]] RETURN n.id [1] [1]
    MATCH (n:T) WHERE n.k = $p RETURN n.id ($p = [[1, 2], [3]]) [2] []
    MATCH (n:T) WHERE n.k = [[1, 2], [3]] RETURN n.id [2] [2]
    MATCH (n:T {k: $p}) RETURN n.id [2] []
    SELECT id FROM T WHERE k IN :vs [1] []
    SELECT id FROM T WHERE k = :p [2] []

    The plan of the first one is NodeIndexSeek(n:T) [index=T[k], k=IN [$vs], ...]. So the stable key for arrays has to be applied to the lookup key as well as to the stored value (or the lookup should convert nested arrays to lists before building the key). Measured on 26.12.1-SNAPSHOT e0c278a054.

  3. added this to the 26.12.1 milestone on Nov 12, 2026
  4. added
    in progress
    on Nov 12, 2026
  5. added a commit that references this issue on Nov 13, 2026
  6. added a commit that references this issue on Nov 15, 2026
  7. added a commit that references this issue on Nov 15, 2026
  8. added a commit that references this issue on Nov 16, 2026
  9. removed
    in progress
    on Nov 18, 2026
  10. added a commit that references this issue on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugengineopencypherseverity:minor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions