Repository navigation
refactor(query): build_postings_table consumes the shared scan_postings stream (BR8 step 3 final) - #1559
Conversation
…gs stream (BR8 step 3 final) Extract scan_postings from collect_postings (the single posting scan: iterate + optional FROM/WHERE + accumulate balance/account_balance -> PostingContext); collect_postings becomes a thin wrapper computing the #1080 gates. build_postings_table now drives scan_postings(None, None, all-gates) and reads balance/account_balance from each context instead of its own accumulator loop, and its redundant date-sort is removed (the loader pre-sorts; the other scanners do not re-sort). One iteration, not two -- eliminating the duplicated accumulation that was the source of bug #2. No perf regression; #postings parity test + full query suite unchanged.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📊 Benchmark Results
vs main branch (2026-06-23)
What do these numbers mean?
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the query executor to centralize posting iteration/balance accumulation into a single shared scan (scan_postings), and updates the #postings system table builder to consume that shared scan instead of maintaining its own parallel posting loop. This reduces duplicated logic and keeps computed columns like running balances aligned across query paths.
Changes:
- Introduces
scan_postings(...)as the shared posting-iteration + running-balance accumulator used bycollect_postings. - Rewrites
build_postings_tableto consumescan_postings(None, None, true, true, false)and remove its redundant per-account/cumulative accumulators. - Removes the local transaction sorting in
build_postings_table, relying on directive order.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/rustledger-query/src/executor/system_tables.rs | #postings now consumes scan_postings output and drops duplicated balance accumulation/sorting logic. |
| crates/rustledger-query/src/executor/mod.rs | Factors shared posting scan logic behind scan_postings and routes collect_postings through it. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…scan invariants with expect Copilot: (1) account_balance is independent of WHERE, not FROM (the FROM clause is honored) — fix the comment; (2)/(3) scan_postings(None,None,..) is infallible and always sets directive_index, so use expect to assert those invariants instead of silently returning an empty table / attributing rows to directive 0.
|
All three addressed: (1) corrected the comment — |
What
Architecture-roadmap [XL/BR8] — step 3, final: the iterator merge. The two posting-source iterations are now one.
build_postings_table(the#postingstable) consumes the samescan_postingsstream the defaultSELECTpath uses, instead of re-implementing the iterate-postings + accumulate-balances loop.This is the structural dedup the audit's step 3 calls for — and it eliminates the duplicated balance-accumulation loop that was the source of bug #2 and the
type/cost_datedrift, replacing "two loops that must be kept in sync (and a test that catches it when they aren't)" with "one loop."How
scan_postings(from, where, needs_balance, needs_account_balance, where_reads_balance)fromcollect_postings— the single posting scan: iterate resolved directives, apply optionalFROM/WHERE, accumulate cumulativebalance+ per-accountaccount_balance, yield onePostingContextper posting.collect_postingsis now a thin wrapper that computes the WASM hangs when reading accounts from Assets #1080 gates from the query and calls it.build_postings_tablenow callsscan_postings(None, None, true, true, false)— every posting, no filter, both balances tracked — and readsbalance/account_balancestraight from eachPostingContext. Its ownaccount_balances/cumulative_balanceaccumulators are gone.build_postings_table's redundantsort_by_key(date)— the loader already sorts directives, and the other two scanners (collect_postings,build_balances_with_filter) rely on that pre-sorted order without re-sorting. This also makes the three consumers consistent.Safety
build_postings_tablealready paid the per-posting Inventory clone (the table materializesbalance/account_balance);collect_postings's WASM hangs when reading accounts from Assets #1080 gating is preserved (passed as explicit params).#postingsparity test (every projectable column, including the accumulated balances) passes against the rewritten table, and the fullrustledger-querysuite is unchanged —scan_postingswith no filter produces exactly the values the old inline loop did.Tests
#postingsparity harness + fullrustledger-querysuite pass; clippy--all-features --all-targets -D warnings+ fmt clean.🤖 Generated with Claude Code