Skip to content
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

Support tables with triggers and foreign keys #28

Closed
bancer opened this issue Apr 11, 2019 · 2 comments
Closed

Support tables with triggers and foreign keys #28

bancer opened this issue Apr 11, 2019 · 2 comments

Comments

@bancer
Copy link

bancer commented Apr 11, 2019

https://github.com/facebookincubator/OnlineSchemaChange/wiki/Limitation

  • Both original and new schema must NOT have existing TRIGGER
  • Both original and new schema must NOT referencing or being referenced by a FOREIGN KEY

Would it be possible to add support for tables with triggers and foreign keys? Almost all our tables have foreign keys as we use MySQL Innodb engine and some of the huge tables have triggers.

@adregner
Copy link
Contributor

Hi @bancer, thanks for the note. I'll address this in two parts for each limitation.

Supporting this style of schema changes for tables with foreign key checks enabled is not possible because in the process of rebuilding the table with the new schema, we need to re-insert the data it contained which mean it will not be able to satisfy those foreign key checks against tables that are not being rebuilt. Any method to get around this has to come from knowledge of the specific application and data semantics and is not something that a tool like OSC can account for. If we disabled the foreign key checks for the duration of the schema change, we would have no assurances that the data in the new table satisfies all the foreign key constraints because MySQL does not scan and cross-reference them and all the data they point to when enabling it.

Existing triggers are not supported because OSC uses a few triggers to track changes to the table it's rebuilding. Existing triggers could conflict with the triggers OSC has to put in place during its operation, without those we can't rebuild the table with the new schema while still being able to catch up to the changes the table has had while this was all happening.

Github released their online mysql schema changing system, "gh-ost" which uses "ROW" format binlogs to do the catchup instead of triggers like OSC uses, which gets around that limitation at least. You can learn more about it here: https://github.com/github/gh-ost.

For OSC we have it in mind to use row-based binlogs for the catchup (as described in issue #11) so someday OSC and gh-ost will at least have that in common. Until then there isn't anything we can do to address the limitations you bring up.

@bancer
Copy link
Author

bancer commented Apr 23, 2019

@adregner Thanks. I am aware about gh-ost project. There are similar issues there: github/gh-ost#153, github/gh-ost#507. It seems both problems are solvable there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants