about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-03-01 13:10:06 -0600
committermultiple creatures <dev@multiple-creature.party>2020-03-01 13:10:06 -0600
commitec3bb41e383e0d3d229e84e0d71c215d31d1a502 (patch)
tree6ab62731886f40c19ad9228b8c38cae9b084cb85
parent5961141ed711ea330ceb2691eff6ddda03b51cb1 (diff)
improve column indexes on `statuses` table
-rw-r--r--db/migrate/20200227214439_modify_status_index.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/db/migrate/20200227214439_modify_status_index.rb b/db/migrate/20200227214439_modify_status_index.rb
new file mode 100644
index 000000000..df8ca263a
--- /dev/null
+++ b/db/migrate/20200227214439_modify_status_index.rb
@@ -0,0 +1,15 @@
+class ModifyStatusIndex < ActiveRecord::Migration[5.2]
+  def up
+    remove_index :statuses, name: :index_statuses_20190820
+    remove_index :statuses, name: :index_statuses_on_account_id_and_id_and_visibility_not_hidden
+    remove_index :statuses, name: :index_statuses_on_account_id_and_id_and_visibility
+    remove_index :statuses, name: :index_statuses_local_20190824
+
+    safety_assured do
+      add_index :statuses, [:account_id, :id, :visibility, :updated_at], where: '(deleted_at IS NULL) AND (NOT hidden)', order: { id: :desc }, name: :index_statuses_20200301
+      add_index :statuses, [:id, :account_id], where: 'network AND (NOT hidden) AND ((local OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility IN (0, 5)) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))', order: { id: :desc }, name: :index_statuses_local_20200301
+      add_index :statuses, [:id, :account_id], where: '(NOT hidden) AND ((deleted_at IS NULL) AND (visibility in (0, 1, 5)) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))', order: { id: :desc }, name: :index_statuses_public_20200301
+      add_index :statuses, [:id, :account_id], where: 'hidden', name: :index_statuses_hidden_20200301
+    end
+  end
+end