Repository navigation
Description
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:
- An index seek never finds such a record:
MATCH (n:N) WHERE n.l = $preturns nothing, the label scanWHERE n.l = [7, 8]finds it. - The key is a different string on every read of the record, so an
UPDATEorDELETEof 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. CHECK DATABASEreports 0 errors.REBUILD INDEXdrops 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
shaunpatterson commentedon Nov 12, 2026
The same identity-string key also shows up on the lookup side, so records stored as a plain
LISTare missed too. Over HTTP a numeric array nested in a parameter arrives as along[]($vs = [[1, 2]],$p = [[1, 2], [3]]), the seek turns the key into itstoString(), and nothing matches. Literals and the label scan are fine: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-SNAPSHOTe0c278a054.fix(ArcadeData#11578): an index key of an undeclared property holds t…
fix(ArcadeData#11578): a list holding arrays keys by its content, and…
fix(#11578): an index key of an undeclared property holds the text of…
test(#11777): pin canonical list keys on undeclared-property indexes …
fix(#12160, #12233): an undeclared-property index written by an older…