about summary refs log tree commit diff
path: root/db/migrate
diff options
context:
space:
mode:
authorAkihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp>2017-06-24 00:46:00 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-06-23 17:46:00 +0200
commit6f34a6a77f5df6ddd6980c85c9edcc6aa400df73 (patch)
tree6806f61f71f50335bb2db71d3f42866987e56864 /db/migrate
parente078919f07c3542f8cc6aedc3c554404f328e907 (diff)
Add index statuses on account_id and id (#3895)
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20170610000000_add_statuses_index_on_account_id_id.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/db/migrate/20170610000000_add_statuses_index_on_account_id_id.rb b/db/migrate/20170610000000_add_statuses_index_on_account_id_id.rb
new file mode 100644
index 000000000..3e74346a8
--- /dev/null
+++ b/db/migrate/20170610000000_add_statuses_index_on_account_id_id.rb
@@ -0,0 +1,13 @@
+class AddStatusesIndexOnAccountIdId < ActiveRecord::Migration[5.1]
+  disable_ddl_transaction!
+
+  def change
+    # Statuses queried by account_id are often sorted by id. Querying statuses
+    # of an account to show them in his status page is one of the most
+    # significant examples.
+    # Add this index to improve the performance in such cases.
+    add_index 'statuses', ['account_id', 'id'], algorithm: :concurrently, name: 'index_statuses_on_account_id_id'
+
+    remove_index 'statuses', algorithm: :concurrently, column: 'account_id', name: 'index_statuses_on_account_id'
+  end
+end