posts: add string_to_array(tag_string, ' ') index.
This is preparation for removing tag_index and test_parser.
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
class AddStringToArrayTagStringIndexOnPosts < ActiveRecord::Migration[6.1]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_index :posts, "string_to_array(tag_string, ' ')", using: :gin, algorithm: :concurrently
|
||||||
|
|
||||||
|
up_only do
|
||||||
|
# Set the statistics target on the index to 3000 so that Postgres will a)
|
||||||
|
# collect stats on the size of top 3000 largest tags and b) sample
|
||||||
|
# 3000*300 = 900k random posts to do so. This is necessary so that
|
||||||
|
# Postgres can generate good query plans based on the size of the tag.
|
||||||
|
#
|
||||||
|
# https://akorotkov.github.io/blog/2017/05/31/alter-index-weird/
|
||||||
|
# https://www.postgresql.org/docs/current/planner-stats.html
|
||||||
|
# https://www.postgresql.org/docs/current/sql-alterindex.html
|
||||||
|
execute "ALTER INDEX index_posts_on_string_to_array_tag_string ALTER COLUMN 1 SET STATISTICS 3000"
|
||||||
|
execute "VACUUM (VERBOSE, ANALYZE) posts"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4341,6 +4341,14 @@ CREATE INDEX index_posts_on_rating ON public.posts USING btree (rating) WHERE (r
|
|||||||
CREATE INDEX index_posts_on_source_trgm ON public.posts USING gin (source public.gin_trgm_ops);
|
CREATE INDEX index_posts_on_source_trgm ON public.posts USING gin (source public.gin_trgm_ops);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_posts_on_string_to_array_tag_string; Type: INDEX; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_posts_on_string_to_array_tag_string ON public.posts USING gin (string_to_array(tag_string, ' '::text));
|
||||||
|
ALTER INDEX public.index_posts_on_string_to_array_tag_string ALTER COLUMN 1 SET STATISTICS 3000;
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_posts_on_tag_index; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_posts_on_tag_index; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
@@ -5050,6 +5058,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||||||
('20210921170444'),
|
('20210921170444'),
|
||||||
('20210926123414'),
|
('20210926123414'),
|
||||||
('20210926125826'),
|
('20210926125826'),
|
||||||
('20211008091234');
|
('20211008091234'),
|
||||||
|
('20211010181657');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user