Read issue positions from work_item_positions

What

Cut over Issue's relative-position reads to source relative_position from the work_item_positions table instead of issues.relative_position, behind the read_relative_positions_from_work_item_positions feature flag (gitlab_com_derisk, default off). Writes still target issues.relative_position; the existing sync_work_item_positions_from_issues trigger keeps the two columns in sync.

  • Flag off (default): behaviour is byte-for-byte identical to today.
  • Flag on: all reorder reads — list/board ordering (order_by_relative_position), edge-drop neighbour (next_object_by_relative_position), the null scopes, and the move-flow reads (place_at_position occupant check, find_next_gap scans, min/max_sibling, calculate_relative_position) — read the joined work_item_positions.relative_position. Same rows, same order.

This is the first step of #594236. It is a correctness/relocation step — no performance improvement is expected here (the group-wide scope is unchanged; the index + root-scoping that make it fast come in a follow-up MR).

Scope

RelativePositioning reads issues.relative_position in many places, including reads that run inside the move/write flow. This MR relocates all reads; writes stay on issues (follow-up MR). Non-issue models that share the concern (designs, epics, parent-links) are unaffected — the column indirection defaults to their own relative_position.

Query plans (DB-lab, gitlab-org, neighbour lookup, same anchor)

Variant Time Buffers
Today — issues fan-out (session) ~5.25 s 46,182
This MR shapework_item_positions, scope unchanged (session) ~13.5 s ~6M
Follow-up — root-scoped + (relative_positioning_namespace_id, relative_position) index (session) ~0.245 ms 8

⚠️ Reading the new table while keeping the current namespace_id IN (self_and_descendant_ids) scope is slower. This MR is deliberately only the relocation; the speed-up needs the root-leading index + scope change (follow-up). That's why it's flag-gated and enabled only for validation. The changed scopes now JOIN work_item_positionsdatabase review requested.

Testing

  • Specs (both flag states): spec/models/issue_spec.rb, spec/lib/gitlab/relative_positioning/item_context_spec.rb, spec/services/issues/relative_position_rebalancing_service_spec.rb.
  • Manual: enabled the flag locally and reordered on the work-items list/board (top / bottom / middle drops) — confirmed the reorder queries source from work_item_positions and the order + drop outcome are unchanged; toggled the flag off → reads revert to issues.

Follow-ups (not this MR)

  1. Root column + index + root-scope the reads → the actual speed-up.
  2. Move writes to work_item_positions (dual-write, then drop the issues write at 100%).
  3. Drop issues.relative_position (backlog).
Edited by Vedant Jain

Merge request reports

Loading