Sort work items by status with mapping support
What does this MR do and why?
This MR builds on top of !199860 (merged) and enhances work item status sorting to properly handle all status mapping scenarios:
- Supports custom status mappings with proper date range validation (valid_from/valid_until).
- Correctly resolves chained mappings where a status is mapped to another status.
- Handles converted system-defined statuses and their subsequent mappings.
- Ensures the sorting order respects the same mapping resolution logic used in WorkItems::Statuses::CurrentStatus.
The implementation uses COALESCE with subqueries to properly traverse the mapping chain, ensuring work items are sorted by their effective mapped status category rather than their direct status.
References
Query plans
Query plans were executed for the gitlab-org/gitlab project (ID: 278964).
- Sort work items by status in ascending order: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/43823/commands/133857.
- Sort work items by status in descending order: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/43823/commands/133858.
Previous query plans can be found here.
Screenshots or screen recordings
| Sort by status in ascending order | ![]() |
| Sort by status in descending order | ![]() |
How to set up and validate locally
- Enable the
work_item_status_mvc2feature flag. - Set up custom statuses by following the instructions here.
- Create at least one status mapping by following the instructions here.
- Test sorting by status (ascending and descending) on the group issues list, project issues list, and user dashboard issues list.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Agnes Slota

