Optimize list_groups_info query: replace OR join predicate with LATERAL JOIN + UNION#2337
Closed
Copilot wants to merge 2 commits into
Closed
Optimize list_groups_info query: replace OR join predicate with LATERAL JOIN + UNION#2337Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Merged
Replace the OR condition in the join predicate with a LATERAL JOIN that uses a UNION subquery. This separates the two cases: 1. Networks explicitly allowed for a group (via wnag table) 2. Networks where allow_all_groups = true This avoids the intermediate result set explosion caused by the OR predicate matching every allow_all_groups network for every group row. Update the sqlx offline query cache accordingly. Co-authored-by: moubctez <12608048+moubctez@users.noreply.github.com>
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on 'Allowed groups' PR
Optimize list_groups_info query: replace OR join predicate with LATERAL JOIN + UNION
Mar 13, 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.
📝 New contributors
📖 Description
The
list_groups_infoquery joinedwireguard_networkwith an OR predicate (wn.allow_all_groups OR wn.id = wnag.network_id), causing everyallow_all_groupsnetwork to match against every row inwireguard_network_allowed_group— a result-set explosion proportional toO(groups × allow_all_groups_networks).Fix: Replace the OR join with a
LEFT JOIN LATERALover a UNION subquery that resolves each branch independently:.sqlx/) to match the new query🛠️ Dev Branch Merge Checklist:
Documentation
Testing
Deployment
🏚️ Main Branch Merge Checklist:
Testing
Documentation
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.