Fix GroupJoin CTE missing join key columns with QueryOnly storage#4189
Merged
jeremydmiller merged 1 commit intoJasperFx:masterfrom Mar 23, 2026
Merged
Conversation
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>
This was referenced Mar 24, 2026
This was referenced Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4188
GroupJoinwithIQuerySession(QueryOnly storage), the generated CTE omittedd.idfrom its SELECTlist because
IdColumn.ShouldSelect()returnsfalseforStorageStyle.QueryOnly. This caused a42703: column does not existPostgreSQL error when the join key referenced the document'sId.EnsureJoinKeyInCte()toCollectionUsage.Compilation.cswhich verifies that join key columns are present inboth CTE SELECT lists before building the JOIN clause, injecting them via
DuplicatedFieldSelectClause.EnsureColumn()if missing.EnsureColumn()method toDuplicatedFieldSelectClauseto allow dynamically adding columns to the selectlist.
IdusingQuerySession.Test plan
GroupJoin_left_join_on_id_with_query_session— verifies left join viaDefaultIfEmpty()produces correctresults including null for unmatched rows
GroupJoin_inner_join_on_id_with_query_session— verifies inner join produces correct results excludingunmatched rows
GroupJointests continue to pass (no regression forIDocumentSessionusage)