Relative positioning improvements
What does this MR do?
Addresses #230953
This MR changes the RelativePositioning
concern in the following ways:
- less arbitrary definition of
IDEAL_DISTANCE
- edge case handling and tests
- extension of usable range to all integers
- improvement of method documentation. This is a complex concern, and explaining how it works will make future devs' lives easier.
Benchmarks
Benchmarking against master suggests that these changes are beneficial to performance
- Braiding - about 5% faster
- Placement - up to 10% faster (48k queries vs 53k)
- Leap-frog - about 10% faster
- Moving nulls - largest improvement. 95% faster, 104 queries vs 10004 queries.
Database changes
The main DB changes are to the movement of unplaced items.
The main update loop issues the following query, with at most 100 values on any iteration:
WITH cte(cte_id, new_pos) AS (
SELECT *
FROM (VALUES (584, 513), (585, 1026), (586, 1539), (580, 2052), (581, 2565), (583, 3078),
(589, 3591), (582, 4104), (587, 4617), (588, 5130), (590, 5643), (591, 6156),
(735, 6669), (736, 7182), (737, 7695), (738, 8208), (739, 8721), (740, 9234),
(741, 9747), (733, 10260), (734, 10773), (742, 11286), (743, 11799), (745, 12312),
(744, 12825), (746, 13338), (747, 13851), (748, 14364), (749, 14877), (750, 15390),
(751, 15903), (752, 16416))
as t (id, pos)
)
UPDATE issues
SET relative_position = cte.new_pos
FROM cte
WHERE cte_id = id
Which explains as follows (see https://explain.depesz.com/s/fpI4):
Update on issues (cost=0.96..115.68 rows=32 width=1320)
CTE cte
-> Values Scan on "*VALUES*" (cost=0.00..0.40 rows=32 width=8)
-> Nested Loop (cost=0.56..115.28 rows=32 width=1320)
-> CTE Scan on cte (cost=0.00..0.64 rows=32 width=40)
-> Index Scan using issues_pkey on issues (cost=0.56..3.58 rows=1 width=1256)
Index Cond: (id = cte.cte_id)
Summary:
Time: 8.727 ms
- planning: 0.624 ms
- execution: 8.103 ms
- I/O read: 7.694 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 124 (~992.00 KiB) from the buffer pool
- reads: 4 (~32.00 KiB) from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
Other queries are not changed, but we do handle edge cases better
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- No security changes
Edited by Alex Kalderimis