Repository navigation
core: split users list superuser annotation in API into two EXISTS subqueries (cherry-pick #26275 to version-2026.8) - #27462
Merged
Conversation
…bqueries (#26275) * core: split users list superuser annotation into two EXISTS subqueries UserViewSet annotates every user with is_superuser using one EXISTS with an OR across two join paths: direct membership of a superuser group, and membership of a descendant group through authentik_core_groupancestry. PostgreSQL can't convert a subquery whose OR mixes two correlated conditions into a hashed subplan, so it runs once per user row, including rows skipped by OFFSET and inside DISTINCT/COUNT wrappers. Its join plan also depends on the ancestry materialized view's statistics: once a first group hierarchy exists and the view's stats are stale, the planner can pick a merge join that scans every group for every user. Use two separate EXISTS subqueries combined with OR instead. Each one is correlated only by user id equality, so PostgreSQL can run it once per query as a hashed subplan. The result is unchanged: a user is a superuser if they are a member of a superuser group or of any of its descendants, the same as User.is_superuser. Add tests for direct, child, grandchild, non-superuser parent and no group membership in the list and detail endpoints, and check that the list doesn't add group queries per user. * core: drop ExpressionWrapper from superuser annotation Exists | Exists already resolves to a Q with a boolean output field, so the wrapper isn't needed. The generated SQL is unchanged.
3 tasks
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Signed-off-by: Jens Langhammer <[email protected]>
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
BeryJu
approved these changes
Nov 5, 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.
Cherry-pick of #26275 to
version-2026.8branch.Original PR: #26275
Original Author: @ryanpesek
Cherry-picked commit: 9d8323b