Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELECT * FROM pg_vector_index_stat does not work with partitions #477

Closed
ydylla opened this issue May 12, 2024 · 4 comments · Fixed by #478
Closed

SELECT * FROM pg_vector_index_stat does not work with partitions #477

ydylla opened this issue May 12, 2024 · 4 comments · Fixed by #478
Assignees
Labels
type/bug 🐛 type/question 🙋 Further information is requested

Comments

@ydylla
Copy link

ydylla commented May 12, 2024

Hi,
I noticed that SELECT * FROM pg_vector_index_stat does not work when an index for a partitioned table was created. It produces the following error: [XX000] ERROR: pgvecto.rs: The index is not existing in the background worker..

Here is a reproducer for Postgres 15 and pgvecto.rs 0.2.1 based on the existing partition.slt:

CREATE TABLE items (val vector(3), category_id int) PARTITION BY LIST(category_id);

CREATE TABLE id_123 PARTITION OF items FOR VALUES IN (1, 2, 3);
CREATE TABLE id_456 PARTITION OF items FOR VALUES IN (4, 5, 6);

INSERT INTO items (val, category_id)
SELECT
    ARRAY[random(), random(), random()]::real[],
    (random() * 5 + 1)::int
FROM generate_series(1, 1000);

CREATE INDEX ON items USING vectors (val vector_l2_ops);

SELECT * FROM pg_vector_index_stat; -- fails
SELECT * FROM pg_vector_index_stat WHERE indexname = 'items_val_idx'; -- fails
SELECT * FROM pg_vector_index_stat WHERE indexname = 'id_123_val_idx'; -- works
@usamoi
Copy link
Collaborator

usamoi commented May 15, 2024

It'll be fixed in next version and you could use

CREATE OR REPLACE VIEW pg_vector_index_stat AS
    SELECT
        C.oid AS tablerelid,
        I.oid AS indexrelid,
        C.relname AS tablename,
        I.relname AS indexname,
        (_vectors_index_stat(I.oid)).*
    FROM pg_class C JOIN
         pg_index X ON C.oid = X.indrelid JOIN
         pg_class I ON I.oid = X.indexrelid JOIN
         pg_am A ON A.oid = I.relam
    WHERE A.amname = 'vectors' AND C.relkind = 'r';

to fix the behavior in current version.

@ydylla
Copy link
Author

ydylla commented May 15, 2024

Thanks for the quick reply @usamoi.
I tried your workaround but now I get a different error [XX000] ERROR: oid_ is null and even the query that previously did work now no longer works. Somehow I bricked it 😅 since even going back to the view without the AND C.relkind = 'r' fix is now broken. I guess I have to reinstall the extension, luckily it's just a test setup.

@usamoi
Copy link
Collaborator

usamoi commented May 16, 2024

Thanks for the quick reply @usamoi. I tried your workaround but now I get a different error [XX000] ERROR: oid_ is null and even the query that previously did work now no longer works. Somehow I bricked it 😅 since even going back to the view without the AND C.relkind = 'r' fix is now broken. I guess I have to reinstall the extension, luckily it's just a test setup.

Feel sorry for it. I forgot that the view is changed in development branch since v0.2.1.

If you are using v0.2.1,

CREATE OR REPLACE VIEW pg_vector_index_stat AS
    SELECT
        C.oid AS tablerelid,
        I.oid AS indexrelid,
        C.relname AS tablename,
        I.relname AS indexname,
        (_vectors_index_stat(I.relfilenode)).*
    FROM pg_class C JOIN
         pg_index X ON C.oid = X.indrelid JOIN
         pg_class I ON I.oid = X.indexrelid JOIN
         pg_am A ON A.oid = I.relam
    WHERE A.amname = 'vectors' AND C.relkind = 'r';

should work.

@ydylla
Copy link
Author

ydylla commented May 16, 2024

It still produces the same error. But don't worry I will just reinstall the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug 🐛 type/question 🙋 Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants