Runner heartbeat instructs postgres to UPDATE for unchanged columns

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Problem

Some updates take over 10 seconds for the runner heartbeat. https://log.gprd.gitlab.net/app/r/s/GesNu

Screenshot_2025-03-18_at_3.05.01_PM

Code is here: https://gitlab.com/gitlab-org/gitlab/-/blob/8ff509d33ea9e4d55fb32b4ce6fb8e3c96409468/app/models/ci/runner_manager.rb#L163

Possible solutions

The following discussions from !184327 (merged) should be addressed:

  • @allison.browne started a discussion: (+2 comments)

    Idea to help database performance here. We update all columns regardless of if the value changed. We should check if passing just the changed columns would help to reduce write performance/load because some of the columns involved have triggers and indexes and this is an extremely frequent update. I'm not quickly finding docs about specifically how postgres will handle this internally, but it's against best practices, given:

    To optimize update performance, you must take care to only update those columns that were changed. This is obvious if you write the update statement manually. ORM tools, however, might generate update statements that set all columns every time.

    https://use-the-index-luke.com/sql/dml/update

    I did confirm that the update statement generated includes updates to columns even when they don't change.

Edited by 🤖 GitLab Bot 🤖