From 07ba5fa054e34d2a0587daa944c8e517ff82ce18 Mon Sep 17 00:00:00 2001 From: Marie Gauthier Date: Thu, 9 Nov 2023 16:51:04 +0100 Subject: [PATCH] fix: use pg_trgm extension for indexing msg data->@type (#57) --- migrations/committed/000002.sql | 10 ++++++++++ migrations/schema_snapshot.sql | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 migrations/committed/000002.sql diff --git a/migrations/committed/000002.sql b/migrations/committed/000002.sql new file mode 100644 index 0000000..d63be05 --- /dev/null +++ b/migrations/committed/000002.sql @@ -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); diff --git a/migrations/schema_snapshot.sql b/migrations/schema_snapshot.sql index 096384c..e98a921 100644 --- a/migrations/schema_snapshot.sql +++ b/migrations/schema_snapshot.sql @@ -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: - -- @@ -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); --