Skip to content

Commit

Permalink
fix: use pg_trgm extension for indexing msg data->@type (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
blushi authored Nov 9, 2023
1 parent 1505243 commit 07ba5fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions migrations/committed/000002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--! Previous: sha1:5ad90bce5c5fb68d0a8f886b6c07fb280ccd2c42
--! Hash: sha1:80425329666e5d20b5fbb7b6179f3d19acceeb76

-- support for similarity of text using trigram matching
CREATE extension IF NOT EXISTS pg_trgm;

-- drop the previous index that wasn't being useful for LIKE operations
-- and add a new index using gin_trgm_ops operator class from pg_trgm extension.
DROP INDEX IF EXISTS msg_data_type_idx;
CREATE INDEX IF NOT EXISTS msg_data_type_gin_idx ON msg USING gin ((data->>'@type') gin_trgm_ops);
18 changes: 16 additions & 2 deletions migrations/schema_snapshot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;
COMMENT ON EXTENSION pg_stat_statements IS 'track planning and execution statistics of all SQL statements executed';


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

CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;


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

COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams';


--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -579,10 +593,10 @@ CREATE INDEX flyway_schema_history_s_idx ON public.flyway_schema_history USING b


--
-- Name: msg_data_type_idx; Type: INDEX; Schema: public; Owner: -
-- Name: msg_data_type_gin_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX msg_data_type_idx ON public.msg USING btree (((data -> '@type'::text)));
CREATE INDEX msg_data_type_gin_idx ON public.msg USING gin (((data ->> '@type'::text)) public.gin_trgm_ops);


--
Expand Down

0 comments on commit 07ba5fa

Please sign in to comment.