Skip to content

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

Closed

Description

@lvca

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

Activity

  1. added this to the 26.9.1 milestone on Aug 7, 2026
  2. self-assigned this
    on Aug 12, 2026
  3. added
    in progress
    on Aug 12, 2026
  4. added 3 commits that reference this issue on Aug 12, 2026
  5. removed
    in progress
    on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions