Skip to content

Commit

Permalink
Reindex external indexes properly on updates #282
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 authored and Ngalstyan4 committed Feb 8, 2024
1 parent 5cea216 commit 192a4f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sql/lantern.sql
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ RETURNS VOID AS $$
DECLARE
r RECORD;
BEGIN
FOR r IN SELECT indexname FROM pg_indexes
FOR r IN SELECT indexname, indexdef FROM pg_indexes
WHERE indexdef ILIKE '%USING hnsw%' OR indexdef ILIKE '%USING lantern_hnsw%'
LOOP
RAISE NOTICE 'Reindexing index: %', r.indexname;
EXECUTE 'REINDEX INDEX ' || quote_ident(r.indexname) || ';';
IF POSITION('_experimental_index_path' in r.indexdef) > 0 THEN
PERFORM lantern_reindex_external_index(r.indexname::regclass);
ELSE
EXECUTE 'REINDEX INDEX ' || quote_ident(r.indexname) || ';';
END IF;
RAISE NOTICE 'Reindexed index: %', r.indexname;
END LOOP;
END $$ LANGUAGE plpgsql VOLATILE;
20 changes: 20 additions & 0 deletions sql/updates/0.1.0--0.1.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Database updates
-- Must be run in update scripts every time index storage format changes and a finer-grained update
-- method is not shipped for the format change
CREATE OR REPLACE FUNCTION _lantern_internal.reindex_lantern_indexes()
RETURNS VOID AS $$
DECLARE
r RECORD;
BEGIN
FOR r IN SELECT indexname, indexdef FROM pg_indexes
WHERE indexdef ILIKE '%USING hnsw%' OR indexdef ILIKE '%USING lantern_hnsw%'
LOOP
RAISE NOTICE 'Reindexing index: %', r.indexname;
IF POSITION('_experimental_index_path' in r.indexdef) > 0 THEN
PERFORM lantern_reindex_external_index(r.indexname::regclass);
ELSE
EXECUTE 'REINDEX INDEX ' || quote_ident(r.indexname) || ';';
END IF;
RAISE NOTICE 'Reindexed index: %', r.indexname;
END LOOP;
END $$ LANGUAGE plpgsql VOLATILE;

0 comments on commit 192a4f2

Please sign in to comment.