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

Queries containing embedded comments may fail because they contain a semicolon #3

Closed
burggraf opened this issue Apr 1, 2023 · 2 comments · Fixed by #5
Closed

Queries containing embedded comments may fail because they contain a semicolon #3

burggraf opened this issue Apr 1, 2023 · 2 comments · Fixed by #5
Assignees

Comments

@burggraf
Copy link
Member

burggraf commented Apr 1, 2023

Queries obtained from pg_stat_statement often contain embedded comments which often contain a semicolon. This causes index_advisor to throw an error even though the semicolon doesn't exist in the actual SQL statement.

To fix this, queries should be run through a function to strip embedded comments:

trim(regexp_replace(
         regexp_replace(
            regexp_replace(query,'\/\*.+\*\/','','g'),
         '--[^\r\n]*', ' ', 'g')
      , '\s+', ' ', 'g'))
@olirice
Copy link
Collaborator

olirice commented Apr 7, 2023

I'm surprised that comments with semicolons is that common, could you give me an example for context?

the solution sounds good though, are you 100% confident on that regex?

@burggraf
Copy link
Member Author

I've tested the regex and it's been solid for me. These comments happen 100% of the time if you look at pg_stat_statements for a project that uses the javascript library (PostgREST).

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 a pull request may close this issue.

2 participants