pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #784: HNSW Index Cost Computation
3+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #784: HNSW Index Cost Computation
@ 2025-02-24 06:38  "Masrt200 (@Masrt200)" <noreply+Masrt200@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Masrt200 (@Masrt200) @ 2025-02-24 06:38 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi,

I have two datasets one with 128 dimensions and another with 768 dimensions, both have the same number of vectors (10 million). Both indexes are created with the same construction parameters.

When I run a filter query (id < 10000) on the `id` colum, it does seq-scan for the 768 case but uses the hnsw index for the 128 dimension case. `id` is sorted in ascending order.  iterative_scan is off.

I looked at the cost estimation function and it uses `m` and `ef_search` to compute the cost. I tried setting `ef_search` to the maximum value and it still uses the index for the 128-dim case. The 768-dim case starts using seq-scan for a low value of `ef_search`.

Since there are only 10000 vectors, seq-scan gives better performance in this, and I want the planner to behave that way by default. 

Is the size of the vectors, the reason for this behaviour? Also are there any plans to use the iterative_scan parameters in the cost calculation? Any insights would be helpful.

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] issue #784: HNSW Index Cost Computation
@ 2025-02-24 07:44  "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-02-24 07:44 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @Masrt200,

The difference is likely due to the [storage strategy](https://www.postgresql.org/docs/current/storage-toast.html). Vectors with 768 are stored out-of-line by default, so only ones that match the `WHERE` condition need to be loaded. Vectors with 128 dimensions are stored inline by default, so it's more expensive to scan the table.

Re `iterative_scan`: The planner expects all scans to be iterative, so this is already taken into account (see #686).

A few questions:

1. What version of pgvector are you on?
2. What's the output of `EXPLAIN (ANALYZE, BUFFERS, SETTINGS)` for the queries with `SET enable_seqscan = off;`?
3. What's the output of `EXPLAIN (ANALYZE, BUFFERS, SETTINGS)` for the queries with `SET enable_indexscan = off;`?

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] issue #784: HNSW Index Cost Computation
@ 2025-03-03 17:05  "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-03-03 17:05 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-03-03 17:05 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-02-24 06:38 [pgvector/pgvector] issue #784: HNSW Index Cost Computation "Masrt200 (@Masrt200)" <noreply+Masrt200@github.com>
2025-02-24 07:44 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-03-03 17:05 ` "ankane (@ankane)" <noreply+ankane@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox