Skip to content
Snippets Groups Projects
Commit d4bb2c70 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Add temporary index to ci_builds.artifacts_file to speed up SELECT query

parent 33d62be9
No related branches found
No related tags found
No related merge requests found
class AddLegacyPathToCiJobArtifacts < ActiveRecord::Migration
class AddFileLocationToCiJobArtifacts < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
 
DOWNTIME = false
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@ class MigrateLegacyArtifactsToJobArtifacts < ActiveRecord::Migration
 
DOWNTIME = false
MIGRATION = 'MigrateLegacyArtifacts'.freeze
BATCH_SIZE = 500
BATCH_SIZE = 2000
 
disable_ddl_transaction!
 
Loading
Loading
@@ -30,7 +30,12 @@ class MigrateLegacyArtifactsToJobArtifacts < ActiveRecord::Migration
end
 
def up
disable_statement_timeout
# We add an temporary index to `ci_builds.artifacts_file` column to avoid statements timeout
# This index is to be removed after we have cleaned up background migrations
# https://gitlab.com/gitlab-org/gitlab-ce/issues/46866
unless index_exists?(:ci_builds, :artifacts_file)
add_concurrent_index :ci_builds, :artifacts_file, where: "artifacts_file <> ''"
end
 
MigrateLegacyArtifactsToJobArtifacts::Build.legacy_artifacts.without_new_artifacts.tap do |relation|
queue_background_migration_jobs_by_range_at_intervals(relation,
Loading
Loading
@@ -41,6 +46,8 @@ class MigrateLegacyArtifactsToJobArtifacts < ActiveRecord::Migration
end
 
def down
# There's nothing to revert for this migration.
if index_exists?(:ci_builds, :artifacts_file)
remove_concurrent_index :ci_builds, :artifacts_file, where: "artifacts_file <> ''"
end
end
end
Loading
Loading
@@ -331,6 +331,7 @@ ActiveRecord::Schema.define(version: 20180603190921) do
end
 
add_index "ci_builds", ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree
add_index "ci_builds", ["artifacts_file"], name: "index_ci_builds_on_artifacts_file", where: "(artifacts_file <> ''::text)", using: :btree
add_index "ci_builds", ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree
add_index "ci_builds", ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree
add_index "ci_builds", ["commit_id", "status", "type"], name: "index_ci_builds_on_commit_id_and_status_and_type", using: :btree
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment