Skip to content

feat: nested join ON queries - #942

Merged
abnegate merged 7 commits into
feat-query-libfrom
feat-join-on-queries
Aug 21, 2026
Merged

feat: nested join ON queries#942
abnegate merged 7 commits into
feat-query-libfrom
feat-join-on-queries

Conversation

@abnegate

Copy link
Copy Markdown
Member

Summary

  • Depends on utopia-php/query#20 (dev-feat-join-on-queries as 0.4.99).
  • Join validator accepts nested ON conditions (Query::on plus filter queries).
  • Alias collection uses getJoinAlias() so nested leftJoin('orders', 'ord', [...]) unlocks ord.* in select/filter/order.
  • SQL remapping qualifies Query::on columns and dotted ON filters; extra ON predicates compile onto the JOIN (LEFT JOIN semantics).

Stacked on feat-query-lib. Do not merge until query#20 is in.

Test plan

  • Unit validators + SQLFindTest nested ON compile
  • E2E LEFT JOIN ON filter keeps unmatched main rows
  • CI

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • main
  • 0.69.x

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 13c25de3-02dd-4ced-b174-b537d7044f03

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds nested JOIN ON conditions and ensures their predicates retain JOIN semantics while participating in normal query and index validation.

  • Qualifies nested ON columns and compiles additional predicates into the JOIN clause.
  • Collects aliases from the query library’s JOIN API.
  • Recursively validates fulltext searches and counts vector predicates under JOIN ON.
  • Adds unit and end-to-end coverage for SQL generation, aliases, validation, and LEFT JOIN behavior.

Confidence Score: 5/5

The PR appears safe to merge once its declared upstream query-library dependency is available.

No blocking failure remains; the previously reported index-validation bypass and vector double-count are addressed by the current traversal and focused regression tests.

Important Files Changed

Filename Overview
src/Database/Validator/IndexedQueries.php Nested JOIN ON children are traversed exclusively through getJoinOnQueries(), resolving the reported vector double-count while retaining fulltext and multi-vector validation.
src/Database/Validator/Queries.php Nested JOIN filters are routed through filter validators while preserving collected JOIN aliases.
src/Database/Validator/Query/Join.php Nested JOIN conditions now validate required ON columns and supported comparison operators.
src/Database/Adapter/SQL.php Nested ON columns and dotted predicates are remapped and emitted as JOIN conditions rather than WHERE filters.
tests/unit/Validator/IndexedQueriesTest.php Tests cover missing fulltext indexes, combined vector limits, and acceptance of one vector predicate inside JOIN ON.
tests/unit/SQLFindTest.php SQL assertions verify alias qualification and preservation of LEFT JOIN ON semantics.

Reviews (6): Last reviewed commit: "fix: count nested join ON vectors once" | Re-trigger Greptile

Comment thread src/Database/Validator/Queries.php
Collect join aliases from Query::getJoinAlias() so nested leftJoin('orders', 'ord', [Query::on(...), Query::equal(...)]) works. Qualify ON columns, validate Query::on triples, and compile extra ON filters onto the JOIN instead of WHERE.
@abnegate
abnegate force-pushed the feat-join-on-queries branch from 0403d12 to b1466d6 Compare August 21, 2026 05:30
IndexedQueries walked nested and/or children but skipped getJoinOnQueries(),
so a search or extra vector predicate on JOIN ON bypassed fulltext-index
and single-vector checks.
@abnegate

Copy link
Copy Markdown
Member Author

@greptileai review

getJoinOnQueries() returns list<Utopia\Query\Query>, not Database\Query. IndexedQueries now accepts the base type so PHPStan no longer rejects the recursive search and vector walks.
@abnegate

Copy link
Copy Markdown
Member Author

@greptileai review

Replace the join-on branch alias with ^0.5 now that query-lib 0.5.0 is published.
Comment thread src/Database/Validator/IndexedQueries.php Outdated
Walk JOIN ON children exclusively so a single vector predicate in ON is not counted twice if join methods later report as nested.
@abnegate

Copy link
Copy Markdown
Member Author

@greptileai review

Addressed the JOIN ON vector double-count: IndexedQueries walks nested join ON children exclusively, with a unit test that a single vector in JOIN ON is valid.

@abnegate
abnegate merged commit c1d1389 into feat-query-lib Aug 21, 2026
22 checks passed
@abnegate
abnegate deleted the feat-join-on-queries branch August 21, 2026 06:57
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