pgvector HNSW Index Consistently Ignored by Planner on Supabase (v0.8.0) #35432
Unanswered
pearcircuitmike
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Environment:
psqlconnection)public."arxivPapersData"(~250k+ rows)embedding vector(1536)CREATE INDEX idx_arxivpapersdata_embedding_hnsw ON public."arxivPapersData" USING hnsw (embedding vector_cosine_ops)Problem:
We're encountering a persistent issue where the PostgreSQL query planner consistently fails to utilize our HNSW index (
idx_arxivpapersdata_embedding_hnsw) for vector similarity searches using the cosine distance operator (<=>). All queries involvingembedding <=> query_vecfall back to slow sequential scans and nested loops, leading to significant performance degradation and timeouts, even after extensive troubleshooting.Troubleshooting Steps Performed:
hnsw, hasvector_cosine_ops, is populated, and has a size of ~1GB usingpg_indexes. The definition appears correct.ANALYZE public."arxivPapersData";. This did not change the query plan.REINDEX INDEX public.idx_arxivpapersdata_embedding_hnsw;via a directpsqlconnection (required due to platform timeouts). This completed successfully but did not change query plans.EXPLAIN ANALYZE):WHERE embedding <=> query_vec < threshold ORDER BY embedding <=> query_vec LIMIT N.distance < 0.1).ORDER BY embedding <=> query_vec LIMIT N).SET LOCAL enable_seqscan = off;to disable sequential scans. The planner still chose a (now artificially very high cost) sequential scan, indicating it saw no valid plan using the HNSW index.EXPLAIN ANALYZEon queries targeting other indexes on the same table:publishedDate: Used correctly.title/arxivId: Used correctly.arxivCategories: Not used (planner chose fast Seq Scan forLIMIT 10).totalScore: Not used (planner chose Parallel Seq Scan + Sort).Key Evidence (Simplest KNN Query Plan):
Even the most basic query designed for HNSW fails to use the index:
Query:
Resulting Plan Snippet (showing Seq Scan, not Index Scan):
Question:
Has anyone encountered a similar situation where the planner consistently ignores a valid HNSW index, particularly on Supabase or with pgvector 0.8.0? Are there any known planner bugs, configuration issues (beyond standard ANALYZE/REINDEX), or extension interactions that could cause this behavior? Any insights or suggestions would be greatly appreciated.
(We have also submitted a support ticket to Supabase).
All reactions