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

What about having helpers for indexes analysis? #282

Open
EQuincerot opened this issue Mar 28, 2023 · 1 comment
Open

What about having helpers for indexes analysis? #282

EQuincerot opened this issue Mar 28, 2023 · 1 comment

Comments

@EQuincerot
Copy link

EQuincerot commented Mar 28, 2023

Hello,

First of all, thanks for your gem! That's very useful.

I developed some wrapper to pg_query to ease the parsing of pg_query tree for indexes.
Do you think that would be valuable to include that in pg_query?

Example:

my_indexes = IndexDefinition.list(connection)
my_indexes = IndexDefinition.list(connection, pattern: '%deleted_at IS NULL%')
my_indexes = IndexDefinition.list(connection, table_name: 'accounts')

On IndexDefinition class we would have such methods:

  • #name
  • #table_name
  • #definition
  • #composite?
  • #indexed_columns
  • #partial_index?
  • #where_clause

If you think it's interesting I could prepare a PR for that.
If not, I would probably create a dedicated project :)

@lfittl
Copy link
Member

lfittl commented Mar 28, 2023

First of all, thanks for your gem! That's very useful.

Glad to see you find it useful!

I developed some wrapper to pg_query to ease the parsing of pg_query tree for indexes. Do you think that would be valuable to include that in pg_query?

Do I understand correctly that the aim of the methods is to find potential index elements in a given parse tree?

Assuming yes, I think that could certainly be useful, so +1 to opening a PR on pg_query.

Just to note, we have something similar inside in pganalyze (though we actually do it based on a version of a generic plan tree), but I think it'd be helpful to have something simple directly in pg_query as well.

Out of curiosity, how are you handling unqualified column names? (I imagine ideally this would take a table definition, so you know which column relates to which table?)

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

No branches or pull requests

2 participants