Skip to content

fix: optimize queries with leading unbounded expansion BED-8779 - #116

Open
urangel wants to merge 3 commits into
mainfrom
BED-8779
Open

fix: optimize queries with leading unbounded expansion BED-8779#116
urangel wants to merge 3 commits into
mainfrom
BED-8779

Conversation

@urangel

@urangel urangel commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

This changeset implements an optimization strategy for multistep traversals which begin with an unbounded expansion such that the query is first flipped in direction before translating into pg sql.

The idea is that a more tightly defined end is better for selectivity since this circumvents first continuing down an indefinite expansion which may or may not satisfy later evaluated constraints.

We already do some traversal direction reversing within a traversal step itself so this a similar approach but affecting the entire traversal rather than only step by step.

Resolves: BED-8779

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)

Screenshots (if appropriate):

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

  • New Features

    • Improved traversal planning by starting eligible variable-length searches from more selective endpoints.
    • Preserved the original logical path order when traversals are optimized in reverse.
    • Added relationship uniqueness handling to prevent reused edges during path expansion.
  • Bug Fixes

    • Prevented recursive path segments from reusing previously matched relationships.
    • Improved path reconstruction and filtering for multipart and repeated patterns.
  • Tests

    • Added coverage for traversal reversal, path reuse prevention, endpoint constraints, and unsupported reversal scenarios.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 627084fc-203a-4852-a7f8-ff5d06f86b84

📥 Commits

Reviewing files that changed from the base of the PR and between 7e219be and b89473c.

📒 Files selected for processing (16)
  • cypher/models/cypher/model.go
  • cypher/models/pgsql/optimize/direction.go
  • cypher/models/pgsql/optimize/optimizer.go
  • cypher/models/pgsql/optimize/optimizer_test.go
  • cypher/models/pgsql/optimize/reordering.go
  • cypher/models/pgsql/test/translation_cases/multipart.sql
  • cypher/models/pgsql/test/translation_cases/pattern_binding.sql
  • cypher/models/pgsql/test/translation_cases/pattern_expansion.sql
  • cypher/models/pgsql/translate/expansion.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/pattern.go
  • cypher/models/pgsql/translate/projection.go
  • cypher/models/pgsql/translate/tracking.go
  • cypher/models/pgsql/translate/traversal.go
 _____________________________
< Lint today, shine tomorrow. >
 -----------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8779

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

@urangel urangel changed the title fix: optimize translation for queries with leading unbound expansion … fix: optimize queries with leading unbounded expansion BED-8779 Aug 13, 2026
@urangel urangel self-assigned this Aug 13, 2026
@urangel urangel added bug Something isn't working go Pull requests that update go code labels Aug 13, 2026
@urangel
urangel marked this pull request as ready for review August 13, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant