Skip to content

fix(#5855): re-enable plan cache for parameterized @rid filters - #6113

Merged
robfrank merged 3 commits into
mainfrom
fix/5855-rid-filter-plan-cache
Aug 13, 2026
Merged

robfrank merged 3 commits into
mainfrom
fix/5855-rid-filter-plan-cache

Conversation

@robfrank

Copy link
Copy Markdown
Collaborator

Closes #5855

Context

PR #5854 (fixing #5824) rewrites WHERE @rid = <RID> / WHERE @rid IN [<RID list>] on a type
target into a direct FetchFromRidsStep fetch instead of a full type scan. That step resolves the
bound RID(s) at plan-construction time and bakes them into the step. FetchFromRidsStep doesn't
override canBeCached()/copy(), so it defaults to canBeCached() == false
(ExecutionStepInternal.java), making the whole plan non-cacheable. A "get by id" query executed
repeatedly with different bound RIDs re-plans from scratch every execution instead of hitting
db.getExecutionPlanCache().

Before PR #5854 the same query fell through to FetchFromTypeWithFilterStep, which is cacheable:
it stores the WhereClause AST and re-evaluates it fresh against bound parameters on every
execution.

Fix

Mirror FetchFromTypeWithFilterStep's pattern: instead of baking resolved RID values into
FetchFromRidsStep at plan-build time, add a variant that stores the original BooleanExpression
(the @rid = ? / @rid IN ? condition) and re-resolves it lazily against the live
CommandContext on the first pull of every execution, including a cache-hit re-execution with
different bound parameters. That step overrides canBeCached() to return true and copy() to
carry the (immutable) condition forward into the copy handed out by
ExecutionPlanCache.get()/put().

The legacy FetchFromRidsStep(Iterable<RID>, CommandContext) constructor (used by every other
call site: FROM [#1:0, #1:1], a bind-parameter/variable RID target, a function-call target,
FetchEdgesFromVertexStep's sibling paths, etc.) is untouched and stays non-cacheable, matching
the issue's own scoping note that those call sites were already non-cacheable before PR #5854.

SelectExecutionPlanner.handleTypeWithRidFilter now always chains the deferred-resolution step
once the condition is confirmed resolvable in shape (extractRidEqualityOrInList(...) != null)
rather than short-circuiting to EmptyStep when the value the condition resolves to at this
particular build happens to be empty (e.g. an IN-list bound to null on the very first
execution). Baking that build-time "this execution's RIDs happen to be empty" fact into a cached,
reused plan would be wrong for a later execution bound to a non-empty list - EmptyStep itself
carries the comment "DON'T TOUCH! ... this execution plan cannot be cached" for exactly this
reason. Resolving to an empty RID set inside FetchFromRidsStep.syncPull produces the same
zero-row result without that hazard, on every execution.

extractRidEqualityOrInList moved from private to package-private static so
FetchFromRidsStep (same package) can call it during lazy resolution.

A test-only race found and fixed along the way

Running the new tests as part of the wider com.arcadedb.query.sql.** suite (not the isolated
class) surfaced one flaky failure in ridInListBoundParameterPlanIsCacheableAndReresolvesOnReuse:
assertThat(db.getExecutionPlanCache().contains(sql)).isTrue() occasionally failed.

Root cause: RidInScanOptimizationTest.beginTest() creates types, which calls
ExecutionPlanCache.invalidate() (stamps lastInvalidation via System.currentTimeMillis()).
SelectExecutionPlanner.createExecutionPlan's cache-put guard requires
getLastInvalidation() < planningStart before it will cache a freshly-built plan. On a hot/warmed
JVM, beginTest()'s schema setup and the test's first query can land in the same millisecond tick,
so a plan legitimately built after the invalidation gets skipped by the guard anyway - a
pre-existing, unrelated millisecond-resolution artifact in SelectExecutionPlanner/
ExecutionPlanCache (predates this PR). It only became reachable here because this PR is what
makes @rid plans cacheable in the first place, so this is the first test to exercise the guard
for this step type.

Not fixing the production guard (shared, out of scope, and the actual functional correctness of
query results is unaffected either way - only the caching optimization is occasionally skipped).
Instead, beginTest() now waits for the millisecond clock to tick forward before returning, so the
setup and the first query can never land in the same tick. Verified: re-ran the exact suite that
exposed the race (mvn -pl engine test -Dtest='com.arcadedb.query.sql.**') after the fix - clean,
2485/2485, 0 failures.

Test plan

  • planUsesFetchFromRidsStepForEquality / ...ForBracketInList / etc. (pre-existing SQL: WHERE @rid IN [list] is planned as a full type scan, so resolving k RIDs costs O(n) #5824 tests):
    keep passing unchanged - the rewrite's plan shape and results are untouched.
  • New: a bound-parameter @rid = ? plan reports canBeCached() == true and is actually present in
    db.getExecutionPlanCache() after one execution.
  • New: the same query text executed twice with two different bound RIDs returns the record
    matching each execution's own bound value, not a stale RID baked in from the first (cached) plan
    build - this is the actual regression the issue describes.
  • New: same for @rid IN ? bound to two different lists across two executions.
  • New: an IN ? bound to an empty list on the first execution, then to a non-empty list on the
    second (same cached plan reused), returns zero rows the first time and the matching rows the
    second time - pins the EmptyStep-caching hazard called out above.
  • Full com.arcadedb.query.sql.** suite (2485 tests) run clean after the fix.

PR #5854 (fixing #5824) rewrote WHERE @Rid = <RID> / WHERE @Rid IN
[<RID list>] into a direct FetchFromRidsStep fetch, but that step
resolves the bound RID(s) at plan-build time and bakes them in, and
never overrode canBeCached()/copy() - so the whole plan defaulted to
non-cacheable and a "get by id" query re-planned from scratch on
every execution instead of hitting db.getExecutionPlanCache().

Mirror FetchFromTypeWithFilterStep's pattern: add a package-private
BooleanExpression-based FetchFromRidsStep constructor that stores the
original @Rid = ? / @Rid IN ? condition and re-resolves it lazily
against the live CommandContext on the first pull of every execution,
including a cache-hit re-execution with different bound parameters.
That variant overrides canBeCached()=true and copy(); the legacy
Iterable<RID> constructor (every other call site) is untouched and
stays non-cacheable, matching the issue's own scoping note.

SelectExecutionPlanner.handleTypeWithRidFilter now always chains the
deferred-resolution step once the condition is resolvable in shape,
instead of short-circuiting to EmptyStep when this particular build's
resolved RID list happens to be empty - EmptyStep is explicitly
non-cacheable for exactly this "bakes in a build-time fact" hazard,
and baking "empty on this build" into a reused plan would be wrong
for a later execution bound to a non-empty list.

extractRidEqualityOrInList moved from private to package-private
static so FetchFromRidsStep can call it during lazy resolution.

Also fixes a millisecond-resolution test race exposed while running
the new tests as part of the wider com.arcadedb.query.sql.** suite:
RidInScanOptimizationTest.beginTest() creates types, which invalidates
the plan cache (ExecutionPlanCache.lastInvalidation, stamped via
System.currentTimeMillis()); on a hot/warmed-up JVM the type creation
and the test's first query can land in the same millisecond tick,
so SelectExecutionPlanner's cache-put guard (which requires
planningStart to be strictly after lastInvalidation) skips caching a
plan that was legitimately built after the invalidation. This only
became reachable once these @Rid plans became cacheable. Not a bug in
the fix itself; beginTest() now waits for the millisecond clock to
tick forward before returning.
@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

codacy-production Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Coverage 81.48% diff coverage · -6.52% coverage variation

Metric Results
Coverage variation ✅ -6.52% coverage variation
Diff coverage ✅ 81.48% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c66f0c8) 155549 121937 78.39%
Head commit (845b9b8) 188489 (+32940) 135467 (+13530) 71.87% (-6.52%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6113) 54 44 81.48%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@claude

claude Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review

Nice, well-documented fix for the core caching issue (#5855), and the PR description/commit message are unusually thorough. I dug into FetchFromRidsStep's lazy re-resolution and extractRidEqualityOrInList's reuse across build-time and run-time, and found one correctness regression worth fixing before merge, plus a couple of smaller notes.

Correctness bug: mixed valid/invalid IN list silently drops matches on cache reuse

extractRidEqualityOrInList (SelectExecutionPlanner.java:2078-2125) was written as a speculative, build-time-only check: if any element of the IN-list can't be resolved to a RID, the whole method returns null, and the caller (handleTypeWithRidFilter) falls back to a full type scan with normal per-record IN semantics - which correctly matches whichever elements are RIDs and just ignores the ones that aren't.

This PR now also calls the same method from FetchFromRidsStep.syncPull (FetchFromRidsStep.java:69-73) as the final runtime answer on every cache-hit re-execution, with no such fallback:

final List<RID> resolved = SelectExecutionPlanner.extractRidEqualityOrInList(ridCondition, context);
this.rids = resolved == null ? List.of() : resolved;

Repro:

String sql = "SELECT FROM Doc WHERE @rid IN ?";
db.query("sql", sql, List.of(validRid1, validRid2));      // (1) builds & caches FetchFromRidsStep plan
db.query("sql", sql, List.of(validRid1, "not-a-rid"));    // (2) cache hit, reuses the plan

At (1) the plan is built and cached because every element resolves. At (2), the plan is reused from db.getExecutionPlanCache(), but toRid("not-a-rid", ...) returns null inside the loop, so the entire extractRidEqualityOrInList call returns null (not "the elements that did resolve") - syncPull then treats that as List.of() and the query returns 0 rows, even though validRid1 is a real match and the equivalent uncached/fresh-build query (or the pre-#5854 FetchFromTypeWithFilterStep path) would correctly return 1 row.

This is a real behavioral divergence, not just a missed optimization: the result differs based on whether this exact SQL text happened to be cached from a prior execution with an all-resolvable list. It's also easy to hit in practice - e.g. an app running WHERE @rid IN ? in a loop where an occasional id in the bound list fails to parse as a RID.

I'd suggest resolving whatever can be resolved and skipping the rest (mirroring how a normal IN scan behaves), rather than treating "any unresolvable element" as "resolve to nothing." The build-time-only "is this shape even a candidate" check and the runtime "give me the final RID set" call have different correctness requirements now that they share one method - worth splitting or at least changing the loop to skip-and-continue instead of abort-to-null when called from syncPull.

None of the new tests in RidInScanOptimizationTest cover a partially-resolvable bound list across cache reuse, so this slipped through - worth adding as a regression test alongside the existing ones (which are otherwise nicely targeted at the caching hazards this PR is fixing).

Minor: exception-swallowing in extractRidEqualityOrInList now also happens at runtime

The in.getRightMathExpression().execute(...) branch catches Exception and returns null, documented as "not resolvable at plan time." That's a reasonable thing to swallow during a speculative build-time check (falls back to a normal scan that will genuinely re-evaluate and, if warranted, throw). But since this method is now also invoked from syncPull at real execution time, an exception thrown by a UDF/expression on a cache-hit re-execution gets silently swallowed into "0 rows" instead of propagating as a query error - a behavior change from both the pre-#5854 world and from a fresh (uncached) build of the same query. Narrow edge case (only the non-list, non-bind-param IN <expr> shape), but worth a thought given it changes error-reporting semantics, not just performance.

Nit: first-execution parameter shape permanently decides the cached plan

Since the plan cache key is the SQL text only, whichever bound value happens to build the plan first decides forever (until invalidation) whether that text gets the RID-optimized step or falls back to a full scan. E.g. if the very first call to WHERE @rid = ? binds null, extractRidEqualityOrInList returns null at build time (no List.of() allowance for the = case, unlike the explicit empty-list handling on the IN path), so the optimization never kicks in for that text again even when later callers always bind valid RIDs. This looks like a pure performance miss rather than a correctness issue (comparing a real RID to null/garbage via the normal scan path also yields 0 rows), so probably fine to leave as a known limitation of text-keyed plan caching - just flagging in case it's worth a follow-up issue.

Everything else

  • The canBeCached()/copy() overrides on FetchFromRidsStep correctly mirror FetchFromTypeWithFilterStep's pattern, and copy()'s UnsupportedOperationException guard for the legacy (non-cacheable) constructor is consistent with ExecutionPlanCache only ever copying steps that already reported canBeCached() == true.
  • Widening extractRidEqualityOrInList from private to package-private is appropriately minimal (same package only).
  • The EmptyStep-caching hazard fix (always chaining FetchFromRidsStep instead of short-circuiting to a build-time-empty EmptyStep) is correct and well explained, and is exercised by ridInListEmptyThenNonEmptyBoundParameterAcrossCachedReuseStaysCorrect.
  • The test-race fix in RidInScanOptimizationTest.beginTest() is a reasonable, narrowly-scoped test-only workaround for the millisecond-resolution lastInvalidation guard, and the PR is explicit about not touching the shared production guard - good call to keep that out of scope.
  • No new dependencies, no System.out debug leftovers spotted, code style matches the surrounding file.

Overall this is a solid, well-reasoned fix for the caching gap with good test coverage of the scenarios it explicitly targets. The mixed-valid/invalid-list issue above is the one I'd want addressed (or explicitly scoped out with a comment/issue) before merging, since it turns a caching optimization into a source of silently wrong query results.

…time shape check

Review on PR #6113 found a real correctness regression: extractRidEqualityOrInList
served two different callers with incompatible contracts. At build time
(SelectExecutionPlanner.handleTypeWithRidFilter) it's a speculative "is this shape
even a candidate" check where aborting the whole list to null on one unresolvable
element is correct, because the caller falls back to a normal scan that evaluates
the condition itself. But this PR also called the exact same method from
FetchFromRidsStep.syncPull as the FINAL runtime answer on every cache-hit
re-execution - with no scan fallback left. A list with one unresolvable element
(e.g. "@Rid IN [validRid, notARid]") silently returned zero rows instead of
matching the resolvable RID, a real behavioral divergence depending on whether
the plan happened to be reused from the cache.

Split into two methods: extractRidEqualityOrInList keeps its original abort-to-null
behavior for the build-time shape check, and a new resolveRidEqualityOrInListAtRuntime
resolves whatever it can and skips unresolvable elements, mirroring how a normal
per-record IN scan treats a non-RID element. The runtime variant also no longer
swallows an exception from evaluating the right-hand expression into "no rows" -
that's a genuine execution-time error now, not "unknowable at plan time".

Added ridInListWithOneUnresolvableElementStillMatchesTheResolvableOnesOnCacheReuse,
reproducing the reviewer's exact repro: confirmed it fails against the pre-fix
code (empty result instead of the one valid match) and passes after the fix.
Re-ran com.arcadedb.query.sql.** (2486 tests) clean, 0 failures.
@robfrank

Copy link
Copy Markdown
Collaborator Author

Addressed the correctness bug: split `extractRidEqualityOrInList` (build-time shape check, unchanged) from a new `resolveRidEqualityOrInListAtRuntime` (used by `FetchFromRidsStep.syncPull`), which resolves whatever it can and skips unresolvable list elements instead of aborting the whole result to empty, and no longer swallows a right-hand-expression exception into "0 rows" at runtime.

Added `ridInListWithOneUnresolvableElementStillMatchesTheResolvableOnesOnCacheReuse`, reproducing your exact repro - confirmed it fails against the pre-fix code (empty result) and passes after the fix. Re-ran `com.arcadedb.query.sql.**` (2486 tests) clean.

The two minor notes (exception-propagation semantics, and text-keyed-cache-decided-by-first-execution as a known limitation) are addressed by the same change / left as documented limitations respectively, per your own framing of them as non-blocking.

@claude

claude Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review

Went through both commits (the caching fix plus the follow-up "split runtime resolution from build-time shape check"). Overall this is a well-reasoned fix with good test coverage, and the second commit shows the kind of self-review I'd want to see (catching the IN [validRid, "notARid"] cache-reuse regression before merge). A few things worth a look:

Design note: the cached plan's shape is still decided by the first execution's bound value

extractRidEqualityOrInList (the build-time shape check) resolves the bound parameter's actual value to decide whether to emit FetchFromRidsStep at all - if the very first execution of a given statement text binds something that doesn't resolve cleanly (e.g. @rid = ? bound to null, or @rid IN ? bound to a list with one non-RID element mixed in), it returns null and handleTypeWithRidFilter falls back to a normal type scan for that build.

Before this PR that didn't matter, since nothing was cached - every execution re-ran the shape check against its own live value. Now that the resulting plan is cached under the raw statement text (SelectExecutionPlanner.java:2029 / 2041), an unlucky first bind permanently locks that statement text into the slow scan path for the lifetime of the cache entry (until the next ExecutionPlanCache.invalidate()), even though every later execution binds a perfectly good RID. It's not a correctness bug - the scan fallback still evaluates the condition correctly - but it can silently defeat the exact "get-by-id stays fast under caching" goal the PR sets out to fix, for call patterns where the first invocation happens to be atypical (e.g. a generic "get by id or null" helper that's sometimes called with a null id first). Might be worth a short comment noting this tradeoff, or reconsidering later, since it's a subtle interaction with the change rather than something a reviewer would find in the diff alone.

Minor: unused import

FetchFromRidsStep.java adds import java.util.List; but nothing in the file references List as a type - resolveRidEqualityOrInListAtRuntime(...)'s List<RID> return is only ever assigned into the Iterable<RID> rids field. Looks like a leftover from an earlier draft.

Minor: "exceptions propagate at runtime" isn't quite true for every path

resolveRidEqualityOrInListAtRuntime's Javadoc says an exception while evaluating the right-hand expression "is a genuine execution-time error now... and is left to propagate," but that's only true for the in.getRightMathExpression().execute(...) branch. The equality branch and each per-element IN-list expression still go through extractRidValue, which unconditionally swallows any exception into null (silently "no match") in both the build-time and runtime callers. Probably harmless in practice (fails safe to zero rows rather than throwing), but the Javadoc overstates the guarantee and it's an easy thing to trip over if someone later relies on that propagation for the equality path too.

Nit: duplicated "resolve the IN right-hand side" logic

extractRidEqualityOrInList and resolveRidEqualityOrInListAtRuntime share ~15 lines of identical logic for turning in.right / in.getRightMathExpression() / in.getRightParam() into rawValue, differing only in the try/catch around the math-expression branch and in abort-vs-skip handling of unresolvable elements. Given that the two methods having slightly different contracts is exactly what caused the bug fixed in the second commit, factoring the shared "compute rawValue" step into one helper would make it harder for the two to drift apart silently again in a future change.

Nit: FQN instead of import in the new test

ridInListWithOneUnresolvableElementStillMatchesTheResolvableOnesOnCacheReuse uses java.util.Arrays.asList(...) inline rather than importing java.util.Arrays, which goes against the project convention (CLAUDE.md: "don't use fully qualified names if possible, always import the class and just use the name").

What looks solid

  • copy(null) on the cache-put path is handled correctly since syncPull always uses the live context parameter rather than the stored field, mirroring FetchFromTypeWithFilterStep's pattern.
  • Each cache hit/put path produces an independent step copy (ExecutionPlanCache.get/put), so the mutable rids/iterator fields on FetchFromRidsStep aren't shared across concurrent executions of the same cached plan - good, since those fields did become non-final in this change.
  • Dropping the build-time EmptyStep short-circuit in favor of always resolving at runtime is the right call given EmptyStep's own "DON'T TOUCH, non-cacheable" comment - nice catch tying that back to the actual hazard.
  • Test coverage is thorough: cacheability assertions, re-resolution across different bound RIDs, the empty-then-nonempty hazard, the partially-unresolvable-list regression, and combining with a remaining filter after the fetch step.

…fix nits

- Factor the shared "compute the IN right-hand raw value" logic out of
  extractRidEqualityOrInList and resolveRidEqualityOrInListAtRuntime into
  one resolveInRightHandRawValue helper, per review: the two methods
  having slightly different contracts is exactly what caused the bug
  fixed in the prior commit, so keep them from drifting apart silently
  again. The math-expression evaluation is left uncaught in the shared
  helper; each caller applies its own policy (catch-and-fallback at
  build time, propagate at runtime).
- Removed FetchFromRidsStep.java's now-unused `import java.util.List`.
- RidInScanOptimizationTest: import java.util.Arrays instead of the FQN.
- Corrected resolveRidEqualityOrInListAtRuntime's Javadoc, which
  overstated the propagation guarantee: only the getRightMathExpression()
  path can throw and propagate; extractRidValue (equality operand, each
  IN-list literal item) still fails safe to "no match" on any exception
  in both methods, unchanged from before this split.
- Documented the known tradeoff at the build-time call site: the cached
  plan's shape is decided by the first execution's bound value, so an
  atypical first bind (null, or one bad IN-list element) locks that
  statement text into the scan fallback until the next cache
  invalidation - not a correctness issue, just a missed optimization
  for that call pattern.

Re-ran com.arcadedb.query.sql.** (2486 tests) clean, 0 failures.
@claude

claude Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review

Solid fix, and the PR description/commit history shows the author already caught and fixed a real correctness bug (the IN-list-with-one-bad-element regression) and a test-only race in self-review before this was posted. I read through the diff plus the surrounding classes it mirrors (FetchFromTypeWithFilterStep, ExecutionPlanCache, SelectExecutionPlan.copy/copyOn) and didn't find any remaining correctness issues. Notes below are informational/minor.

Correctness

  • The canBeCached()/copy() pair on FetchFromRidsStep correctly follows the existing FetchFromTypeWithFilterStep pattern: copy() rebuilds from the immutable ridCondition, never from the (possibly stale) resolved rids. Verified SelectExecutionPlan.copyOn calls step.copy(ctx) for every step, so a cache hit gets a fully independent FetchFromRidsStep instance per execution — no shared mutable state across concurrent/re-entrant pulls.
  • reset() correctly defers re-resolution (sets iterator = null only) rather than resolving eagerly, so a step reused via reset() (e.g. inside a nested-loop/subquery re-execution) picks up that call's own live CommandContext/bound parameters, not whichever context happened to trigger reset().
  • The build-time vs. runtime split (extractRidEqualityOrInList aborts-to-null on one bad element and falls back to a scan; resolveRidEqualityOrInListAtRuntime skips bad elements since there's no fallback once FetchFromRidsStep is committed) is the right fix for the bug the second commit describes, and ridInListWithOneUnresolvableElementStillMatchesTheResolvableOnesOnCacheReuse pins exactly that regression.
  • copy() throwing UnsupportedOperationException when ridCondition == null is dead code today — SelectExecutionPlanner.createExecutionPlan only calls put() (and therefore copy()) after checking selectExecutionPlan.canBeCached(), and the legacy-constructor step reports canBeCached() == false. Fine as a defensive invariant, just flagging it's unreachable via the current call graph rather than exercised by a test.

Minor / non-blocking

  • Double evaluation on a cache-miss build: handleTypeWithRidFilter now calls extractRidEqualityOrInList purely for the shape check and discards the result, then FetchFromRidsStep.syncPull calls resolveRidEqualityOrInListAtRuntime on the first pull of that same (uncached) execution — so the RID resolution logic runs twice on every cache-miss build. Both paths call resolveInRightHandRawValue, which for the getRightMathExpression() branch executes the right-hand expression. If that expression could have a side effect (e.g. a UDF), it'd run twice on a fresh build. This is almost certainly fine in practice (SQL expressions here are expected to be pure), and it's a pre-existing shape of the code (the old version also called extractRidEqualityOrInList once at build time), just noting the new runtime path adds a second evaluation that didn't exist before.
  • The "known tradeoff" comment (an atypical first bind — null @rid, or one bad IN-list element — locks the statement text into the scan fallback until the next cache invalidation) is clearly documented in three places (planner comment, Javadoc, PR description). Worth keeping in mind if this ever needs to be revisited, but it's a reasonable scope boundary for this fix.
  • RidInScanOptimizationTest.beginTest()'s Thread.onSpinWait() busy-wait to dodge the millisecond-clock race is a pragmatic fix and well-commented; bounded to at most ~1ms so it won't slow the suite down.

Test coverage

Good coverage of the actual regression: cacheability assertions (canBeCached() + getExecutionPlanCache().contains(...)), re-resolution across different bound values for both = and IN, the empty-then-non-empty cache-reuse hazard that motivated dropping the EmptyStep short-circuit, the partially-resolvable IN-list regression found in review, and a remaining-filter-after-cached-step check. I don't see a gap here.

No performance or security concerns — this only removes redundant re-planning work and doesn't change what records a query can return (confirmed the RID-existence check, type filter, and partition-pruning-bypass behavior in FetchFromRidsStep/FilterByTypeStep are untouched).

@robfrank

Copy link
Copy Markdown
Collaborator Author

Review is clean, remaining notes are all explicitly non-blocking (double-evaluation on cache-miss builds is pre-existing shape, not a regression; the documented first-bind tradeoff is an accepted scope boundary). Leaving this for merge review.

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.11111% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.67%. Comparing base (c66f0c8) to head (845b9b8).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...edb/query/sql/executor/SelectExecutionPlanner.java 58.97% 7 Missing and 9 partials ⚠️
...arcadedb/query/sql/executor/FetchFromRidsStep.java 66.66% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6113      +/-   ##
==========================================
+ Coverage   69.62%   69.67%   +0.05%     
==========================================
  Files        1818     1821       +3     
  Lines      155549   156146     +597     
  Branches    32848    32959     +111     
==========================================
+ Hits       108299   108798     +499     
- Misses      33651    33677      +26     
- Partials    13599    13671      +72     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-up (#5824): parameterized WHERE @rid = ? / IN ? no longer hits the plan cache

1 participant