Skip to content

Remove join from TaggableQueries.arel_tag_names_array for models supporting tag_name

Summary

Update the TaggableQueries.arel_tag_names_array method to use the tag_name column directly for models that support it, removing the need to join to the tags table.

Context

This is part of the work to handle FKs from ci_runner_taggings to tags as tracked in #467664.

Now that ci_runner_taggings.tag_name is populated, indexed, and non-nullable, we can optimize queries by reading directly from this column instead of joining to the tags table. This will:

  • Improve query performance by eliminating a join
  • Reduce cross-database foreign key dependencies
  • Support the Cells architecture by keeping data local

Implementation

  1. Identify all models that use TaggableQueries.arel_tag_names_array
  2. Update the method to check if the model supports the tag_name column
  3. For models with tag_name support (like Ci::Runner), query directly from the taggings table
  4. For models without tag_name support, maintain the existing join behavior
  5. Add or update tests to verify the new query path
  6. Monitor query performance to ensure improvements

Prerequisites

  • tag_name column backfilled (#570217 (closed))
  • tag_name column is non-nullable
  • tag_name column is indexed

Related Issues

Edited by Pedro Pombeiro