Skip empty ordering scans for a scoped numeric query - #2908
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe query planner adds a guarded upper-bound rewrite for a specific timestamp query shape. Tests verify the generated CTE and hints, rewrite gates, feature flags, and equivalence of paged results. ChangesNumeric upper-bound planning
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~30 minutes Change: Refactor Sequence Diagram(s)sequenceDiagram
participant QueryCompiler
participant apply-plan
participant numeric-upper-bound
participant PostgreSQL
QueryCompiler->>apply-plan: compile timestamp upper-bound query
apply-plan->>numeric-upper-bound: validate query and scan layout
numeric-upper-bound-->>apply-plan: return upper-bound CTE and exists predicate
apply-plan-->>QueryCompiler: return rewritten query plan
QueryCompiler->>PostgreSQL: execute rewritten SQL
PostgreSQL-->>QueryCompiler: return paged results
Merge Risk: ⚪ Minimal · up to The narrowly scoped query optimization retains equivalent paged results in the covered cases and respects existing hint-disable controls. No actionable merge risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
An allowlisted numeric query can scan the full ordering index when its filter has no matches. Add a one-row existence probe inside the same SQL statement so that PostgreSQL can skip that empty join. The original joins, result envelope and pagination remain in place; nonempty requests continue through the original plan.
The override requires the exact app and complete normalized query shape plus the measured schema, scan choices and SQL layout. Existing hint-disable controls bypass it. The precheck copies the filter predicates, so correctness does not depend on cached cardinality metadata remaining current until execution.
Validation: