From 27123bce56201e31cb1705f521101fb0722c5cdd Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Thu, 27 Jan 2022 07:18:51 -0500 Subject: [PATCH] Adding possibly missing indices (#16323) This is meant as a conversation. Throughout the code-base we have have `Tag.order(hotness_score: :desc)` and with PR #16322 we'll also have `Tag.order(taggings_count: :desc)`. My understanding is that if we have sorting, we might want to consider an index. I put this forward as a conversation with a possible quick win. Related to #16322 --- db/migrate/20220126205052_adding_indices_to_tag.rb | 7 +++++++ db/schema.rb | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220126205052_adding_indices_to_tag.rb diff --git a/db/migrate/20220126205052_adding_indices_to_tag.rb b/db/migrate/20220126205052_adding_indices_to_tag.rb new file mode 100644 index 000000000..3c4b7b050 --- /dev/null +++ b/db/migrate/20220126205052_adding_indices_to_tag.rb @@ -0,0 +1,7 @@ +class AddingIndicesToTag < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + def change + add_index :tags, :hotness_score, algorithm: :concurrently + add_index :tags, :taggings_count, algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index f1c616557..bcfa1a0be 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: 2021_12_22_040359) do +ActiveRecord::Schema.define(version: 2022_01_26_205052) do # These are extensions that must be enabled in order to support this database enable_extension "citext" @@ -1121,9 +1121,11 @@ ActiveRecord::Schema.define(version: 2021_12_22_040359) do t.datetime "updated_at", null: false t.text "wiki_body_html" t.text "wiki_body_markdown" + t.index ["hotness_score"], name: "index_tags_on_hotness_score" t.index ["name"], name: "index_tags_on_name", unique: true t.index ["social_preview_template"], name: "index_tags_on_social_preview_template" t.index ["supported"], name: "index_tags_on_supported" + t.index ["taggings_count"], name: "index_tags_on_taggings_count" end create_table "tweets", force: :cascade do |t|