Skip to content

chore: fix performance of a couple of queries (CM-1008)#3890

Merged
themarolt merged 1 commit intomainfrom
fix-query-perf-CM-1008
Mar 3, 2026
Merged

chore: fix performance of a couple of queries (CM-1008)#3890
themarolt merged 1 commit intomainfrom
fix-query-perf-CM-1008

Conversation

@themarolt
Copy link
Copy Markdown
Contributor

@themarolt themarolt commented Mar 3, 2026

Note

Medium Risk
Rewrites the SQL used to count and list member/organization merge suggestions; while intended as a performance optimization, it can change result counts/order if assumptions about uniqueness or segment membership differ.

Overview
Improves performance of merge-suggestion queries for members and organizations by replacing segment-table joins with EXISTS checks and avoiding unnecessary joins unless a displayName filter is applied.

For members, the count query switches to COUNT(*) and the list query drops DISTINCT, relying on the memberToMerge row set plus EXISTS-based segment filtering.

For organizations, the count query removes the previous cte and counts distinct symmetric pairs via a hash, and the list query replaces segment joins with EXISTS plus scalar subselects to fetch a matching primary/secondary segment id.

Written by Cursor Bugbot for commit 468c588. This will update automatically on new commits. Configure here.

Signed-off-by: Uroš Marolt <uros@marolt.me>
@themarolt themarolt merged commit 2457b41 into main Mar 3, 2026
19 checks passed
@themarolt themarolt deleted the fix-query-perf-CM-1008 branch March 3, 2026 17:23
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