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

Add check "Do not index arrays via btree - use gin instead" #364

Closed
mfvanek opened this issue Apr 7, 2024 · 10 comments
Closed

Add check "Do not index arrays via btree - use gin instead" #364

mfvanek opened this issue Apr 7, 2024 · 10 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@mfvanek
Copy link
Owner

mfvanek commented Apr 7, 2024

See https://habr.com/ru/articles/800121/

SELECT
    c.relname,  -- наименование отношения
    ic.relname, -- наименование индекса
    a.amname    -- тип индекса 
FROM pg_catalog.pg_index AS i
	INNER JOIN pg_catalog.pg_class AS ic ON i.indexrelid = ic.oid
    INNER JOIN pg_catalog.pg_am AS a ON ic.relam = a.oid AND a.amname = 'btree'
    INNER JOIN pg_catalog.pg_class AS c ON i.indrelid = c.oid
WHERE
    -- проверяем существование в индексе колонки с типом массива
    EXISTS (SELECT * FROM pg_catalog.pg_attribute AS att
                INNER JOIN pg_catalog.pg_type AS typ ON typ.oid = att.atttypid
                WHERE att.attrelid = i.indrelid
                    AND att.attnum = ANY ((string_to_array(indkey::text, ' ')::int2[])[1:indnkeyatts])
                    AND typ.typcategory = 'A')
@mfvanek mfvanek added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Apr 7, 2024
@mfaulther
Copy link
Collaborator

Hi, @mfvanek

May i take this issue ?

@mfvanek
Copy link
Owner Author

mfvanek commented Apr 16, 2024

Hi @mfaulther,

May i take this issue ?

Yeah, sure, fell free to contribute.

P.S. Recently I updated contributing guide

@mfvanek mfvanek added work in progress Work on this issue has already begun and removed help wanted Extra attention is needed good first issue Good for newcomers labels Apr 28, 2024
@mfvanek mfvanek added this to the 0.10.4 milestone Apr 28, 2024
@mfaulther
Copy link
Collaborator

@mfvanek
Found some problems with NamedParameterParser.
Placeholder substitution clashes with PostgreSQL array slicing, which is used in the SQL query for this task (as both use the symbol :).

This part of query (line 21):

and col.attnum = any((string_to_array(i.indkey::text, ' ')::int2[])[:i.indnkeyatts])

becomes:

and col.attnum = any((string_to_array(i.indkey::text, ' ')::int2[])[?.indnkeyatts])

which is not that we need

What do you think about adding support for escaping symbol \ ?

If i write:

and col.attnum = any((string_to_array(i.indkey::text, ' ')::int2[])[\:i.indnkeyatts])

symbol : will not be replaced with '?' and will remain as is:

and col.attnum = any((string_to_array(i.indkey::text, ' ')::int2[])[:i.indnkeyatts])

@mfvanek
Copy link
Owner Author

mfvanek commented Apr 29, 2024

Hi @mfaulther,
Thank you for feedback.

What do you think about adding support for escaping symbol \ ?

I think we need to support arrays operations as it was done in Spring
https://github.com/spring-projects/spring-framework/blob/main/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java

I'm going to fix it in 1-2 days.

@mfvanek
Copy link
Owner Author

mfvanek commented Apr 29, 2024

@mfaulther
It turned out to be much easier than I expected.
Fix is already in the master branch.

@mfvanek
Copy link
Owner Author

mfvanek commented May 3, 2024

Hi @mfaulther,
do you plan to send PRs to starter and demo apps?
If not I'll make it myself.
I'm going to release a new version this weekend.

@mfaulther
Copy link
Collaborator

Hi @mfvanek

do you plan to send PRs to starter and demo apps?

I'm going to do it this evening

@mfvanek
Copy link
Owner Author

mfvanek commented May 3, 2024

I'm going to do it this evening

Cool! I'll wait for your PR

@mfvanek
Copy link
Owner Author

mfvanek commented May 3, 2024

@mfaulther
I've just released pg-index-health version 0.11.0
Thank you very much for being part of it.

P.S. The next step is to release pg-index-health-test-starter

@mfvanek
Copy link
Owner Author

mfvanek commented May 4, 2024

@mfvanek mfvanek removed the work in progress Work on this issue has already begun label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants