-
Notifications
You must be signed in to change notification settings - Fork 49
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
♻️ Refactor SQL chunk processing to reduce memory errors #699
Conversation
🦋 Changeset detectedLatest commit: a387527 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CI Feedback 🧐(Feedback updated until commit 7e3a65d)A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
c749b2a
to
0badc26
Compare
0badc26
to
f08c5ee
Compare
f08c5ee
to
d714b0f
Compare
e13604a
to
de1bc5d
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Skipped Deployments
|
de1bc5d
to
7e3a65d
Compare
This refactor increases the likelihood of processing larger `.sql` files without encountering memory errors. - Updated `processor` to improve error handling and prevent unnecessary semicolon-related logic. - Modified `processSQLInChunks` to track read offsets and adjust chunk sizes dynamically. - Improved test cases to ensure SQL chunks are processed correctly, even when split mid-statement.
7e3a65d
to
fa395d0
Compare
- Added test cases to verify correct handling of `readOffset` when processing SQL chunks with incomplete statements. - Added test cases for `errorOffset` handling, including shrinking and expanding modes when parsing SQL statements larger than the chunk size.
- Introduced a new test case to verify that SQL statements exceeding 500 lines (surpassing CHUNK_SIZE) are parsed correctly without errors. - Added a `normal` test case in `createParserTestCases` for basic column validation. - Updated `index.test.ts` to include a test for handling long SQL statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
It looks fine!
'CREATE TABLE t1 (\n c1 int,\n c2 int,\n c3 int,\n c4 int\n);', | ||
[null, null, []], | ||
], | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test case is easy to understand 👍🏻
Co-authored-by: Hirotaka Miyagi <31152321+MH4GF@users.noreply.github.com>
Thanks, I'll merge now |
User description
closes #410
closes #688
♻️ Refactor SQL chunk processing to reduce memory errors
This refactor increases the likelihood of processing larger
.sql
files without encountering memory errors.processor
to improve error handling and prevent unnecessary semicolon-related logic.processSQLInChunks
to track read offsets and adjust chunk sizes dynamically.Cons:
The processing time for
mastodon db/structure.sql liam-hq's pg_dump
increases 😭( 0.84s -> 4.54s ). (It has not only DDLs, but also a little DMLs.) Reducing the chunk size has resulted in more frequent calls to theparse
function. This might lead to more.sql
files timing out in erd-web. However, since it reduces the likelihood of errors, I still want to proceed with this change.Related Issue
Testing
result:
main branch ( on 0cda4f4 ) :
this PR branch ( on 7e3a65d ) :
Other Information
PR Type
Enhancement, Tests
Description
Refactored SQL chunk processing to reduce memory errors.
Enhanced test cases for SQL chunk processing.
Added utility function to determine line numbers for error handling.
Changes walkthrough 📝
index.ts
Refactor `processor` for better SQL chunk handling
frontend/packages/db-structure/src/parser/sql/postgresql/index.ts
processor
to handle incomplete SQL statements.processSQLInChunks.ts
Refactor `processSQLInChunks` for dynamic chunk handling
frontend/packages/db-structure/src/parser/sql/postgresql/processSQLInChunks.ts
processSQLInChunks.test.ts
Enhance tests for SQL chunk processing
frontend/packages/db-structure/src/parser/sql/postgresql/processSQLInChunks.test.ts
cyan-crabs-kiss.md
Add changeset for SQL chunk processing refactor
.changeset/cyan-crabs-kiss.md
Footnotes
supabase.sql.txt ↩ ↩2
mastodon-structure.sql.txt ↩ ↩2