Add some missing indexes on foreign keys (#18157)

This commit is contained in:
Claire 2022-04-28 17:15:11 +02:00 committed by GitHub
parent d55154819e
commit 9b4024a389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,7 @@
class AddIndexStatusesOnAccountId < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :statuses, [:account_id], name: :index_statuses_on_account_id, algorithm: :concurrently
end
end

View File

@ -0,0 +1,7 @@
class AddIndexStatusesPinsOnStatusId < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :status_pins, [:status_id], name: :index_status_pins_on_status_id, algorithm: :concurrently
end
end

View File

@ -0,0 +1,7 @@
class AddIndexReportsOnAssignedAccountId < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :reports, [:assigned_account_id], name: :index_reports_on_assigned_account_id, algorithm: :concurrently, where: 'assigned_account_id IS NOT NULL'
end
end

View File

@ -0,0 +1,7 @@
class AddIndexReportsOnActionTakenByAccountId < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :reports, [:action_taken_by_account_id], name: :index_reports_on_action_taken_by_account_id, algorithm: :concurrently, where: 'action_taken_by_account_id IS NOT NULL'
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_03_16_233212) do ActiveRecord::Schema.define(version: 2022_04_28_114902) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -784,6 +784,8 @@ ActiveRecord::Schema.define(version: 2022_03_16_233212) do
t.datetime "action_taken_at" t.datetime "action_taken_at"
t.bigint "rule_ids", array: true t.bigint "rule_ids", array: true
t.index ["account_id"], name: "index_reports_on_account_id" t.index ["account_id"], name: "index_reports_on_account_id"
t.index ["action_taken_by_account_id"], name: "index_reports_on_action_taken_by_account_id", where: "(action_taken_by_account_id IS NOT NULL)"
t.index ["assigned_account_id"], name: "index_reports_on_assigned_account_id", where: "(assigned_account_id IS NOT NULL)"
t.index ["target_account_id"], name: "index_reports_on_target_account_id" t.index ["target_account_id"], name: "index_reports_on_target_account_id"
end end
@ -860,6 +862,7 @@ ActiveRecord::Schema.define(version: 2022_03_16_233212) do
t.datetime "created_at", default: -> { "now()" }, null: false t.datetime "created_at", default: -> { "now()" }, null: false
t.datetime "updated_at", default: -> { "now()" }, null: false t.datetime "updated_at", default: -> { "now()" }, null: false
t.index ["account_id", "status_id"], name: "index_status_pins_on_account_id_and_status_id", unique: true t.index ["account_id", "status_id"], name: "index_status_pins_on_account_id_and_status_id", unique: true
t.index ["status_id"], name: "index_status_pins_on_status_id"
end end
create_table "status_stats", force: :cascade do |t| create_table "status_stats", force: :cascade do |t|
@ -896,6 +899,7 @@ ActiveRecord::Schema.define(version: 2022_03_16_233212) do
t.boolean "trendable" t.boolean "trendable"
t.bigint "ordered_media_attachment_ids", array: true t.bigint "ordered_media_attachment_ids", array: true
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)" t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
t.index ["account_id"], name: "index_statuses_on_account_id"
t.index ["deleted_at"], name: "index_statuses_on_deleted_at", where: "(deleted_at IS NOT NULL)" t.index ["deleted_at"], name: "index_statuses_on_deleted_at", where: "(deleted_at IS NOT NULL)"
t.index ["id", "account_id"], name: "index_statuses_local_20190824", order: { id: :desc }, where: "((local OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))" t.index ["id", "account_id"], name: "index_statuses_local_20190824", order: { id: :desc }, where: "((local OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
t.index ["id", "account_id"], name: "index_statuses_public_20200119", order: { id: :desc }, where: "((deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))" t.index ["id", "account_id"], name: "index_statuses_public_20200119", order: { id: :desc }, where: "((deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
@ -1236,4 +1240,5 @@ ActiveRecord::Schema.define(version: 2022_03_16_233212) do
ORDER BY (sum(t0.rank)) DESC; ORDER BY (sum(t0.rank)) DESC;
SQL SQL
add_index "follow_recommendations", ["account_id"], name: "index_follow_recommendations_on_account_id", unique: true add_index "follow_recommendations", ["account_id"], name: "index_follow_recommendations_on_account_id", unique: true
end end