Skip to content

feat(graph): Query Rewriting for Graph Optimization (Issue #250) - #4621

Merged
makr-code merged 3 commits into
developfrom
copilot/query-rewriting-for-graph-optimization
Apr 13, 2026
Merged

makr-code merged 3 commits into
developfrom
copilot/query-rewriting-for-graph-optimization

Conversation

Copilot AI commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Implements GraphQueryRewriter — an automatic, rule-based JSON plan transformer for graph query optimization. Operates on a pure JSON plan representation with no DB I/O; thread-safe and deterministic. Applies rules to a fixed point (max 5 iterations) with an optional wall-clock time budget.

New: GraphQueryRewriter

Five rewrite rules:

Rule Effect
PREDICATE_PUSHDOWN / PRUNE_EARLY Promotes vertex_filters → prune_conditions on graph_traversal nodes; pushes filter_scan predicates into child traversal
COMMON_SUBEXPRESSION Detects identical graph_traversal sub-trees, hoists to let_scope binding, replaces duplicates with ref nodes
JOIN_REORDERING Swaps traversal_join operands when right side has lower heuristic cardinality (depth × filter count)
MATERIALIZED_VIEW Tags traversal nodes with use_materialized_view: true for multi-access patterns; aggressive mode tags any depth ≥ 2
QUERY_DECOMPOSITION Splits multi_traversal (multi-start fan-out) into parallel_subqueries for concurrent execution

Additional API: estimateSpeedup(), explainRewrites(), addCustomRule() / clearCustomRules(), RewriteConfig (selective rule enable, aggressive mode, time limit), factory helpers (makeTraversalPlan, makeJoinPlan, makeMultiTraversalPlan, etc.).

GraphQueryRewriter rewriter;
auto plan = GraphQueryRewriter::makeTraversalPlan(
    "social", "person/123", "OUTBOUND", 1, 3,
    json::array({{"field","country"},{"op","eq"},{"value","USA"}}));

auto [rewritten, stats] = rewriter.rewrite(plan);
// rewritten["prune_conditions"] now contains the country filter for early pruning

std::cout << rewriter.explainRewrites(plan, rewritten);
// → PredicatePushdown: added 1 prune condition(s) to graph traversal node(s)

double speedup = rewriter.estimateSpeedup(plan, rewritten); // > 1.0

Files

  • New: include/graph/graph_query_rewriter.h, src/graph/graph_query_rewriter.cpp
  • New: tests/test_graph_query_rewriter.cpp — 38 unit tests (all acceptance criteria)
  • Modified: cmake/CMakeLists.txt — adds source to build; tests/CMakeLists.txt — adds test_graph_query_rewriter standalone CTest target
  • Updated: src/graph/ROADMAP.md (Phase 5 ✅), src/graph/FUTURE_ENHANCEMENTS.md, src/ROADMAP.md (row 250 ✅)

Linked Issues

Closes #250

Type of Change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Refactoring (non-breaking)
  • Documentation
  • Breaking change (requires MAJOR version bump — see VERSIONING.md)
  • Security fix
  • Other:

Breaking Change Checklist

  • MAJOR version bump planned in VERSION and CMakeLists.txt
  • Migration guide added in docs/migration/
  • Announcement prepared for GitHub Discussions (≥ 2 weeks before release)
  • CHANGELOG ### Removed / ### Changed section updated

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Benchmarks run (if performance-sensitive change)

38 unit tests in tests/test_graph_query_rewriter.cpp covering all acceptance criteria: per-rule correctness, RewriteStats population, estimateSpeedup > 1.0 after rewrites, explainRewrites content, custom rule hook, selective rule enablement via RewriteConfig::enabled_rules, and time-limit escape hatch.

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines (clang-format / clang-tidy)
  • Self-review completed
  • Documentation updated (if needed)
  • CHANGELOG.md updated under [Unreleased]
  • No new warnings introduced
  • Security-sensitive paths reviewed by security maintainer (if applicable)

Copilot AI linked an issue Apr 13, 2026 that may be closed by this pull request
14 tasks
Copilot AI changed the title [WIP] Implement query rewriting for graph optimization feat(graph): Query Rewriting for Graph Optimization (Issue #250) Apr 13, 2026
Copilot AI requested a review from makr-code April 13, 2026 12:31
@makr-code
makr-code marked this pull request as ready for review April 13, 2026 13:36
@makr-code
makr-code merged commit e9e9c80 into develop Apr 13, 2026
11 checks passed
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.

Query Rewriting for Graph Optimization

2 participants