From: pearcircuitmike (@pearcircuitmike) <noreply+pearcircuitmike@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #584: Can't get the query planner to use HNSW index
Date: Fri, 02 May 2025 23:08:12 +0000
Message-ID: <gh-pgvector-pgvector-584-c2848252717@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-584@github.com>
References: <gh-pgvector-pgvector-584@github.com>
Hi @ankane and others,
Thanks for the discussion in this thread. I read through it as I'm facing a similar symptom (planner not using HNSW index) but with a different root cause.
In my case, I've confirmed I am using the correct operator (<=>) matching my index definition (USING hnsw (embedding vector_cosine_ops)).
Despite this, and even after running ANALYZE and successfully completing REINDEX via a direct connection, the query planner consistently ignores the HNSW index and falls back to a slow sequential scan, even for the simplest ORDER BY embedding <=> query_vec LIMIT N queries. Disabling sequential scans (SET enable_seqscan = off) also didn't force the index usage.
We've tested this on Supabase with PostgreSQL 15.6 (and also after upgrading to the latest minor version available) and pgvector 0.8.0. Other index types (B-tree, GIN FTS) on the same table are being used correctly by the planner.
It seems like a planner issue specific to HNSW evaluation in this environment. Has anyone else seen cases where a valid HNSW index with the matching operator is still ignored by the planner?
(We've also opened a support ticket with Supabase detailing these findings).
Any insights would be appreciated! Link to more details: https://github.com/orgs/supabase/discussions/35432