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).

  1. Sort work items by status in ascending order: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/43823/commands/133857.
  2. 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 Screenshot_2025-09-23_at_3.59.54_pm
Sort by status in descending order Screenshot_2025-09-23_at_4.00.04_pm

How to set up and validate locally

  1. Enable the work_item_status_mvc2 feature flag.
  2. Set up custom statuses by following the instructions here.
  3. Create at least one status mapping by following the instructions here.
  4. 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

Merge request reports

Loading