From 025a06d3228fc518c91a98e617652655bb778e5f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 21 Aug 2018 20:11:34 +0200 Subject: [PATCH] Add missing indices for ON DELETE CASCADE constraints (#8332) Fix #8327 --- .../20180820232245_add_foreign_key_indices.rb | 16 ++++++++++++++++ db/schema.rb | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180820232245_add_foreign_key_indices.rb diff --git a/db/migrate/20180820232245_add_foreign_key_indices.rb b/db/migrate/20180820232245_add_foreign_key_indices.rb new file mode 100644 index 000000000..e346c1f5b --- /dev/null +++ b/db/migrate/20180820232245_add_foreign_key_indices.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddForeignKeyIndices < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def change + add_index :follows, :target_account_id, algorithm: :concurrently + add_index :blocks, :target_account_id, algorithm: :concurrently + add_index :mutes, :target_account_id, algorithm: :concurrently + add_index :notifications, :from_account_id, algorithm: :concurrently + add_index :accounts, :moved_to_account_id, algorithm: :concurrently + add_index :statuses, :in_reply_to_account_id, algorithm: :concurrently + add_index :session_activations, :access_token_id, algorithm: :concurrently + add_index :oauth_access_grants, :resource_owner_id, algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 8e9242973..f3b06f7c0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_14_171349) do +ActiveRecord::Schema.define(version: 2018_08_20_232245) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -88,6 +88,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.string "actor_type" t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true + t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id" t.index ["uri"], name: "index_accounts_on_uri" t.index ["url"], name: "index_accounts_on_url" end @@ -122,6 +123,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.bigint "target_account_id", null: false t.string "uri" t.index ["account_id", "target_account_id"], name: "index_blocks_on_account_id_and_target_account_id", unique: true + t.index ["target_account_id"], name: "index_blocks_on_target_account_id" end create_table "conversation_mutes", force: :cascade do |t| @@ -209,6 +211,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.boolean "show_reblogs", default: true, null: false t.string "uri" t.index ["account_id", "target_account_id"], name: "index_follows_on_account_id_and_target_account_id", unique: true + t.index ["target_account_id"], name: "index_follows_on_target_account_id" end create_table "identities", id: :serial, force: :cascade do |t| @@ -297,6 +300,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.bigint "target_account_id", null: false t.boolean "hide_notifications", default: true, null: false t.index ["account_id", "target_account_id"], name: "index_mutes_on_account_id_and_target_account_id", unique: true + t.index ["target_account_id"], name: "index_mutes_on_target_account_id" end create_table "notifications", force: :cascade do |t| @@ -309,6 +313,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.index ["account_id", "activity_id", "activity_type"], name: "account_activity", unique: true t.index ["account_id", "id"], name: "index_notifications_on_account_id_and_id", order: { id: :desc } t.index ["activity_id", "activity_type"], name: "index_notifications_on_activity_id_and_activity_type" + t.index ["from_account_id"], name: "index_notifications_on_from_account_id" end create_table "oauth_access_grants", force: :cascade do |t| @@ -320,6 +325,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.string "scopes" t.bigint "application_id", null: false t.bigint "resource_owner_id", null: false + t.index ["resource_owner_id"], name: "index_oauth_access_grants_on_resource_owner_id" t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true end @@ -423,6 +429,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.bigint "access_token_id" t.bigint "user_id", null: false t.bigint "web_push_subscription_id" + t.index ["access_token_id"], name: "index_session_activations_on_access_token_id" t.index ["session_id"], name: "index_session_activations_on_session_id", unique: true t.index ["user_id"], name: "index_session_activations_on_user_id" end @@ -486,6 +493,7 @@ ActiveRecord::Schema.define(version: 2018_08_14_171349) do t.bigint "application_id" t.bigint "in_reply_to_account_id" t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc } + t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id" t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id" t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id" t.index ["uri"], name: "index_statuses_on_uri", unique: true