Skip to content

feat: uses left join in query organizations#4016

Open
ulemons wants to merge 1 commit intomainfrom
fix/use-left-join-on-query-organization
Open

feat: uses left join in query organizations#4016
ulemons wants to merge 1 commit intomainfrom
fix/use-left-join-on-query-organization

Conversation

@ulemons
Copy link
Copy Markdown
Contributor

@ulemons ulemons commented Apr 13, 2026

Note

Medium Risk
Changes the organizations advanced query to no longer require a matching organizationSegmentsAgg row when aggregates are requested, which can alter result sets/counts and ordering for segment-scoped queries. Risk is moderate due to query semantics/performance changes but limited to read-path SQL joins.

Overview
Updates the organizations advanced search SQL to always LEFT JOIN organizationSegmentsAgg (instead of conditionally using an INNER JOIN when aggregates are included).

This ensures organizations without matching aggregate rows for the requested segment (or null segment) can still be returned, with aggregate fields continuing to rely on coalesce(...) defaults.

Reviewed by Cursor Bugbot for commit e4ff931. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
@ulemons ulemons self-assigned this Apr 13, 2026
@ulemons ulemons added the Bug Created by Linear-GitHub Sync label Apr 13, 2026
Copilot AI review requested due to automatic review settings April 13, 2026 10:20
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR changes the organizations advanced query SQL to always use a LEFT JOIN to organizationSegmentsAgg, regardless of whether aggregate fields are requested, so organizations without matching aggregate rows are still returned.

Changes:

  • Replace the conditional INNER JOIN/LEFT JOIN selection for organizationSegmentsAgg with a consistent LEFT JOIN.
  • Preserve the segment join predicate while altering join semantics (no longer filtering organizations out via the join).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

: ` LEFT JOIN "organizationSegmentsAgg" osa ON osa."organizationId" = o.id AND ${
segmentId ? `osa."segmentId" = $(segmentId)` : `osa."segmentId" IS NULL`
}`
LEFT JOIN "organizationSegmentsAgg" osa ON osa."organizationId" = o.id AND ${
Comment on lines +1494 to 1496
LEFT JOIN "organizationSegmentsAgg" osa ON osa."organizationId" = o.id AND ${
segmentId ? `osa."segmentId" = $(segmentId)` : `osa."segmentId" IS NULL`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants