Skip to content

DB level traversal_ids and updates

This issue is exploratory and should not be considered final.

We can improve performance of Namespace#traversal_ids by pushing initialization and updates to the database layer.

I have a proposal for two improvements to traversal_ids. These improvements effectively obsolete work completed in !52854 (merged) which utilize feature flags by moving functionality from Ruby to SQL.

Initialize traversal_ids value

The value should be:

# Translate this to a SQL function
traversal_ids = (parent&.traversal_ids || []) + [currval('namespaces_id_seq')])

This would be implemented as a SQL function and enforced through a trigger(s).

Maybe this work makes the traversal_ids a read only attribute in Ruby land.

Update traversal_ids

An update to a namespaces' parent_id will have to update its traversal_ids and also that of its descendants traversal_ids. We can translate TraversalHierarchy#sync_traversal_ids! from Ruby to SQL to update traversal_ids from within the DB layer and avoid any problems caused by going around the existing Ruby code, such as with batch updates.

Implement through a column update trigger.


Some previous work has been saved in a branch at https://gitlab.com/gitlab-org/gitlab/-/tree/300377-traversal-ids-column-sync-with-constraints

Edited by Alex Pooley