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

Query to find B-tree indexes on array columns #35

Merged

Conversation

mfaulther
Copy link
Collaborator

Query to find B-tree indexes on array columns

mfvanek/pg-index-health#364

@mfaulther mfaulther force-pushed the feature/btree-indexes-on-array-columns-check branch 2 times, most recently from cd754f6 to 58b6118 Compare April 21, 2024 18:44
@mfvanek
Copy link
Owner

mfvanek commented Apr 21, 2024

Hi @mfaulther,
Thanks for contribution!
Ther are some linter issues:

== [/github/workspace/sql/btree_indexes_on_array_columns.sql] FAIL
L:  23 | P:  20 | RF02 | Unqualified reference '*' found in select with more than
                       | one referenced table/view. [references.qualification]
L:  26 | P:  41 | LT06 | Function name not immediately followed by parenthesis.
                       | [layout.functions]
L:  26 | P:  60 | RF02 | Unqualified reference 'indkey' found in select with more
                       | than one referenced table/view.
                       | [references.qualification]
L:  26 | P:  87 |  PRS | Line 26, Position 87: Found unparsable section:
                       | '[1:indnkeyatts]'
L:  27 | P:  47 | LT12 | Files must end with a single trailing newline.
                       | [layout.end-of-file]

How to run linter locally

To run super-linter locally

sql/btree_indexes_on_array_columns.sql Outdated Show resolved Hide resolved
@mfaulther mfaulther force-pushed the feature/btree-indexes-on-array-columns-check branch from 58b6118 to 35ea7e3 Compare April 21, 2024 18:59
@mfvanek mfvanek mentioned this pull request Apr 22, 2024
@mfaulther
Copy link
Collaborator Author

@mfvanek
Linter has failed on this line:

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

with message:

== [/tmp/lint/sql/btree_indexes_on_array_columns.sql] FAIL
L:  26 | P:  88 |  PRS | Line 26, Position 88: Found unparsable section:
                       | '[1:indnkeyatts]'

But actually it's correct (i checked this query locally, it works correctly without syntax errors)

Found that sqlfluff had bugs with parsing postgres array slices (1,2), that were fixed in version 2.0.4

Can i bump the version of github/super-linter/ from slim-v5 to slim-v6 ? It should help to fix it.

Also, there's another option:
I can change this line:

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

to

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

(simply change [1:indnkeyatts] to [:indnkeyatts])
with this change the linter doesn't fail with version slim-v5

@mfvanek
Copy link
Owner

mfvanek commented Apr 23, 2024

@mfaulther

Can i bump the version of github/super-linter/ from slim-v5 to slim-v6 ?

Yes, sure!

@mfaulther mfaulther requested a review from mfvanek April 23, 2024 20:18
Copy link
Owner

@mfvanek mfvanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfaulther
Great job! Need only some polish

sql/bloated_indexes.sql Outdated Show resolved Hide resolved
sql/btree_indexes_on_array_columns.sql Outdated Show resolved Hide resolved
sql/btree_indexes_on_array_columns.sql Outdated Show resolved Hide resolved
@mfaulther mfaulther requested a review from mfvanek April 25, 2024 18:16
@mfvanek mfvanek merged commit 7d9e0c6 into mfvanek:master Apr 25, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants