Hello,
when using pt-online-schema-change with the --where option on a table that has foreign-key child tables, the tool crashes during the row-estimate phase for each child.
Steps to reproduce:
Create two tables with a foreign-key relationship, e.g.:
CREATE TABLE parent (
id INT PRIMARY KEY,
status VARCHAR(10)
);
CREATE TABLE child (
id INT PRIMARY KEY,
parent_id INT,
FOREIGN KEY (parent_id) REFERENCES parent(id)
);
Populate both tables with sample data.
Run:
pt-online-schema-change
–execute
–force
–alter-foreign-keys-method auto
–alter “ENGINE=InnoDB”
–where “status = ‘active’”
D=dbname,t=parent
Observe the failure with an error similar to:
# NibbleIterator:6302 10847 EXPLAIN SELECT * FROM `dbname`.`child` WHERE status = ‘active’
DBD::mysql::db selectrow_hashref failed: fetch() without execute() [for Statement “EXPLAIN SELECT * FROM `dbname`.`child` WHERE status = ‘active’”] at /opt/percona-toolkit-3.7.0-2/bin/pt-online-schema-change line 6303.
Because the WHERE expression references columns that exist only in the parent table, MySQL returns `ERROR 1054 (42S22): Unknown column ‘’ in ‘where clause’`. This aborts the migration even though the parent table itself would process fine.
It looks like a bug, but I’m unable to open a ticket because Jira appears to be experiencing an issue and won’t let me create a new ticket (ref: https://status.atlassian.com/).