pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #1047: IVFFlat validation accepts a halfvec operator class missing required type-info support function 5
3+ messages / 2 participants
[nested] [flat]
* [pgvector/pgvector] issue #1047: IVFFlat validation accepts a halfvec operator class missing required type-info support function 5
@ 2026-10-26 11:57 "leemeii (@leemeii)" <noreply+leemeii@github.com>
0 siblings, 0 replies; 3+ messages in thread
From: leemeii (@leemeii) @ 2026-10-26 11:57 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
## Summary
`ivfflatvalidate()` unconditionally returns `true`, allowing an IVFFlat operator class for `halfvec` to be accepted even when it omits the required type-info support function 5.
When the index is subsequently created, `IvfflatGetTypeInfo()` falls back to the default `vector` type callbacks instead of rejecting the incomplete operator class. These callbacks are incompatible with `halfvec`, causing index creation to fail at runtime.
This is a validation correctness issue: an invalid operator class passes validation but cannot safely be used to build an index.
## Steps to reproduce
Run the following SQL against a PostgreSQL instance with pgvector installed.
Save it as `repro_ivfflat_halfvec_typeinfo.sql`:
```sql
CREATE EXTENSION IF NOT EXISTS vector;
-- Clean up objects from a previous run.
DROP TABLE IF EXISTS repro_ivfflat_halfvec_typeinfo CASCADE;
DROP OPERATOR CLASS IF EXISTS
repro_ivfflat_halfvec_typeinfo USING ivfflat;
-- Create a minimal halfvec table.
CREATE TABLE repro_ivfflat_halfvec_typeinfo (
v halfvec(2)
);
INSERT INTO repro_ivfflat_halfvec_typeinfo
VALUES ('[1,2]'::halfvec(2));
-- Define an IVFFlat operator class without support function 5.
CREATE OPERATOR CLASS repro_ivfflat_halfvec_typeinfo
FOR TYPE halfvec USING ivfflat AS
OPERATOR 1 <-> (halfvec, halfvec) FOR ORDER BY float_ops,
FUNCTION 1 halfvec_l2_squared_distance(halfvec, halfvec),
FUNCTION 3 l2_distance(halfvec, halfvec);
-- Validation unexpectedly succeeds.
SELECT amvalidate(oid) AS valid
FROM pg_opclass
WHERE opcname = 'repro_ivfflat_halfvec_typeinfo';
-- Index creation is expected to fail because the type-info
-- callback is missing and the default vector callbacks are used.
CREATE INDEX repro_ivfflat_halfvec_typeinfo_idx
ON repro_ivfflat_halfvec_typeinfo
USING ivfflat (v repro_ivfflat_halfvec_typeinfo)
WITH (lists = 1);
-- Cleanup. psql must continue after the expected CREATE INDEX error.
DROP TABLE IF EXISTS repro_ivfflat_halfvec_typeinfo CASCADE;
DROP OPERATOR CLASS IF EXISTS
repro_ivfflat_halfvec_typeinfo USING ivfflat;
```
Run it with:
```bash
psql -X -d your_database -f repro_ivfflat_halfvec_typeinfo.sql
```
Use the default `psql` error-handling behavior for this demonstration; do not enable `ON_ERROR_STOP`, so the cleanup statements can run after the expected index-creation error.
## Expected behavior
The operator class should be rejected during validation because it lacks the required type-info callback for `halfvec`.
The `amvalidate()` result should be `false`, or the invalid definition should otherwise be rejected before it can be used to create an index.
## Actual behavior
1. The custom operator class is created without support function 5.
2. `amvalidate()` returns `true`.
3. `CREATE INDEX` proceeds into the IVFFlat implementation.
4. `IvfflatGetTypeInfo()` falls back to the default `vector` type callbacks.
5. Index creation fails at runtime because those callbacks are incompatible with `halfvec`.
The validation stage therefore accepts an operator class that cannot safely be used by the access method.
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #1047: IVFFlat validation accepts a halfvec operator class missing required type-info support function 5
@ 2026-10-26 19:23 "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-10-26 19:23 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @leemeii, I think the validation level is in line with the built-in index types at this point. Ultimately, ["it is the user's responsibility to define a valid operator class"](https://www.postgresql.org/docs/current/sql-createopclass.html), which is why it requires a superuser.
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #1047: IVFFlat validation accepts a halfvec operator class missing required type-info support function 5
@ 2026-10-26 19:23 "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-10-26 19:23 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-26 19:23 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 11:57 [pgvector/pgvector] issue #1047: IVFFlat validation accepts a halfvec operator class missing required type-info support function 5 "leemeii (@leemeii)" <noreply+leemeii@github.com>
2026-10-26 19:23 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-10-26 19:23 ` "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