From: sainnhe (@sainnhe) <noreply+sainnhe@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #842: Inserting a new row will cause index not been hit.
Date: Thu, 22 May 2025 13:57:31 +0000
Message-ID: <gh-pgvector-pgvector-842@github.com> (raw)
## Description
I created a table and create an index on a halfvec column.
I inserted 4 new records, and executed `explain`. At present, it hits index.
But if I insert a new record, and re-execute `explain`, the index will not be hit.
## Steps to reproduce
This bug can be reproduced in the following environment:
1. macOS 15.5 (arm64)
2. ArchLinux (x86_64)
```text
.
├── compose.yml
└── docker-entrypoint-initdb.d
└── 00-pic_material.sql
```
1. Create a docker compose file `compose.yml` and launch pgvector container
```yaml
services:
# Login command: PGPASSWORD=test psql -h localhost -p 5432 -U test test
db:
image: pgvector/pgvector:pg17
container_name: db
restart: always
ports:
- 5432:5432
volumes:
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
environment:
- POSTGRES_USER=test
- POSTGRES_PASSWORD=test
- POSTGRES_DB=test
```
In `docker-entrypoint-initdb.d/00-pic_material.sql`, copy and paste the content of the following file:
[00-pic_material.sql.zip](https://github.com/user-attachments/files/20393663/00-pic_material.sql.zip)
Launch docker compose:
```
docker compose up -d
```
You can check the log of this container via `docker logs db`. The sql should be successfully executed.
If you have permission issue, execute `chmod -R a+rX docker-entrypoint-initdb.d`
You can also use the following command to execute the sql file:
```
PGPASSWORD=test psql -h localhost -p 5432 -U test test < /path/to/sql
```
In this sql file, you can see that I inserted 4 records. But if you uncomment the 5th insertion statement and execute `explain`, you'll find that the index will not be hit.
Before uncomment:

After uncomment:
