]> cat aescling's git repositories - mastodon.git/commitdiff
Add index statuses on account_id and id (#3895)
authorAkihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp>
Fri, 23 Jun 2017 15:46:00 +0000 (00:46 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 23 Jun 2017 15:46:00 +0000 (17:46 +0200)
db/migrate/20170610000000_add_statuses_index_on_account_id_id.rb [new file with mode: 0644]
db/schema.rb

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 (file)
index 0000000..3e74346
--- /dev/null
@@ -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
index ba6c0e876f522d373006fecea1f5f539ced4a802..2f12c7308b4f207934eebdfaef543608bfe6b4ff 100644 (file)
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20170609145826) do
+ActiveRecord::Schema.define(version: 20170610000000) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -279,7 +279,7 @@ ActiveRecord::Schema.define(version: 20170609145826) do
     t.integer "reblogs_count", default: 0, null: false
     t.string "language"
     t.bigint "conversation_id"
-    t.index ["account_id"], name: "index_statuses_on_account_id"
+    t.index ["account_id", "id"], name: "index_statuses_on_account_id_id"
     t.index ["conversation_id"], name: "index_statuses_on_conversation_id"
     t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
     t.index ["reblog_of_id"], name: "index_statuses_on_reblog_of_id"