mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-28 10:02:15 +00:00
a28950661c
The `/introspect` endpoint showed poor performance during v4 load testing due to an inefficient database query in `internal/query/introspection_client_by_id.sql`. This PR optimizes the query structure to significantly improve performance. ## Query Optimizations **UNION → UNION ALL**: Changed expensive `UNION` to `UNION ALL` since `client_id` is unique across both API and OIDC config tables, eliminating unnecessary deduplication overhead (30-50% improvement expected). **Simplified Keys CTE**: Optimized the keys lookup logic by using `$2::text as client_id` instead of `identifier as client_id` with `group by`, and added explicit `$3 = true` condition to the LEFT JOIN for better query planning. **Enhanced Readability**: Added consistent table aliases (c, a, p, o, k) for better maintainability. ## Benefits - **Zero-downtime deployment**: Uses existing database indexes, no schema changes required - **Secondary performance gains**: Other similar queries (`oidc_client_by_id.sql`, `userinfo_client_by_id.sql`) will also benefit from the optimizations - **Minimal code changes**: Only 13 lines added, 9 lines removed in the SQL query - **Backward compatible**: Same result set and API behavior The optimized query maintains the same functionality while providing significant performance improvements for the introspection endpoint under high concurrent load. Fixes #10389. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to start the survey. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: muhlemmer <[email protected]> Co-authored-by: Tim Möhlmann <[email protected]>