Sorting by Rank does not show expected values
Platform Notice: Cloud, Server, and Data Center - This article applies equally to all platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Symptoms
When you attempt to sort issues by Rank using the Issue Navigator, the issues do not appear to be sorted numerically. Users sometimes expect that issues will appear ordered by the Rank field, in consecutive order from 1 to the number of ranked issues.
Explanation
In JIRA Agile 5.8 and later, ranking is based on a custom field called 'Rank' (of type Global Rank). Note that you can have multiple fields of type Global Rank, if you wish. Each Global Rank field is a linked list that contains every issue in JIRA in order (from highest rank to lowest rank).
The 'value' of a Global Rank field for an issue is not meaningful, though by co-incidence it contains the absolute index inside the linked list of issues in the system. The user is not meant to view this field (it is not shown on the View Issue screen or the Issue Navigator by default) because the absolute number does not mean anything except when compared to other issues in the search results. For example, the ranks in a system might look like the following:
Rank | Issue Key |
---|---|
1 | HIT-5 |
2 | PRO-1 |
3 | TST-3 |
4 | PRO-2 |
5 | TST-1 |
6 | PRO-8 |
7 | PRO-13 |
If the user searched inside project PRO and ordered by the rank field they would get the correct order of issues (PRO-1, PRO-2, PRO-8, PRO-13) but would be confused by the numbers (2, 4, 6, 7). The fact that there are gaps is irrelevant because they probably do not care about TST at all. The end summary:
- If you query issues with "order by rank asc" you will get the correct order of issues by rank.
- The numbers shown (ie. the value of the Rank field) will often not be sequential, but their order is correct.
- The exception to the above is that sub-tasks are ranked independently.
- If you queried every issue in the system and ordered by Rank, then the rank field would begin at 1 and increase consecutively except for subtasks.
Special Note About Sub-Tasks
While sub-tasks are included in the global rank linked list, they are ranked first by their parent then by their own rank. Thus the logic for comparing two issues during a "sort by rank" is:
- If issue is a parent issue, compare index.
- If issue is a subtask,
- First compare parent index, return higher (if not subtasks of the same parent).
- Then compare subtask index (if the other issue is also a subtask of the same issue).
This means that subtasks are always ranked immediately next to their parent regardless of the absolute ranking index value. As a result, a search of all issues in a system with something like "order by rank asc" would correctly return the ordered list of issues but the rank value would only be consecutive for non sub-tasks (except for gaps where the sub-tasks consume index values). Here's an example:
Rank | Issue Key |
---|---|
1 | PRO-8 |
2 | TST-4 |
3 | PRO-4 |
4 | PRO-8 / PRO-16 |
5 | TST-2 |
6 | PRO-8 / PRO-19 |
7 | PRO-1 |
8 | TST-6 |
9 | PRO-1 / PRO-4 |
If you searched only for project PRO with "order by rank asc" you would get PRO-8, PRO-16, PRO-19, PRO-4, PRO-1, PRO-4. The 'rank' values would be 1, 4, 6, 3, 7, 9.