Skip to content

fix: traversal predicate root step correlation BED-8321 - #108

Merged
urangel merged 2 commits into
mainfrom
BED-8321
Jul 28, 2026
Merged

fix: traversal predicate root step correlation BED-8321#108
urangel merged 2 commits into
mainfrom
BED-8321

Conversation

@urangel

@urangel urangel commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a query decorrelation bug in multi-step pattern predicate translation. When a pattern predicate has more than one traversal step (e.g. where (:User)-[:MemberOf]->(:Group)-[:MemberOf]->(g)), the root step was comma-joining the enclosing query part's CTE as a FROM source, causing a re-scan that broke row correlation
with the outer query. The fix introduces OmitPreviousFrameSource on TraversalStep to suppress that join for pattern predicate roots.

Resolves: BED-8321

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):

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

  • Bug Fixes
    • Improved translation for multi-step pattern predicates (including directed/undirected, negated, and self-referential traversals).
    • Fixed correlated query handling to avoid unnecessary re-scans by correctly sourcing the traversal root frame.
    • Added/strengthened group membership traversal tests to ensure accurate reachable Group counting.
  • Tests
    • Expanded BED-8321 integration coverage for multi-step pattern predicates.
    • Added a targeted unit test validating SQL/CTE structure for a two-hop undirected predicate with an unbound directionless root.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9a67ea26-eae7-481b-b397-1885cd04ffc1

📥 Commits

Reviewing files that changed from the base of the PR and between 3f0de72 and ba1d14a.

📒 Files selected for processing (1)
  • cypher/models/pgsql/translate/predicate_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cypher/models/pgsql/translate/predicate_test.go

Walkthrough

This change adjusts PostgreSQL traversal-root correlation for pattern predicates by optionally omitting the previous frame as a FROM source. It adds shared traversal-source selection and regression coverage for multi-step, directed, typed, untyped, negated, and group-membership patterns.

Changes

Pattern predicate correlation

Layer / File(s) Summary
Traversal source correlation
cypher/models/pgsql/translate/model.go, cypher/models/pgsql/translate/predicate.go, cypher/models/pgsql/translate/query.go, cypher/models/pgsql/translate/traversal*.go
Adds OmitPreviousFrameSource, applies it to pattern predicate roots, and uses a shared helper when selecting previous traversal sources.
Multi-step predicate regression coverage
cypher/models/pgsql/test/translation_cases/nodes.sql, integration/testdata/cases/bed8321-multi_step_pattern_predicates.json, cypher/models/pgsql/translate/predicate_test.go
Updates directed traversal coverage and adds assertions for multi-hop membership, typed and untyped predicates, negation, orientation variants, and CTE correlation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PatternPredicateBuilder
  participant TraversalTranslator
  participant PostgreSQLCTEs
  PatternPredicateBuilder->>TraversalTranslator: mark root to omit previous frame source
  TraversalTranslator->>PostgreSQLCTEs: build correlated traversal CTEs
  PostgreSQLCTEs-->>PatternPredicateBuilder: evaluate terminal existence predicate
Loading

Possibly related PRs

  • SpecterOps/DAWGS#73: Adjusts PostgreSQL pattern-predicate traversal root and outer-frame correlation.
  • SpecterOps/DAWGS#98: Updates related traversal correlation and previous-frame selection.

Poem

A rabbit hops through paths anew,
Keeping outer frames firmly in view.
Two edges join, predicates align,
Group hops count in a neat design.
Tests thump softly: “The roots are true!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the core fix for traversal predicate root correlation.
Description check ✅ Passed The description follows the template and includes the issue, change type, testing, driver impact, and checklist sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8321

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

@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.

🧹 Nitpick comments (1)
cypher/models/pgsql/translate/traversal_directionless.go (1)

204-210: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for multi-step directionless predicates.

This changed path handles unbound directionless roots, but the supplied multi-step regressions are directed; the existing undirected cases are single-hop. Add a two-hop undirected pattern predicate and assert its correlated terminal set to protect this source-selection behavior.

🤖 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 `@cypher/models/pgsql/translate/traversal_directionless.go` around lines 204 -
210, Add a regression test for a two-hop undirected pattern predicate with an
unbound directionless root, asserting the correlated terminal set produced by
the traversal. Reuse the existing directionless predicate test setup and ensure
the case exercises previousFrameTraversalSource and the resulting source
selection in the generated query.
🤖 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.

Nitpick comments:
In `@cypher/models/pgsql/translate/traversal_directionless.go`:
- Around line 204-210: Add a regression test for a two-hop undirected pattern
predicate with an unbound directionless root, asserting the correlated terminal
set produced by the traversal. Reuse the existing directionless predicate test
setup and ensure the case exercises previousFrameTraversalSource and the
resulting source selection in the generated query.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8d428fd8-661c-4e86-a02d-2bfa7684bc56

📥 Commits

Reviewing files that changed from the base of the PR and between f048db8 and e0cf439.

📒 Files selected for processing (7)
  • cypher/models/pgsql/test/translation_cases/nodes.sql
  • cypher/models/pgsql/translate/model.go
  • cypher/models/pgsql/translate/predicate.go
  • cypher/models/pgsql/translate/query.go
  • cypher/models/pgsql/translate/traversal.go
  • cypher/models/pgsql/translate/traversal_directionless.go
  • integration/testdata/cases/bed8321-multi_step_pattern_predicates.json

@urangel urangel added bug Something isn't working go Pull requests that update go code labels Jul 27, 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: 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/translate/predicate_test.go`:
- Around line 272-291: The predicate translation test’s global string assertions
do not verify that each edge-kind filter and source belongs to the correct CTE.
Update the assertions around the formatted query in the affected test to extract
or parse the bodies of s1 and s2, then assert s1 contains the s0 correlation and
kind 2 filter while s2 sources from s1 and contains kind 3; keep the terminal
existence assertion scoped to s2.
🪄 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: c9aeb54e-0c91-4840-89f9-b60816c8544d

📥 Commits

Reviewing files that changed from the base of the PR and between e0cf439 and 3f0de72.

📒 Files selected for processing (1)
  • cypher/models/pgsql/translate/predicate_test.go

Comment thread cypher/models/pgsql/translate/predicate_test.go

@seanjSO seanjSO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! 🥳

@urangel
urangel merged commit 6638cc2 into main Jul 28, 2026
9 checks passed
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.

2 participants