Fix nested selected link joins#27
Conversation
Plan selected single-link joins recursively so nested result shapes use the parent selected alias as the join source. Preserve parent rows under optional selected sources by lowering descendant joins to LEFT joins. Assisted-by: Codex:gpt-5.5
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c7e67f23c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Assign planner-owned SQL aliases to repeated nested selected links and reuse the alias plan across joins, selected values, and result-shape references. Assisted-by: Codex:gpt-5.5
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48dda43463
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Reserve root path aliases before assigning nested selected link SQL aliases so selected joins do not collide with filter or ordering joins synthesized from the root source. Assisted-by: Codex:gpt-5.5
Keep Many cardinality distinct from optional source nullability so unsupported multi-link selected shapes do not get planned as single-link joins. Assisted-by: Codex:gpt-5.5
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 991cd76e33
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let sql_alias = if !shape_path.is_empty() && conflicts_with_existing_alias { | ||
| join_aliases.next_alias() | ||
| } else { | ||
| preferred_alias.to_string() |
There was a problem hiding this comment.
Reserve root link aliases before nested aliases
When a root-level selected link appears after an earlier nested selected link with the same field name, this condition ignores the detected conflict because shape_path is empty, so both joins get the same SQL alias. For example, with Post.best_friend and User.best_friend, select Post { author: { best_friend: { name } }, best_friend: { name } } first assigns the nested author.best_friend alias best_friend, then assigns the root Post.best_friend alias best_friend too, producing two different joins with the same table alias. Root aliases need to win up front, or this conflict must allocate a fresh alias.
Useful? React with 👍 / 👎.
| let mut used_aliases = vec!["root".to_string()]; | ||
| used_aliases.extend(reserved_root_path_aliases); | ||
| collect_selected_shape_aliases(shape, &[], &mut used_aliases, &mut aliases, join_aliases); |
There was a problem hiding this comment.
Reserve root-path aliases in generated alias allocation
These root-path aliases are added only to used_aliases, but the join_aliases allocator used below does not reserve them. If a valid root link named like the allocator prefix, such as __gelite_join_0, is referenced by a filter or order clause, then a later nested selected-link conflict can call next_alias() and reuse __gelite_join_0 for a different selected join, producing duplicate SQL table aliases. Add these root-path aliases to the allocator's reserved set, or check used_aliases after generating an alias.
Useful? React with 👍 / 👎.



Summary
Fix nested selected single-link shape planning so descendant selected links join from the selected parent alias instead of the root source, while keeping SQL aliases unique when selected link names repeat or collide with root-relative path aliases.
Closes #26
Scope
sqlite-query-plan.Manycardinality distinct from nullable parent sources so unsupported multi-link shapes do not get lowered as single-link joins.LEFT JOINfor descendant selected joins under optional selected sources so root rows are preserved.Post.author.best_friendand repeatedUser.best_friend.best_friendnested selection.Spec and plan alignment
List the
spec/andplan/files checked for this change. If the changeintentionally diverges from them, explain why and include the required document
update in this pull request.
spec/query.md: selected relation fields require nested shapes, and the query pipeline must preserve nested result shapes.spec/sqlite-query-plan.md: SQLite Plan owns aliases, joins, selected value slots, result-shaping metadata, andinner/leftjoin choices for required and optional links. Multi-link nested shapes are specified for follow-up planning rather than single-link joins.plan/sqlite-query-plan-implementation-plan.md: the change stays insidesqlite-query-planand keeps SQL string rendering insqlite-query-sqlgen.Tests
List the automated and manual checks performed.
cargo test --workspacecargo test -p sqlite-query-plan sqlite_select_plan_can_join_nested_selected_single_linkcargo test -p sqlite-query-plan sqlite_select_plan_uses_left_join_for_nested_selected_link_under_optional_sourcecargo test -p sqlite-query-plan sqlite_select_plan_uses_unique_aliases_for_repeated_nested_selected_link_namescargo test -p sqlite-query-plan sqlite_select_plan_avoids_root_path_alias_collision_with_nested_selected_linkcargo test -p sqlite-query-plan sqlite_select_plan_preserves_multi_link_cardinality_under_optional_sourcecargo test --test select_execution select_pipeline_executes_nested_selected_single_link_shapecargo test --test select_execution select_pipeline_executes_repeated_nested_selected_single_link_namesReview notes
Call out API boundaries, temporary rules, migration concerns, or follow-up work
that reviewers should inspect closely.
AI assistance
Disclose AI tool usage according to
AI_POLICY.md.messages with
Assisted-bytrailers.Tools and models: