You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running a migration, the $blueprint->toSql() method compiles a list of statements to execute on the connection. If you have a migration that adds two columns and an index, it will result in two statements: one to add the columns, another to add the index. Is there a reason it does this instead of combining them into a single statement? Would it be safe to combine them into a single statement?
Several tables in our database are too large to use Laravel's default Schema. Migrations on these tables take several hours to run, and the Schema locks the table causing an outage while the migration is ongoing. We've switched to using the package daursu/laravel-zero-downtime-migration and the pt-online-schema-change tool for zero-downtime migrations which doesn't lock the table. However, it has to copy the full table for each $statement[] returned by Blueprint::toSql(). The result is that the time it a migration takes expectedTime * numberOfStatements.
For example, adding 3 indexes to one of these large tables would take 4 hours using the Laravel Schema (bringing our app down for the duration.) The zero-downtime migration works without bringing down the app, but it takes 12 hours (3 * 4) for the migration to complete. This isn't ideal, to say the least.
If I could combine them into a single statement, we'd get a massive performance boost, but I don't have enough context into why they get executed as separate statements to know if it's safe. Does anyone know why it's done this way? I'd be happy to open a PR for this, if it's safe to do.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
When running a migration, the $blueprint->toSql() method compiles a list of statements to execute on the connection. If you have a migration that adds two columns and an index, it will result in two statements: one to add the columns, another to add the index. Is there a reason it does this instead of combining them into a single statement? Would it be safe to combine them into a single statement?
Several tables in our database are too large to use Laravel's default Schema. Migrations on these tables take several hours to run, and the Schema locks the table causing an outage while the migration is ongoing. We've switched to using the package daursu/laravel-zero-downtime-migration and the pt-online-schema-change tool for zero-downtime migrations which doesn't lock the table. However, it has to copy the full table for each
$statement[]
returned byBlueprint::toSql()
. The result is that the time it a migration takesexpectedTime * numberOfStatements
.For example, adding 3 indexes to one of these large tables would take 4 hours using the Laravel Schema (bringing our app down for the duration.) The zero-downtime migration works without bringing down the app, but it takes 12 hours (
3 * 4
) for the migration to complete. This isn't ideal, to say the least.If I could combine them into a single statement, we'd get a massive performance boost, but I don't have enough context into why they get executed as separate statements to know if it's safe. Does anyone know why it's done this way? I'd be happy to open a PR for this, if it's safe to do.
Beta Was this translation helpful? Give feedback.
All reactions