Skip to content

feat: cysql - optimize traversal lowering and predicate planning#104

Merged
zinic merged 1 commit into
SpecterOps:mainfrom
zinic:main
Jul 10, 2026
Merged

feat: cysql - optimize traversal lowering and predicate planning#104
zinic merged 1 commit into
SpecterOps:mainfrom
zinic:main

Conversation

@zinic

@zinic zinic commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Improves PostgreSQL Cypher planning and SQL emission for common traversal-heavy queries.

Key changes include:

  • Lower anonymous directed *1..1 and *2..2 ranges to fixed traversal steps instead of recursive CTEs while preserving relationship uniqueness and path projections.
  • Track optimizer targets independently from generated traversal hops so pruning, predicate placement, suffix pushdown, and later source steps remain aligned.
  • Lower predicate-only ANY/NONE expressions over relationships(p) to EXISTS/NOT EXISTS checks against path edge IDs, avoiding unnecessary path relationship materialization and unnest scans.
  • Reorder dependency-safe non-optional match clauses using selectivity while retaining stable ordering and pinning unresolved dependencies.
  • Keep undirected exact ranges on the existing path until fixed-hop endpoint pairing can be implemented safely.
  • Expand optimizer diagnostics, regression coverage, translation fixtures, plan-corpus guidance, and PostgreSQL development documentation.

Resolves: N/A

Type of Change

  • Chore (a change that does not modify the application functionality)
  • Bug fix (a change that fixes an issue)
  • New feature / enhancement (a change that adds new functionality)
  • Refactor (no behaviour change)
  • Test coverage
  • Build / CI / tooling
  • Documentation

Testing

  • Unit tests added / updated
  • Integration tests added / updated
  • Full test suite run (make test_all with CONNECTION_STRING set)

Validation performed:

  • make test
  • Full Neo4j make test_all run
  • PostgreSQL unit phase and full integration suite.

Screenshots (if appropriate):

N/A

Driver Impact

  • PostgreSQL driver (drivers/pg)
  • Neo4j driver (drivers/neo4j)

Checklist

  • Code is formatted
  • All existing tests pass
  • go.mod / go.sum are up to date if dependencies changed

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added optimizer support for exact-length relationship expansions.
    • Added lowering for ANY/NONE path-relationship predicates.
    • Improved PostgreSQL endpoint handling for startNode()/endNode() with edge-composite typing.
  • Bug Fixes

    • Improved traversal decision targeting and safer handling of traversal steps/suffix pushdown.
    • Improved relationship pattern translation for multi-edge expansion cases.
  • Documentation

    • Updated repository overview and added Quick Start and contributor workflow guides.
    • Added/expanded PostgreSQL translation, plan-capture, and repository map documentation.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@zinic, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 12947498-2283-4d6e-82d7-85b342a7e19e

📥 Commits

Reviewing files that changed from the base of the PR and between bf7f9a6 and f2c7e65.

📒 Files selected for processing (26)
  • README.md
  • cmd/plancorpus/README.md
  • cypher/models/pgsql/README.md
  • cypher/models/pgsql/optimize/OPTIMIZATION_PLAN.md
  • cypher/models/pgsql/optimize/lowering.go
  • cypher/models/pgsql/optimize/lowering_plan.go
  • cypher/models/pgsql/optimize/optimizer_test.go
  • cypher/models/pgsql/optimize/reordering.go
  • cypher/models/pgsql/test/translation_cases/pattern_binding.sql
  • cypher/models/pgsql/test/translation_cases/shortest_paths.sql
  • cypher/models/pgsql/translate/function.go
  • cypher/models/pgsql/translate/function_test.go
  • cypher/models/pgsql/translate/match.go
  • cypher/models/pgsql/translate/model.go
  • cypher/models/pgsql/translate/optimizer_safety_test.go
  • cypher/models/pgsql/translate/path_functions.go
  • cypher/models/pgsql/translate/predicate_placement.go
  • cypher/models/pgsql/translate/projection.go
  • cypher/models/pgsql/translate/quantifiers.go
  • cypher/models/pgsql/translate/relationship.go
  • cypher/models/pgsql/translate/renamer.go
  • cypher/models/pgsql/translate/renamer_test.go
  • cypher/models/pgsql/translate/translator.go
  • cypher/models/pgsql/translate/traversal.go
  • docs/development.md
  • docs/postgresql_translation.md

Walkthrough

This PR adds PostgreSQL optimizer decisions for exact relationship ranges and path predicates, integrates them into translation and traversal handling, updates clause reordering, expands SQL and optimizer tests, and reorganizes development and translation documentation.

Changes

PostgreSQL optimization and translation

Layer / File(s) Summary
Optimization decision planning
cypher/models/pgsql/optimize/lowering.go, cypher/models/pgsql/optimize/lowering_plan.go, cypher/models/pgsql/optimize/reordering.go
Adds exact-range and path-relationship lowering decisions, dependency-aware selectivity reordering, and lowering-plan reporting.
Translation state and exact traversal
cypher/models/pgsql/translate/model.go, cypher/models/pgsql/translate/translator.go, cypher/models/pgsql/translate/relationship.go, cypher/models/pgsql/translate/traversal.go
Propagates optimization decisions, expands eligible exact ranges into fixed traversal steps, tracks source targets, and updates traversal decision lookup and suffix pushdown.
Path predicates and expression rewriting
cypher/models/pgsql/translate/quantifiers.go, cypher/models/pgsql/translate/path_functions.go, cypher/models/pgsql/translate/function.go, cypher/models/pgsql/translate/projection.go, cypher/models/pgsql/translate/renamer.go
Adds edge-ID arrays, EXISTS/NOT EXISTS quantifier lowering, edge-composite endpoint arguments, and array-literal frame-binding rewrites.
Validation
cypher/models/pgsql/optimize/optimizer_test.go, cypher/models/pgsql/translate/optimizer_safety_test.go, cypher/models/pgsql/translate/function_test.go, cypher/models/pgsql/test/translation_cases/*, cypher/models/pgsql/translate/renamer_test.go
Tests optimizer decisions, generated SQL, endpoint functions, conservative reordering, and nested array-literal rewriting.
Documentation
README.md, docs/*, cmd/plancorpus/README.md, cypher/models/pgsql/README.md
Adds quick-start, workflow, plan-corpus, repository-map, optimizer, and PostgreSQL translation documentation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CypherQuery
  participant BuildLoweringPlan
  participant PostgreSQLTranslator
  participant PostgreSQLSQL
  CypherQuery->>BuildLoweringPlan: analyze exact ranges and path predicates
  BuildLoweringPlan->>PostgreSQLTranslator: provide lowering decisions
  PostgreSQLTranslator->>PostgreSQLTranslator: build fixed traversals and edge-ID predicates
  PostgreSQLTranslator->>PostgreSQLSQL: emit joins and EXISTS/NOT EXISTS SQL
Loading

Possibly related PRs

Suggested labels: go

Suggested reviewers: urangel, superlinkx

Poem

I hop through ranges, one hop, two,
With edge-ID trails in a join-built view.
EXISTS blooms where counts once grew,
Docs map the paths for rabbits too.
Thump, thump—optimized anew!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: optimizing traversal lowering and predicate planning.
Description check ✅ Passed The description matches the template and includes the required sections, testing details, driver impact, and checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zinic zinic changed the title perf(pgsql): optimize traversal lowering and predicate planning perf: optimize traversal lowering and predicate planning Jul 10, 2026
@zinic zinic changed the title perf: optimize traversal lowering and predicate planning feat: cysql - optimize traversal lowering and predicate planning Jul 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cypher/models/pgsql/README.md`:
- Around line 4-6: Update the documentation text in the README so the reference
on line 5 consistently uses the exact capitalization “openCypher,” matching the
surrounding terminology.

In `@docs/development.md`:
- Around line 3-4: Update the documentation scope description in
docs/development.md to accurately state that the top-level README keeps the main
quick-start commands and links to detailed documentation, or move the referenced
workflow sections such as benchmarks and plan-corpus usage out of README.md.

In `@docs/postgresql_translation.md`:
- Around line 86-88: The PostgreSQL validation section embeds undated,
changeable corpus counts. Update the documentation near the
`ExactRangeExpansion` and `PathRelationshipPredicate` summary by removing the
specific totals, or replace them with a clearly labeled dated/generated snapshot
reference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78dcc54c-023e-45fc-94a2-86fc47bdc392

📥 Commits

Reviewing files that changed from the base of the PR and between 403c928 and 602ca2a.

📒 Files selected for processing (26)
  • README.md
  • cmd/plancorpus/README.md
  • cypher/models/pgsql/README.md
  • cypher/models/pgsql/optimize/OPTIMIZATION_PLAN.md
  • cypher/models/pgsql/optimize/lowering.go
  • cypher/models/pgsql/optimize/lowering_plan.go
  • cypher/models/pgsql/optimize/optimizer_test.go
  • cypher/models/pgsql/optimize/reordering.go
  • cypher/models/pgsql/test/translation_cases/pattern_binding.sql
  • cypher/models/pgsql/test/translation_cases/shortest_paths.sql
  • cypher/models/pgsql/translate/function.go
  • cypher/models/pgsql/translate/function_test.go
  • cypher/models/pgsql/translate/match.go
  • cypher/models/pgsql/translate/model.go
  • cypher/models/pgsql/translate/optimizer_safety_test.go
  • cypher/models/pgsql/translate/path_functions.go
  • cypher/models/pgsql/translate/predicate_placement.go
  • cypher/models/pgsql/translate/projection.go
  • cypher/models/pgsql/translate/quantifiers.go
  • cypher/models/pgsql/translate/relationship.go
  • cypher/models/pgsql/translate/renamer.go
  • cypher/models/pgsql/translate/renamer_test.go
  • cypher/models/pgsql/translate/translator.go
  • cypher/models/pgsql/translate/traversal.go
  • docs/development.md
  • docs/postgresql_translation.md
💤 Files with no reviewable changes (1)
  • cypher/models/pgsql/optimize/OPTIMIZATION_PLAN.md

Comment thread cypher/models/pgsql/README.md
Comment thread docs/development.md Outdated
Comment thread docs/postgresql_translation.md Outdated
Comment on lines +86 to +88
Recent PostgreSQL-only plan-corpus validation captured 425 PostgreSQL records. `ExactRangeExpansion` was planned and
applied in 6 cases, and `PathRelationshipPredicate` was planned and applied in 1 case, with no skipped entries for
either lowering.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Avoid embedding undated corpus counts in evergreen documentation.

The “recent” totals will drift as fixtures and optimizer rules change. Remove them, or link to a dated/generated capture artifact and label the snapshot explicitly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/postgresql_translation.md` around lines 86 - 88, The PostgreSQL
validation section embeds undated, changeable corpus counts. Update the
documentation near the `ExactRangeExpansion` and `PathRelationshipPredicate`
summary by removing the specific totals, or replace them with a clearly labeled
dated/generated snapshot reference.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cypher/models/pgsql/optimize/lowering_plan.go`:
- Around line 132-134: Gate dependent planning on an emitted ExactRangeExpansion
decision rather than structural eligibility. In the relevant logic, including
the branches near the reading-clause check and the classifications around lines
364 and 474, verify that decision.Target or stepTarget is present in
plan.ExactRangeExpansion before treating the range as expanded; otherwise retain
normal range traversal behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7a3c1a93-90b7-4343-9ce4-df3a2ef3e697

📥 Commits

Reviewing files that changed from the base of the PR and between 602ca2a and bf7f9a6.

📒 Files selected for processing (26)
  • README.md
  • cmd/plancorpus/README.md
  • cypher/models/pgsql/README.md
  • cypher/models/pgsql/optimize/OPTIMIZATION_PLAN.md
  • cypher/models/pgsql/optimize/lowering.go
  • cypher/models/pgsql/optimize/lowering_plan.go
  • cypher/models/pgsql/optimize/optimizer_test.go
  • cypher/models/pgsql/optimize/reordering.go
  • cypher/models/pgsql/test/translation_cases/pattern_binding.sql
  • cypher/models/pgsql/test/translation_cases/shortest_paths.sql
  • cypher/models/pgsql/translate/function.go
  • cypher/models/pgsql/translate/function_test.go
  • cypher/models/pgsql/translate/match.go
  • cypher/models/pgsql/translate/model.go
  • cypher/models/pgsql/translate/optimizer_safety_test.go
  • cypher/models/pgsql/translate/path_functions.go
  • cypher/models/pgsql/translate/predicate_placement.go
  • cypher/models/pgsql/translate/projection.go
  • cypher/models/pgsql/translate/quantifiers.go
  • cypher/models/pgsql/translate/relationship.go
  • cypher/models/pgsql/translate/renamer.go
  • cypher/models/pgsql/translate/renamer_test.go
  • cypher/models/pgsql/translate/translator.go
  • cypher/models/pgsql/translate/traversal.go
  • docs/development.md
  • docs/postgresql_translation.md
💤 Files with no reviewable changes (1)
  • cypher/models/pgsql/optimize/OPTIMIZATION_PLAN.md
✅ Files skipped from review due to trivial changes (5)
  • cypher/models/pgsql/README.md
  • cmd/plancorpus/README.md
  • docs/postgresql_translation.md
  • docs/development.md
  • README.md
🚧 Files skipped from review as they are similar to previous changes (18)
  • cypher/models/pgsql/translate/match.go
  • cypher/models/pgsql/translate/predicate_placement.go
  • cypher/models/pgsql/translate/renamer_test.go
  • cypher/models/pgsql/translate/path_functions.go
  • cypher/models/pgsql/translate/function.go
  • cypher/models/pgsql/optimize/lowering.go
  • cypher/models/pgsql/translate/quantifiers.go
  • cypher/models/pgsql/translate/projection.go
  • cypher/models/pgsql/translate/relationship.go
  • cypher/models/pgsql/translate/function_test.go
  • cypher/models/pgsql/translate/renamer.go
  • cypher/models/pgsql/translate/model.go
  • cypher/models/pgsql/test/translation_cases/pattern_binding.sql
  • cypher/models/pgsql/translate/translator.go
  • cypher/models/pgsql/translate/traversal.go
  • cypher/models/pgsql/optimize/reordering.go
  • cypher/models/pgsql/optimize/optimizer_test.go
  • cypher/models/pgsql/translate/optimizer_safety_test.go

Comment thread cypher/models/pgsql/optimize/lowering_plan.go
@zinic zinic merged commit baff269 into SpecterOps:main Jul 10, 2026
7 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.

1 participant