Add index in issues on last_edited_by_id
What does this MR do?
While investigating #218036 (closed) @manojmj and I discovered that in https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/services/users/migrate_to_ghost_user_service.rb#L61 we want to update all issues that were last edited by user whose account is getting deleted. As this table is not indexed it takes a long time, which may cause timeouts on whole transaction.
Sentry errors: https://sentry.gitlab.net/gitlab/gitlabcom/?query=is%3Aunresolved+DeleteUserWorker&statsPeriod=14d
Screenshots
this is plan now: (from database-lab channel, checked on 25.05)
Seq Scan on public.issues (cost=0.00..9837682.09 rows=69 width=1307) (actual time=747.780..71151.995 rows=84 loops=1)
Filter: (issues.last_edited_by_id = 2311904)
Rows Removed by Filter: 26973906
Buffers: shared read=2376456 dirtied=2237 written=1770
I/O Timings: read=61076.325 write=49.037
Time: 1.186 min
- planning: 0.206 ms
- execution: 1.186 min
- I/O read: 1.018 min
- I/O write: 49.037 ms
Shared buffers:
- hits: 0 from the buffer pool
- reads: 2376456 (~18.10 GiB) from the OS file cache, including disk I/O
- dirtied: 2237 (~17.50 MiB)
- writes: 1770 (~13.80 MiB)
When I created index:
Index Scan using index_issues_on_last_edited_by_id on public.issues (cost=0.44..100.14 rows=71 width=1307) (actual time=49.054..256.549 rows=84 loops=1)
Index Cond: (issues.last_edited_by_id = 2311904)
Buffers: shared read=88
I/O Timings: read=255.335
Time: 256.884 ms
- planning: 0.260 ms
- execution: 256.624 ms
- I/O read: 255.335 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 0 from the buffer pool
- reads: 88 (~704.00 KiB) from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
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:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Closes #218036 (closed)