From 58ba2139ce8e26d2c73b2f5055fe3aa54cc1a704 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 13 Oct 2021 13:48:54 -0700 Subject: [PATCH] Added instructions for reindexing - #17 [skip ci] --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 008376b..03789f5 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Speed up queries with an approximate index. Add an index for each distance funct L2 distance ```sql -CREATE INDEX ON table USING ivfflat (column); +CREATE INDEX ON table USING ivfflat (column vector_l2_ops); -- default if no opclass specified ``` Inner product @@ -77,7 +77,19 @@ Cosine distance CREATE INDEX ON table USING ivfflat (column vector_cosine_ops); ``` -Indexes should be created after the table has data for optimal clustering. Also, unlike typical indexes which only affect performance, you may see different results for queries after adding an approximate index. +Indexes should be created after the table has data for optimal clustering. If the distribution of data changes significantly, you can reindex without downtime: + +```sql +-- Postgres 12+ +REINDEX INDEX CONCURRENTLY index_name; + +-- Postgres < 12 (change opclass as needed) +CREATE INDEX CONCURRENTLY temp_name ON table USING ivfflat (column vector_l2_ops); +DROP INDEX CONCURRENTLY index_name; +ALTER INDEX temp_name RENAME TO index_name; +``` + +Also, unlike typical indexes which only affect performance, you may see different results for queries after adding an approximate index. ### Index Options