Skip to content

Fix GroupJoin CTE missing join key columns with QueryOnly storage#4189

Merged
jeremydmiller merged 1 commit intoJasperFx:masterfrom
davidpipes:fix/groupjoin-cte-missing-id-column
Mar 23, 2026
Merged

Fix GroupJoin CTE missing join key columns with QueryOnly storage#4189
jeremydmiller merged 1 commit intoJasperFx:masterfrom
davidpipes:fix/groupjoin-cte-missing-id-column

Conversation

@davidpipes
Copy link
Copy Markdown

Fixes #4188

  • When using GroupJoin with IQuerySession (QueryOnly storage), the generated CTE omitted d.id from its SELECT
    list because IdColumn.ShouldSelect() returns false for StorageStyle.QueryOnly. This caused a 42703: column does not exist PostgreSQL error when the join key referenced the document's Id.
  • Added EnsureJoinKeyInCte() to CollectionUsage.Compilation.cs which verifies that join key columns are present in
    both CTE SELECT lists before building the JOIN clause, injecting them via
    DuplicatedFieldSelectClause.EnsureColumn() if missing.
  • Added EnsureColumn() method to DuplicatedFieldSelectClause to allow dynamically adding columns to the select
    list.
  • Added two regression tests covering left join and inner join on Id using QuerySession.

Test plan

  • GroupJoin_left_join_on_id_with_query_session — verifies left join via DefaultIfEmpty() produces correct
    results including null for unmatched rows
  • GroupJoin_inner_join_on_id_with_query_session — verifies inner join produces correct results excluding
    unmatched rows
  • Existing GroupJoin tests continue to pass (no regression for IDocumentSession usage)

When using IQuerySession (QueryOnly storage), IdColumn.ShouldSelect()
returns false, excluding d.id from the CTE SELECT list. This causes
"column does not exist" errors when GroupJoin uses Id as a join key.

Ensure join key columns are present in both CTE SELECT lists by adding
them if missing, handling both DuplicatedFieldSelectClause and bare
DocumentStorage select clauses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

GroupJoin CTE does not include d.id in SELECT list when using IQuerySession (QueryOnly storage)

2 participants