-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Optimize database foreign keys references - MySQL/MariaDB #12843
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
Conversation
make separate requests to each information_schema table instead of one with inner joins for much better performance on MySQL 5.7
@tiagolima90 can you sign the CLA before the engineers take a look? Thank you! |
|
@derrickmehaffy hi. CLA signed. Thanks. |
Codecov Report
@@ Coverage Diff @@
## master #12843 +/- ##
==========================================
- Coverage 54.25% 48.56% -5.69%
==========================================
Files 1198 242 -956
Lines 30598 8940 -21658
Branches 5571 2006 -3565
==========================================
- Hits 16601 4342 -12259
+ Misses 12179 3789 -8390
+ Partials 1818 809 -1009
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
|
Hi, Did you have a chance to check this PR? Currently I have to use my forked version to work with strapi 4, because on every single change I get a knex timeout on restart. Thank you. Tiago Lima |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/strapi-postgres-connection-pool-breaks-connection/17926/16 |
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.
I noticed this only really is being applied to MySQL/MariaDB and doesn't address possible issues in PostgreSQL and SQLite too maybe?
|
Hi, Since I use MySQL at work, I focused on that dialect. Since the changes are made only on this dialect, it shouldn't break anything for PostgreSQL and SQLite. If those dialects are having the same issues, you can try to apply the same fixes. The only thing I have done was to query each table separately and merge the info later. I have been using this fix since I have made this PR and is working perfectly with MySQL. No timeouts since then. |
|
I can confirm that this issue exists on PostgreSQL too. I came across this PR because I do experience the same issue on a PostgreSQL Database hosted on Digital Ocean Managed Databases. As a matter of fact, I do have two projects there, one has few relations and database tables (~80) where I never had any issues so far. The other one has multiple relations and tables (~190) and it fails their automated health check when deploying because the DB work isn't done yet. |
|
Has anyone resolved it on postgres? |
|
I was facing the same issue when adding a new component on strapi v4 on existing database. I have resolved it by applying the similar logic. Now no more knex error for me. i tried to raise a PR but looks like I am not authorize to push a new branch. Patch has been posted on. |
|
@meherchandan, thank you. I've tried applying your patch but ran into this server starting error: I suppose a check must be made for the permissions table or probably check all tables with an IF exists condition? |
You need to make a fork and submit the PR from the fork. |
Thank you. Created the PR #13550 |
Can you try the updated patch on same forum post. For me this is working fine on prod server as well. |
|
patches-12843.zip |
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.
Waiting for automated tests to go through but this is a HUGE improvement.
So far it LGTM but we need @alexandrebodin to review as well.
Something @sunnysonx mentioned though he still has some performance issues and might have an additional fix to improve this further and we might want to consider moving away from using the information schema in the future.
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
|
Great contribution. That a good step for optimization. We can still work on optimization concurrency and pooling but that's great 👍 |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: |


What does it do?
Optimize the "getForeignKeys" when synchronizing with the database.
Why is it needed?
Using Strapi in a MySQL 5.7 database with lots of schemas and tables with foreign keys, the SQL query to get the foreign keys using inner joins is painfully slow, leading to the error "Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?" on every single content type update.
How to test it?
Trigger database synchronization on startup updating any content type.
Related issue(s)/PR(s)
#11860