You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cached SELECT statement AST is mutated for a $var target: subsequent reuse reads the wrong type (and a first-execution data race) #6669
SelectExecutionPlanner.init() aliases the statement's target without copying it, and a later planner rewrite mutates that shared node in place. Because the Statement object is cached (StatementCache) and shared across executions, a SELECT ... FROM $var whose $var resolves to a type name permanently pins the cached statement (and cached plan) to the first execution's type — a subsequent execution with a different $var binding reads the wrong type. Also a concurrent-first-execution data race on the shared AST.
info.target = this.statement.getTarget(); // L140 — ALIAS (no .copy())info.whereClause = ...getWhereClause().copy(); // L141 — every other clause IS copied
...
StringtypeName = info.target.getItem().getIdentifier().getStringValue(); // L823if (typeName.startsWith("$")) {
typeName = (String) context.getVariable(typeName);
info.target.getItem().setIdentifier(newIdentifier(typeName)); // L826 — mutates the SHARED cached AST node
}
SelectStatement builds the planner on the cached statement (new SelectExecutionPlanner(this), no copy), and a $var-only target reports isCacheable() == true.
Repro
In a script / prepared reuse under one SQL text:
LET $t = "Agent"; SELECT FROM $t WHERE ... → statement S cached; L826 overwrites S's FromItem identifier to "Agent"; plan cached.
Same SQL text with $t = "Queue" → the cached plan (bound to Agent) is returned, or the mutated S (identifier now literally "Agent", no longer $-prefixed) re-plans against Agent.
Expected rows from Queue; actual rows from Agent. Silent wrong result. Concurrent first-executions also race on S's shared FromItem via the unsynchronized setIdentifier.
Suggested fix
Copy the target in init() (info.target = statement.getTarget() == null ? null : statement.getTarget().copy();) so the $var rewrite mutates a per-planning copy; or resolve $var into info only, never into the shared node; or make a $var target non-cacheable in FromItem.isCacheable().
Scope / confidence
High on the code (the target is the one clause init() doesn't copy, and L826 writes the shared node). Requires a $-variable target bound to a type-name string, reused with a different binding under the same SQL text.
Confirmed and fixed. A SELECT FROM $var query (where the target type comes from a variable) could, in rare cases, get cached against the wrong type and return results from a previous execution's type instead of the current one, especially when the same query text runs repeatedly with different variable values.
❤️ 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.
Activity
fix(#6670): skip GAV expand-into fast path for while/maxDepth pattern…
docs(#6670,#6669): explain expand-into filter reuse and the unbounded…
fix(#6670): MatchGAVFusedStep has the same direction bug, found in re…
docs(#6669): correct which method mutates the $var target in place
Merge pull request #6706 from ArcadeData/fix/6670-6669-match-gav-and-…
lvca commentedon Aug 24, 2026
Confirmed and fixed. A
SELECT FROM $varquery (where the target type comes from a variable) could, in rare cases, get cached against the wrong type and return results from a previous execution's type instead of the current one, especially when the same query text runs repeatedly with different variable values.Fixed in #6706 (merged).
❤️ 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.
fix(ArcadeData#6670,ArcadeData#6669): correct MATCH GAV expand-into f…