Skip to content

fix(main): Write to mysql in bulk#19123

Merged
erezrokah merged 6 commits intocloudquery:mainfrom
jsifuentes:fix/bulk-write-mysql
Sep 16, 2024
Merged

fix(main): Write to mysql in bulk#19123
erezrokah merged 6 commits intocloudquery:mainfrom
jsifuentes:fix/bulk-write-mysql

Conversation

@jsifuentes
Copy link
Copy Markdown
Contributor

@jsifuentes jsifuentes commented Sep 7, 2024

Summary

Fixes #19122

Before, the INSERT query was built within the appendTableBatch and overwriteTableBatch functions. But we aren't yet aware of how many rows need to be inserted, so we don't know how many value blocks to add. Rows are iterated within writeResources to create the final records to insert, so this is an opportunity to calculate a row count. So I moved the query building to within writeResources and constructed the INSERT query based on the amount of rows to be inserted.

This reduced the time to write 27,000 records from 20 minutes to under 1 minute.

@jsifuentes jsifuentes requested review from a team, erezrokah and maaarcelino and removed request for a team September 7, 2024 04:20
@jsifuentes jsifuentes changed the title f8x fix: write to mysql in bulk Sep 7, 2024
@jsifuentes jsifuentes changed the title fix: write to mysql in bulk fix(mysql): write to mysql in bulk Sep 7, 2024
@jsifuentes jsifuentes changed the title fix(mysql): write to mysql in bulk fix(main): write to mysql in bulk Sep 7, 2024
@jsifuentes jsifuentes changed the title fix(main): write to mysql in bulk fix(main): Write to mysql in bulk Sep 7, 2024
@yevgenypats
Copy link
Copy Markdown
Contributor

Hey @jsifuentes , Thanks so much for submitting this PR! There might some short delay for the review here as our team is at an offsite at the moment.

@erezrokah erezrokah removed the request for review from maaarcelino September 13, 2024 09:11
@erezrokah erezrokah self-assigned this Sep 13, 2024
Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @jsifuentes looks great. Sorry for the late review, I wanted to make sure we're not hitting query size limits. Looks like our batching limits prevent that from happening (unless someone increases them simnifically).

I also added a test to see, on my local machine the improvement of the test time was fro m 127.894s to 39.591s which is a great 🚀

@erezrokah erezrokah merged commit 0d1b9d5 into cloudquery:main Sep 16, 2024
kodiakhq bot pushed a commit that referenced this pull request Sep 16, 2024
🤖 I have created a release *beep* *boop*
---


## [5.2.8](plugins-destination-mysql-v5.2.7...plugins-destination-mysql-v5.2.8) (2024-09-16)


### Bug Fixes

* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.62.0 ([#19137](#19137)) ([ed315d0](ed315d0))
* **main:** Write to mysql in bulk ([#19123](#19123)) ([0d1b9d5](0d1b9d5))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@erezrokah
Copy link
Copy Markdown
Member

erezrokah commented Sep 16, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mysql destination does not actually bulk write to the database

4 participants