8000 feat: selective B+Tree lookup in filter_facts_for_query (#208) by adityamukho · Pull Request #246 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat: selective B+Tree lookup in filter_facts_for_query (#208) - #246

Merged
adityamukho merged 9 commits into
mainfrom
feature/issue-208-selective-lookup
May 15, 2026
Merged

adityamukho merged 9 commits into
mainfrom
feature/issue-208-selective-lookup

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • Promotes get_facts_by_entity and get_facts_by_attribute from #[cfg(test)] to production code in graph/storage.rs
  • Adds selective_fact_fetch helper on DatalogExecutor that inspects query patterns for bound entity literals and attribute names, unions index-driven results (up to a threshold of 4 total lookups), and falls back to get_all_facts() when the threshold is exceeded or no bound values exist
  • Wires selective fetch into the (None, None) arm of filter_facts_for_query; as_of arms always use the full log for correctness
  • Adds btree_lookup/entity_point and btree_lookup/attribute_scan benchmark groups at 1k/10k/100k scale — baseline for Benchmark SIMD vectorization gains vs current scalar implementation #229 SIMD work

Test Plan

  • cargo test — all 795+ tests pass, zero failures
  • cargo clippy — clean
  • cargo fmt --check — clean
  • Entity-bound point query returns correct results via selective path
  • Attribute-bound query returns correct results via selective path
  • as_of queries still take full-scan path and return correct results
  • Benchmark groups compile and smoke-run without panics

Closes #208. Prerequisite for #229.

🤖 Generated with Claude Code

adityamukho and others added 9 commits May 15, 2026 10:45
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
)

Move get_facts_by_entity, get_facts_by_attribute, and
get_facts_by_entity_attribute from #[cfg(test)] to a production impl
block so they can be called from the query executor. Also promote the
resolve_fact_ref and next_string_prefix helper functions to production
scope. The five remaining test-only helpers stay in #[cfg(test)].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add `selective_fact_fetch` to `DatalogExecutor` and wire it into the
`(None, None)` arm of `filter_facts_for_query`. For rule-free queries
with ≤4 distinct bound entities/attributes, this skips the full
`get_all_facts()` scan in favour of targeted index lookups. Patterns
inside `not`/`not-join`/`or`/`or-join` bodies are included via
`collect_all_patterns` so the snapshot is always complete. Rule queries
continue to use the full scan since rules require the entire fact base.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
codecov Bot commented May 15, 2026
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/query/datalog/executor.rs 96.07% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit daa80a9 into main May 15, 2026
18 of 21 checks passed
@adityamukho
adityamukho deleted the feature/issue-208-selective-lookup branch May 15, 2026 09:11
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.

perf(post-1.0): B+Tree selective lookup for bound patterns

1 participant

0