[Pg-kit] fix: use opcname instead of amname for index operator class introspection#5496
Open
sleitor wants to merge 1 commit intodrizzle-team:betafrom
Open
[Pg-kit] fix: use opcname instead of amname for index operator class introspection#5496sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor wants to merge 1 commit intodrizzle-team:betafrom
Conversation
…erator class introspection Fixes drizzle-team#5495 When introspecting PostgreSQL indexes (e.g. ivfflat from pgvector), the operator class subquery was joining pg_am and using amname (the access method name, e.g. 'ivfflat') instead of pg_opclass.opcname (the actual operator class name, e.g. 'vector_cosine_ops'). This caused drizzle-kit pull to generate incorrect SQL like: CREATE INDEX ... USING ivfflat (embedding ivfflat) instead of: CREATE INDEX ... USING ivfflat (embedding vector_cosine_ops) Fix: replace pg_am.amname with pg_opclass.opcname in the opclasses array subquery and remove the now-unnecessary pg_am JOIN. Applies to both postgres/introspect.ts and postgres/aws-introspect.ts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #5495
When running
drizzle-kit pullagainst PostgreSQL databases with pgvectorivfflatindexes (or other non-default access methods), the generated schema uses the access method name (ivfflat) in the operator class position instead of the actual operator class (e.g.vector_cosine_ops).Incorrect output:
which generates invalid SQL:
Root Cause
In
drizzle-kit/src/dialects/postgres/introspect.ts(andaws-introspect.ts), the opclasses subquery built an array of{oid, name, default}objects for each index column, but usedpg_am.amname(the access method name) instead ofpg_opclass.opcname(the operator class name).Fix
Replace
pg_am.amnamewithpg_opclass.opcnamein the opclasses subquery, and remove the now-unnecessaryJOIN pg_catalog.pg_amfrom that subquery (the outer query already joinspg_amfor the index access method).Correct output:
which generates valid SQL:
Changes
drizzle-kit/src/dialects/postgres/introspect.ts: usepg_opclass.opcnameinstead ofpg_am.amname, remove unusedpg_amJOIN from opclasses subquerydrizzle-kit/src/dialects/postgres/aws-introspect.ts: same fixdrizzle-kit/tests/postgres/pull.test.ts: add test for ivfflat index opclass introspection using PGlite's vector extension