Improve the query performance to find unsynced job artifacts

parent 95ac1154
......@@ -141,7 +141,7 @@ module Geo
fdw_job_artifacts.joins("LEFT OUTER JOIN job_artifact_registry
ON job_artifact_registry.artifact_id = #{fdw_job_artifacts_table}.id")
.with_files_stored_locally
.where(job_artifact_registry: { id: nil })
.where(job_artifact_registry: { artifact_id: nil })
.where.not(id: except_artifact_ids)
end
......
class AddIndexToArtifactIdOnJobArtifactRegistry < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :job_artifact_registry, :artifact_id
end
def down
if index_exists?(:job_artifact_registry, :artifact_id)
remove_concurrent_index :job_artifact_registry_finder, :artifact_id
end
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180405074130) do
ActiveRecord::Schema.define(version: 20180412213305) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -47,6 +47,7 @@ ActiveRecord::Schema.define(version: 20180405074130) do
t.boolean "missing_on_primary", default: false, null: false
end
add_index "job_artifact_registry", ["artifact_id"], name: "index_job_artifact_registry_on_artifact_id", using: :btree
add_index "job_artifact_registry", ["retry_at"], name: "index_job_artifact_registry_on_retry_at", using: :btree
add_index "job_artifact_registry", ["success"], name: "index_job_artifact_registry_on_success", using: :btree
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment