fix: Allow proper filtering with --where in parent-child relationships #885
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description:
When using the --where filter in pt-online-schema-change, an error occurs when the filter is applied to a parent table (e.g., city), and the tool attempts to propagate changes to related child tables (e.g., address). Specifically, the --where condition is applied to the parent table, but the tool erroneously tries to apply this filter to child tables that do not contain the referenced column. This causes an error, as the columns in the child tables do not exist, leading to a failure during the operation.
The issue arises because pt-online-schema-change tries to apply the filter to the child tables, where the column being referenced in the --where condition (e.g., status in city) does not exist. This behavior prevents the tool from successfully executing the change and results in the error, particularly in relationships with foreign keys between the tables.
Example SQL:
In this example, the tables city and address are related via a foreign key (city_id in address referencing id in city). If a --where filter is applied to the city table, pt-online-schema-change might incorrectly attempt to apply this filter to the address table as well, causing an error because the status column (referenced in the --where condition) does not exist in the child table.
Note: Unfortunately, I was unable to run the tests locally, so I have not included any test commits with this pull request. If this issue doesn't seem relevant, could you please provide guidance on resolving this locally so that I can run the tests correctly?