Add unscoped index on articles.feed_source_url (#16984)

We already have a partial unique index for this column scoped on
`published = true`, which is still useful. This index does not make that
index redundant because that index is used to enforce a constraint that
we *only* want to apply to published articles. This index will be used
when `WHERE published` is not part of the query.
This commit is contained in:
Jamie Gaskins 2022-03-24 11:57:55 -04:00 committed by GitHub
parent 659ddb8829
commit 92c8c1a760
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,21 @@
class IndexArticlesOnFeedSourceUrl < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
# We already have a unique index scoped to `published = true`, so we need
# this one to be across all articles.
INDEX_NAME = :index_articles_on_feed_source_url_unscoped
def up
add_index :articles, :feed_source_url,
name: INDEX_NAME,
if_not_exists: true,
algorithm: :concurrently
end
def down
remove_index :articles,
name: INDEX_NAME,
if_exists: true,
algorithm: :concurrently
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_01_26_205052) do
ActiveRecord::Schema.define(version: 2022_03_23_185428) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
@ -162,6 +162,7 @@ ActiveRecord::Schema.define(version: 2022_01_26_205052) do
t.index ["comments_count"], name: "index_articles_on_comments_count"
t.index ["featured_number"], name: "index_articles_on_featured_number"
t.index ["feed_source_url"], name: "index_articles_on_feed_source_url", unique: true, where: "(published IS TRUE)"
t.index ["feed_source_url"], name: "index_articles_on_feed_source_url_unscoped"
t.index ["hotness_score", "comments_count"], name: "index_articles_on_hotness_score_and_comments_count"
t.index ["hotness_score"], name: "index_articles_on_hotness_score"
t.index ["path"], name: "index_articles_on_path"