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

Support opclass_parameter in createIndex #1361

Open
benkroeger opened this issue Feb 24, 2025 · 0 comments
Open

Support opclass_parameter in createIndex #1361

benkroeger opened this issue Feb 24, 2025 · 0 comments
Labels
c: bug Something isn't working has workaround Workaround provided or linked help wanted Extra attention is needed p: 1-normal Nothing urgent

Comments

@benkroeger
Copy link
Contributor

benkroeger commented Feb 24, 2025

Description

Sometimes one might want to set parameters for specific opclasses when creating an index.
E.g. when using the ltree extension, setting the siglen parameter can be crucial to performance of that index.

Currently, the entire 'opclass' param is converted to mOptions.literal - which leads to postgres not finding the opclass at all

pgm.createIndex('container', [{ name: 'path', opclass: 'gist_ltree_ops(siglen=256)' }], { method: 'gist' } );

creates

CREATE INDEX "container__path_index" ON "container" USING gist ("path" "gist_ltree_ops(siglen=256)");

which leads to

ERROR:  operator class "gist_ltree_ops(siglen=256)" does not exist for access method "gist" 

SQL state: 42704

because postgres doesn't expect the opclass + parameter to be quoted

CREATE INDEX "container__path_index" ON "container" USING gist ("path" gist_ltree_ops(siglen=256));

Suggested solution

  • treat opclass not as litera
  • do not quote when opclass contains parameters
  • exclude parameters from quoted opclass argument

Alternative

the sourcecode in 7.9.0 emits a warning when using opclass option and recommends a syntax that doesn't align with the exported type interface - but I think it could solve the issue.
The 8.0.0-rc code doesn't emit that warning but uses the same opclass syntax and conversion as 7.9.0

Additional context

Current workaround is to include the opclass and parameters in the column name becuase detecting braces () in the name would treat them as expression and not quote at all

pgm.createIndex('container', [{ name: 'path gist_ltree_ops(siglen=256)' }], { method: 'gist' } );
@benkroeger benkroeger added the s: pending triage Pending Triage label Feb 24, 2025
@Shinigami92 Shinigami92 added c: bug Something isn't working has workaround Workaround provided or linked help wanted Extra attention is needed p: 1-normal Nothing urgent and removed s: pending triage Pending Triage labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working has workaround Workaround provided or linked help wanted Extra attention is needed p: 1-normal Nothing urgent
Projects
None yet
Development

No branches or pull requests

2 participants