Skip to content

Commit

Permalink
Merge pull request #2592 from ujh/add-missing-indices
Browse files Browse the repository at this point in the history
Add missing indices as suggested by pg_hero
  • Loading branch information
ujh authored Dec 28, 2024
2 parents 3e36945 + 2f27f26 commit c4f453f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 28 deletions.
17 changes: 17 additions & 0 deletions db/migrate/20241228202733_add_indices_suggested_by_pg_hero.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class AddIndicesSuggestedByPgHero < ActiveRecord::Migration[8.0]
disable_ddl_transaction!

def change
add_index :collected_pens, :user_id, algorithm: :concurrently
add_index :collected_pens,
:model,
using: "gist",
opclass: :gist_trgm_ops,
algorithm: :concurrently
add_index :collected_pens,
:brand,
using: "gist",
opclass: :gist_trgm_ops,
algorithm: :concurrently
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class RemoveIndicesAsSuggestedByPgHero < ActiveRecord::Migration[8.0]
def change
remove_index :collected_inks,
name: "index_collected_inks_on_archived_on",
column: :archived_on
remove_index :gutentag_taggings,
name:
"index_gutentag_taggings_on_taggable_type_and_taggable_id",
column: %i[taggable_type taggable_id]
remove_index :leader_board_rows,
name: "index_leader_board_rows_on_type",
column: :type
remove_index :usage_records,
name: "index_usage_records_on_currently_inked_id",
column: :currently_inked_id
end
end
65 changes: 37 additions & 28 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public;
COMMENT ON EXTENSION fuzzystrmatch IS 'determine similarities and distance between strings';


--
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;


--
-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION pg_stat_statements IS 'track planning and execution statistics of all SQL statements executed';


--
-- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -1335,13 +1349,6 @@ CREATE INDEX index_brand_clusters_on_description ON public.brand_clusters USING
CREATE UNIQUE INDEX index_brand_clusters_on_name ON public.brand_clusters USING btree (name);


--
-- Name: index_collected_inks_on_archived_on; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_collected_inks_on_archived_on ON public.collected_inks USING btree (archived_on);


--
-- Name: index_collected_inks_on_archived_on_and_user_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1398,13 +1405,34 @@ CREATE INDEX index_collected_inks_on_simplified_ink_name ON public.collected_ink
CREATE INDEX index_collected_inks_on_tsv ON public.collected_inks USING gin (tsv);


--
-- Name: index_collected_pens_on_brand; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_collected_pens_on_brand ON public.collected_pens USING gist (brand public.gist_trgm_ops);


--
-- Name: index_collected_pens_on_model; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_collected_pens_on_model ON public.collected_pens USING gist (model public.gist_trgm_ops);


--
-- Name: index_collected_pens_on_pens_micro_cluster_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_collected_pens_on_pens_micro_cluster_id ON public.collected_pens USING btree (pens_micro_cluster_id);


--
-- Name: index_collected_pens_on_user_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_collected_pens_on_user_id ON public.collected_pens USING btree (user_id);


--
-- Name: index_currently_inked_on_collected_ink_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1433,13 +1461,6 @@ CREATE INDEX index_currently_inked_on_user_id ON public.currently_inked USING bt
CREATE INDEX index_gutentag_taggings_on_tag_id ON public.gutentag_taggings USING btree (tag_id);


--
-- Name: index_gutentag_taggings_on_taggable_type_and_taggable_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_gutentag_taggings_on_taggable_type_and_taggable_id ON public.gutentag_taggings USING btree (taggable_type, taggable_id);


--
-- Name: index_gutentag_tags_on_name; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1496,13 +1517,6 @@ CREATE INDEX index_ink_reviews_on_macro_cluster_id ON public.ink_reviews USING b
CREATE UNIQUE INDEX index_ink_reviews_on_url_and_macro_cluster_id ON public.ink_reviews USING btree (url, macro_cluster_id);


--
-- Name: index_leader_board_rows_on_type; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_leader_board_rows_on_type ON public.leader_board_rows USING btree (type);


--
-- Name: index_leader_board_rows_on_type_and_user_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1636,13 +1650,6 @@ CREATE INDEX index_reading_statuses_on_blog_post_id ON public.reading_statuses U
CREATE INDEX index_reading_statuses_on_user_id ON public.reading_statuses USING btree (user_id);


--
-- Name: index_usage_records_on_currently_inked_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_usage_records_on_currently_inked_id ON public.usage_records USING btree (currently_inked_id);


--
-- Name: index_usage_records_on_currently_inked_id_and_used_on; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1919,6 +1926,8 @@ ALTER TABLE ONLY public.collected_inks
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
('20241228204210'),
('20241228202733'),
('20241211115823'),
('20241114144808'),
('20240916060008'),
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ x-rails: &rails
context: .
target: dev
environment:
NEW_RELIC_LOG: stdout
NODE_ENV: development
PORT: 80
POSTGRES_PASSWORD: fpc
Expand Down

0 comments on commit c4f453f

Please sign in to comment.