pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #875: HNSW index causes important performance degradation for UPDATE statements on non-vector columns
3+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #875: HNSW index causes important performance degradation for UPDATE statements on non-vector columns
@ 2025-07-20 21:16 "plagree (@plagree)" <noreply+plagree@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: plagree (@plagree) @ 2025-07-20 21:16 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

I'm experiencing severe performance issues when updating non-vector columns in tables that have HNSW vector indexes. The UPDATE statements become (very) much slower even though the vector column itself is not being modified.

**Minimal reproduction:**

```sql
-- Table with HNSW index
CREATE TABLE test_table (
    id SERIAL PRIMARY KEY,
    name TEXT,
    embedding vector(1536)
);

INSERT INTO test_table (name, embedding) 
SELECT 'item_' || i, array_fill(random(), ARRAY[1536])::vector(1536)
FROM generate_series(1, 10000) i;

SET maintenance_work_mem = '256MB';

CREATE INDEX test_embedding_idx ON test_table 
USING hnsw (embedding vector_cosine_ops);

-- This UPDATE is extremely slow despite not touching the vector column
UPDATE test_table SET name = 'updated';
```

**Performance impact:**
- **With HNSW index:** ~6s for updating 10k rows (3.7M buffer hits!)
- **Without HNSW index:** 58ms for 10k rows (59k buffer hits)

**EXPLAIN ANALYZE shows:**
- Much higher buffer usage when HNSW index is present
- Same execution plan otherwise
- No apparent reason why a non-vector column update should touch the vector index

**Environment:**
- PostgreSQL version: `17`
- pgvector version: ` 0.8.0`

**Questions:**
1. Is this expected behavior for HNSW indexes?
2. Should updates to non-vector columns trigger HNSW index maintenance?
3. Are there any workarounds besides dropping/recreating the index for bulk updates? Or should I just split in 2 table with one-to-one relation where 1 table only contains vectors and another contains all the other fields that receive frequent updates etc.?

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

* Re: [pgvector/pgvector] issue #875: HNSW index causes important performance degradation for UPDATE statements on non-vector columns
@ 2025-07-21 01:40 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-07-21 01:40 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @plagree, see https://github.com/pgvector/pgvector/issues/810#issuecomment-2760152872 for 1 and 2.

For 3, a one-to-one relation would probably work best.

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

* Re: [pgvector/pgvector] issue #875: HNSW index causes important performance degradation for UPDATE statements on non-vector columns
@ 2025-07-21 01:40 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-07-21 01:40 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-07-21 01:40 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-07-20 21:16 [pgvector/pgvector] issue #875: HNSW index causes important performance degradation for UPDATE statements on non-vector columns "plagree (@plagree)" <noreply+plagree@github.com>
2025-07-21 01:40 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-07-21 01:40 ` "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