mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.5k stars 302 forks source link

Formatting a Query with large IN criteria is very slow #977

Closed sivaramasubramanian closed 2 years ago

sivaramasubramanian commented 2 years ago

Describe the bug Formatting the attached SQL Query with SQLTools formatter takes more than 25-30 seconds. I'm using an M1 Macbook Pro with 16GB RAM so the hardware must not be much of an issue here.

The Query has a large number of values in IN ( ... ) expression (around 5000), when formatted each of these values will be in a newline, this might be causing the slowness. When I reduce the no. of values in IN() the formatting is quicker

To Reproduce Steps to reproduce the behavior:

  1. Paste the attached Query in VS Code
  2. Right-click -> Format Document
  3. Observe that formatting takes a long time to complete

Expected behavior Formatting should be completed in less than 1s.

Desktop (please complete the following information):

Additional context sample.sql.txt

sivaramasubramanian commented 2 years ago

I have raised PR #978 with a fix that somewhat improves the performance.

sivaramasubramanian commented 2 years ago

@gjsjohnmurray Thanks for reviewing and merging the change.

When is the next release planned? Also, the NPM package for the formatter ( https://www.npmjs.com/package/@sqltools/formatter ) has not been updated in the last 2 years. Are there any plans to update the NPM package too?