Commit 237c4784 authored by Andreas Brandl's avatar Andreas Brandl

Replace events index with partial one

This improves the index size by removing all records with `group_id`
from the index. On GitLab.com this means reducing the size from 9 GB to
8kb (as long as the column stays mostly null).

Relates to
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/32826#note_214690051
parent 8c5bed72
---
title: Replace events index with partial one
merge_request: 32874
author:
type: performance
# frozen_string_literal: true
class ReplaceEventsIndexOnGroupIdWithPartialIndex < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index(:events, :group_id, where: 'group_id IS NOT NULL', name: 'index_events_on_group_id_partial')
remove_concurrent_index_by_name(:events, 'index_events_on_group_id')
end
def down
add_concurrent_index(:events, :group_id, name: 'index_events_on_group_id')
remove_concurrent_index_by_name(:events, 'index_events_on_group_id_partial')
end
end
......@@ -1330,7 +1330,7 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do
t.index ["action"], name: "index_events_on_action"
t.index ["author_id", "project_id"], name: "index_events_on_author_id_and_project_id"
t.index ["created_at", "author_id"], name: "analytics_index_events_on_created_at_and_author_id"
t.index ["group_id"], name: "index_events_on_group_id"
t.index ["group_id"], name: "index_events_on_group_id_partial", where: "(group_id IS NOT NULL)"
t.index ["project_id", "created_at"], name: "index_events_on_project_id_and_created_at"
t.index ["project_id", "id"], name: "index_events_on_project_id_and_id"
t.index ["target_type", "target_id"], name: "index_events_on_target_type_and_target_id"
......
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