Repository navigation
Description
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. Flagged during review: #5854 (comment)
The gap
Before PR #5854, SELECT ... FROM Type WHERE @rid = ? fell through to FetchFromTypeWithFilterStep, which is cacheable (canBeCached() == true) - it stores the WhereClause AST and re-evaluates it fresh against bound parameters on every execution, so repeated executions with different bound RIDs reuse the same cached plan.
After PR #5854, the same query now takes FetchFromRidsStep, which 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 now re-plans from scratch every execution instead of hitting db.getExecutionPlanCache().
This is almost certainly still a net perf win overall - an O(k) direct fetch plus a full replan is far cheaper than a cached plan reused to drive an O(n) scan - and it's not a new category of gap: every other FetchFromRidsStep call site (FROM [#1:0, #1:1], a bind-parameter/variable RID target, a function-call target) is already non-cacheable today. But it does mean this specific rewrite trades away plan-cache reuse that previously existed for the @rid = ? / @rid IN ? shape.
Suggested direction
Make FetchFromRidsStep (or a variant used by this rewrite) cacheable by storing a re-resolvable reference to the bind parameter/expression - mirroring how FetchFromTypeWithFilterStep.copy() re-attaches its WhereClause - rather than baking resolved RID values into the step at plan-build time. That would let parameterized RID lookups get both the O(k) fetch and cached-plan reuse.
Worth measuring first: confirm the replan cost is actually non-negligible relative to the O(k) fetch before spending effort here - it may not be worth the added complexity.
Where to look
SelectExecutionPlanner.handleTypeWithRidFilter/extractRidEqualityOrInList(introduced in PR fix(sql): plan WHERE @rid = / IN [RIDs] as a direct RID fetch, not a full type scan #5854)FetchFromRidsStep(engine/src/main/java/com/arcadedb/query/sql/executor/FetchFromRidsStep.java)ExecutionStepInternal.canBeCached()default andSelectExecutionPlanner.createExecutionPlan's cache-put gate
Activity
fix(#5855): address review - split runtime RID resolution from build-…
fix(#5855): address second review pass - dedupe rawValue resolution, …
fix(#5855): re-enable plan cache for parameterized @Rid filters (#6113)