From 6b07ebc18186caaf67b33f8d98205052cb5e9c7e Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Tue, 5 Feb 2019 21:15:48 +0000 Subject: [PATCH] Update GIN/GIST index note With a little explain/analyze testing and both gin and gist indexes, it looks like using the <-> operator in combination with a low limit will use the GIST index and work well for basic search-string matching. --- migrations/008.search.up.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/008.search.up.sql b/migrations/008.search.up.sql index 4a41e735..f9768672 100644 --- a/migrations/008.search.up.sql +++ b/migrations/008.search.up.sql @@ -26,6 +26,6 @@ CREATE TABLE IF NOT EXISTS search_locations ( -- - SELECT *, search_str <-> 'searchterm' AS dist FROM search_locations ORDER BY dist LIMIT 5; -- - SELECT *, similarity(search_str, 'searchterm') AS dist FROM search_locations -- WHERE t % 'searchterm' ORDER BY dist ASC, t LIMIT 5; --- Docs suggest the second query will perform better than the third, when only a small number --- of closest matches are desired, if combined with a GIST index (not GIN as below), +-- Docs suggest the '<->' query will perform better than the 'similarity', when only a small +-- number of closest matches are desired, if combined with a GIST index, CREATE INDEX trgm_gist_idx_search_str ON search_locations USING GIST (search_str gist_trgm_ops);