pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #1040: Performance bug: Equivalent AND-TRUE identity filter causes up to 208.99x search latency difference
3+ messages / 2 participants
[nested] [flat]
* [pgvector/pgvector] issue #1040: Performance bug: Equivalent AND-TRUE identity filter causes up to 208.99x search latency difference
@ 2026-10-14 04:05 "beyond-mountains (@beyond-mountains)" <noreply+beyond-mountains@github.com>
0 siblings, 0 replies; 3+ messages in thread
From: beyond-mountains (@beyond-mountains) @ 2026-10-14 04:05 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
**Summary**
Equivalent representation: `F is equivalent to F AND TRUE AND ... AND TRUE`.
With the same table, vector, HNSW parameters, and eligible row set, the equivalent predicate representation causes a reproduced 208.994x client end-to-end ANN latency difference. The same case also changes Recall@10 from 0.0000 to 1.0000, despite identical eligible IDs and exact Top-K results.
**Environment**
- Backend: PostgreSQL + pgvector
- PostgreSQL: 15.17 (Debian 15.17-1.pgdg12+1), x86_64
- pgvector: 0.8.2
- Client: psycopg2-binary 2.9.10, Python 3.12
- Deployment: Docker, `pgvector/pgvector:pg15`
- Container resources: 8 physical CPU cores, 32 GiB memory, 8 GiB shared memory
- PostgreSQL settings: `shared_buffers=8GB`, `work_mem=256MB`, `max_parallel_workers_per_gather=0`
- Dataset/index: 200,000 vectors, 128 dimensions, COSINE distance, HNSW M=16, ef_construction=128
**Metadata schema and distribution**
All metadata columns are `NOT NULL`.
| Column | SQL type | Generation |
|---|---|---|
| `id` | BIGINT PRIMARY KEY | sequential values 0 through 199999 |
| `embedding` | vector(128) | normalized vectors described below |
| `tenant` | INTEGER | uniform integer in [0, 99] |
| `level` | INTEGER | uniform integer in [0, 31] |
| `category` | INTEGER | `tenant + 1` |
| `category5` | INTEGER | `tenant % 5 + 1` |
| `age` | INTEGER | uniform integer in [1, 1000] |
| `parity` | TEXT | `even` for even tenants, otherwise `odd` |
B-tree indexes are present on all metadata columns. The vector index is:
```sql
CREATE INDEX efa_pgvector_full_hnsw
ON efa_pgvector_full USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 128);
```
**Current Behavior**
The two filters select the same 16,218 rows (8.1090% selectivity), but have substantially different ANN latency.
| Measurement | Original filter | Equivalent filter |
|---|---:|---:|
| Eligible rows | 16,218 | 16,218 |
| ANN p50 | 1.1961 ms | 249.9680 ms |
| Exact sequential-scan p50 | 87.0451 ms | 253.2950 ms |
| Recall@10 | 0.0000 | 1.0000 |
- ANN symmetric latency ratio: 208.994x
- Equivalent/original latency ratio: 208.994x
- Exact symmetric latency ratio: 2.910x
- Recall gap: 1.0000
- Eligible-set equality: `True`
- Exact Top-K equality: `True`
**Expected Behavior**
Semantically equivalent filters should select the same rows and should not cause an unexpectedly large latency or Recall@K difference when the query vector, table, HNSW index, `top_k`, and `hnsw.ef_search` are unchanged.
**Steps To Reproduce**
1. Create the table and indexes:
```sql
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE efa_pgvector_full (
id BIGINT PRIMARY KEY,
embedding vector(128) NOT NULL,
tenant INTEGER NOT NULL,
level INTEGER NOT NULL,
category INTEGER NOT NULL,
category5 INTEGER NOT NULL,
age INTEGER NOT NULL,
parity TEXT NOT NULL
);
CREATE INDEX efa_pgvector_full_hnsw
ON efa_pgvector_full USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 128);
CREATE INDEX ON efa_pgvector_full (tenant);
CREATE INDEX ON efa_pgvector_full (level);
CREATE INDEX ON efa_pgvector_full (category);
CREATE INDEX ON efa_pgvector_full (category5);
CREATE INDEX ON efa_pgvector_full (age);
CREATE INDEX ON efa_pgvector_full (parity);
ANALYZE efa_pgvector_full;
```
2. Generate rows with NumPy `default_rng(20261002)`. Generate one normalized random center for each of 100 tenants. With `c = 0.85`, calculate each vector as `c * center[tenant] + sqrt(1-c*c) * normalized_noise`, then normalize it. Populate metadata using the table above.
3. Use this original filter:
```sql
age BETWEEN 10 AND 90
```
Equivalent filter, abbreviated:
```text
age BETWEEN 10 AND 90 followed by category5 IN (1,2,3,4,5) 128 times with AND
```
Construct the complete predicate with:
```python
original_filter = "age BETWEEN 10 AND 90"
true_predicate = "category5 IN (1, 2, 3, 4, 5)"
equivalent_filter = f"({original_filter}) AND " + " AND ".join(
f"({true_predicate})" for _ in range(128)
)
```
4. Generate four query vectors with NumPy `default_rng(20261003)` by selecting an eligible tenant center, adding normal noise with standard deviation 0.03, and normalizing. For ANN search, run:
```sql
SET enable_seqscan = off;
SET enable_indexscan = on;
SET hnsw.ef_search = 16;
SELECT id
FROM efa_pgvector_full
WHERE <FILTER_EXPRESSION>
ORDER BY embedding <=> $1::vector
LIMIT 10;
```
5. For each query vector, execute four warmup pairs followed by ten measured pairs in a deterministic randomized order containing exactly five original→equivalent and five equivalent→original pairs. Use the per-query median and then the median across the four queries. For the exact control, run two balanced-order repetitions with sequential scans enabled and index/bitmap scans disabled.
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #1040: Performance bug: Equivalent AND-TRUE identity filter causes up to 208.99x search latency difference
@ 2026-10-14 04:10 ` "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-10-14 04:10 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @beyond-mountains, see #1034 and #1035.
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #1040: Performance bug: Equivalent AND-TRUE identity filter causes up to 208.99x search latency difference
@ 2026-10-14 04:10 ` "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-10-14 04:10 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:[~2026-10-14 04:10 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 04:05 [pgvector/pgvector] issue #1040: Performance bug: Equivalent AND-TRUE identity filter causes up to 208.99x search latency difference "beyond-mountains (@beyond-mountains)" <noreply+beyond-mountains@github.com>
2026-10-14 04:10 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-10-14 04:10 ` "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