pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #842: Inserting a new row will cause index not been hit.
3+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #842: Inserting a new row will cause index not been hit.
@ 2025-05-22 13:57 "sainnhe (@sainnhe)" <noreply+sainnhe@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: sainnhe (@sainnhe) @ 2025-05-22 13:57 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

## 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:

![before](https://share.sainnhe.dev/XfaP/4.png)

After uncomment:

![after](https://share.sainnhe.dev/ZK58/5.png)

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

* Re: [pgvector/pgvector] issue #842: Inserting a new row will cause index not been hit.
@ 2025-05-22 19:06 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

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

Hi @sainnhe, see the [troubleshooting docs](https://github.com/pgvector/pgvector?tab=readme-ov-file#why-isnt-a-query-using-an-index). For small tables, a table scan may be faster / just as fast.

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

* Re: [pgvector/pgvector] issue #842: Inserting a new row will cause index not been hit.
@ 2025-05-22 19:06 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2025-05-22 19:06 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-05-22 19:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-05-22 13:57 [pgvector/pgvector] issue #842: Inserting a new row will cause index not been hit. "sainnhe (@sainnhe)" <noreply+sainnhe@github.com>
2025-05-22 19:06 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-05-22 19:06 ` "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