From f40975701b4d7052bafc64e6e9903e811ca584f6 Mon Sep 17 00:00:00 2001 From: rhymes Date: Mon, 16 Nov 2020 17:10:48 +0100 Subject: [PATCH] Add partial index on users.feed_url (#11411) --- ...20201114151157_add_partial_index_to_users_feed_url.rb | 9 +++++++++ db/schema.rb | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20201114151157_add_partial_index_to_users_feed_url.rb diff --git a/db/migrate/20201114151157_add_partial_index_to_users_feed_url.rb b/db/migrate/20201114151157_add_partial_index_to_users_feed_url.rb new file mode 100644 index 000000000..a71dbd265 --- /dev/null +++ b/db/migrate/20201114151157_add_partial_index_to_users_feed_url.rb @@ -0,0 +1,9 @@ +class AddPartialIndexToUsersFeedUrl < ActiveRecord::Migration[6.0] + disable_ddl_transaction! + + def change + # adds an index only on users with a feed URL, as they are a tiny percentage of the total + # number of users, there is no need to add a full index as most entries will be empty + add_index :users, :feed_url, where: "COALESCE(feed_url, '') <> ''", algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c6ef647c..8685b2bf4 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: 2020_10_19_012200) do +ActiveRecord::Schema.define(version: 2020_11_14_151157) do # These are extensions that must be enabled in order to support this database enable_extension "citext" @@ -1328,6 +1328,7 @@ ActiveRecord::Schema.define(version: 2020_10_19_012200) do t.index ["created_at"], name: "index_users_on_created_at" t.index ["email"], name: "index_users_on_email", unique: true t.index ["facebook_username"], name: "index_users_on_facebook_username" + t.index ["feed_url"], name: "index_users_on_feed_url", where: "((COALESCE(feed_url, ''::character varying))::text <> ''::text)" t.index ["github_username"], name: "index_users_on_github_username", unique: true t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true t.index ["invitations_count"], name: "index_users_on_invitations_count"